| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + # Vendored-in for from google-apitools 0.4.11 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,10 +1,9 @@ | |||
| 1 | - #!/usr/bin/env python | ||
| 2 | 1 | """Small helper class to provide a small slice of a stream. | |
| 3 | 2 | ||
| 4 | 3 | This class reads ahead to detect if we are at the end of the stream. | |
| 5 | 4 | """ | |
| 6 | 5 | ||
| 7 | - from apitools.base.py import exceptions | ||
| 6 | + from gcloud._apitools import exceptions | ||
| 8 | 7 | ||
| 9 | 8 | ||
| 10 | 9 | # TODO(user): Consider replacing this with a StringIO. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,3 @@ | |||
| 1 | - #!/usr/bin/env python | ||
| 2 | 1 | """Exceptions for generated client libraries.""" | |
| 3 | 2 | ||
| 4 | 3 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,3 @@ | |||
| 1 | - #!/usr/bin/env python | ||
| 2 | 1 | """HTTP wrapper for apitools. | |
| 3 | 2 | ||
| 4 | 3 | This library wraps the underlying http library we use, which is | |
@@ -16,8 +15,8 @@ | |||
| 16 | 15 | from six.moves import http_client | |
| 17 | 16 | from six.moves.urllib import parse | |
| 18 | 17 | ||
| 19 | - from apitools.base.py import exceptions | ||
| 20 | - from apitools.base.py import util | ||
| 18 | + from gcloud._apitools import exceptions | ||
| 19 | + from gcloud._apitools import util | ||
| 21 | 20 | ||
| 22 | 21 | __all__ = [ | |
| 23 | 22 | 'CheckResponse', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,6 @@ | |||
| 1 | - #!/usr/bin/env python | ||
| 2 | 1 | """Small helper class to provide a small slice of a stream.""" | |
| 3 | 2 | ||
| 4 | - from apitools.base.py import exceptions | ||
| 3 | + from gcloud._apitools import exceptions | ||
| 5 | 4 | ||
| 6 | 5 | ||
| 7 | 6 | class StreamSlice(object): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,3 @@ | |||
| 1 | - #!/usr/bin/env python | ||
| 2 | 1 | """Upload and download support for apitools.""" | |
| 3 | 2 | from __future__ import print_function | |
| 4 | 3 | ||
@@ -14,11 +13,11 @@ | |||
| 14 | 13 | import six | |
| 15 | 14 | from six.moves import http_client | |
| 16 | 15 | ||
| 17 | - from apitools.base.py import buffered_stream | ||
| 18 | - from apitools.base.py import exceptions | ||
| 19 | - from apitools.base.py import http_wrapper | ||
| 20 | - from apitools.base.py import stream_slice | ||
| 21 | - from apitools.base.py import util | ||
| 16 | + from gcloud._apitools import buffered_stream | ||
| 17 | + from gcloud._apitools import exceptions | ||
| 18 | + from gcloud._apitools import http_wrapper | ||
| 19 | + from gcloud._apitools import stream_slice | ||
| 20 | + from gcloud._apitools import util | ||
| 22 | 21 | ||
| 23 | 22 | __all__ = [ | |
| 24 | 23 | 'Download', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,69 +1,20 @@ | |||
| 1 | - #!/usr/bin/env python | ||
| 2 | - """Assorted utilities shared between parts of apitools.""" | ||
| 1 | + """Assorted utilities shared between parts of apitools. | ||
| 3 | 2 | ||
| 4 | - import collections | ||
| 5 | - import os | ||
| 6 | - import random | ||
| 7 | - | ||
| 8 | - import six | ||
| 9 | - from six.moves import http_client | ||
| 10 | - import six.moves.urllib.error as urllib_error | ||
| 11 | - import six.moves.urllib.parse as urllib_parse | ||
| 12 | - import six.moves.urllib.request as urllib_request | ||
| 13 | - | ||
| 14 | - from apitools.base.protorpclite import messages | ||
| 15 | - from apitools.base.py import encoding | ||
| 16 | - from apitools.base.py import exceptions | ||
| 17 | - | ||
| 18 | - __all__ = [ | ||
| 19 | - 'DetectGae', | ||
| 20 | - 'DetectGce', | ||
| 21 | - ] | ||
| 3 | + Pruned to include only helpers used by other vendored-in modules: | ||
| 22 | 4 | ||
| 23 | - _RESERVED_URI_CHARS = r":/?#[]@!$&'()*+,;=" | ||
| 5 | + ``gcloud._apidools.transfer`` uses: | ||
| 24 | 6 | ||
| 7 | + - Typecheck | ||
| 8 | + - AcceptableMimeType | ||
| 25 | 9 | ||
| 26 | - def DetectGae(): | ||
| 27 | - """Determine whether or not we're running on GAE. | ||
| 10 | + ``gcloud._apitools.http_wrapper`` uses: | ||
| 28 | 11 | ||
| 29 | - This is based on: | ||
| 30 | - https://developers.google.com/appengine/docs/python/#The_Environment | ||
| 31 | - | ||
| 32 | - Returns: | ||
| 33 | - True iff we're running on GAE. | ||
| 34 | - """ | ||
| 35 | - server_software = os.environ.get('SERVER_SOFTWARE', '') | ||
| 36 | - return (server_software.startswith('Development/') or | ||
| 37 | - server_software.startswith('Google App Engine/')) | ||
| 12 | + - CalculateWaitForRetry | ||
| 13 | + """ | ||
| 38 | 14 | ||
| 15 | + import random | ||
| 39 | 16 | ||
| 40 | - def DetectGce(): | ||
| 41 | - """Determine whether or not we're running on GCE. | ||
| 42 | - | ||
| 43 | - This is based on: | ||
| 44 | - https://cloud.google.com/compute/docs/metadata#runninggce | ||
| 45 | - | ||
| 46 | - Returns: | ||
| 47 | - True iff we're running on a GCE instance. | ||
| 48 | - """ | ||
| 49 | - try: | ||
| 50 | - o = urllib_request.build_opener(urllib_request.ProxyHandler({})).open( | ||
| 51 | - urllib_request.Request('http://metadata.google.internal')) | ||
| 52 | - except urllib_error.URLError: | ||
| 53 | - return False | ||
| 54 | - return (o.getcode() == http_client.OK and | ||
| 55 | - o.headers.get('metadata-flavor') == 'Google') | ||
| 56 | - | ||
| 57 | - | ||
| 58 | - def NormalizeScopes(scope_spec): | ||
| 59 | - """Normalize scope_spec to a set of strings.""" | ||
| 60 | - if isinstance(scope_spec, six.string_types): | ||
| 61 | - return set(scope_spec.split(' ')) | ||
| 62 | - elif isinstance(scope_spec, collections.Iterable): | ||
| 63 | - return set(scope_spec) | ||
| 64 | - raise exceptions.TypecheckError( | ||
| 65 | - 'NormalizeScopes expected string or iterable, found %s' % ( | ||
| 66 | - type(scope_spec),)) | ||
| 17 | + from gcloud._apitools import exceptions | ||
| 67 | 18 | ||
| 68 | 19 | ||
| 69 | 20 | def Typecheck(arg, arg_type, msg=None): | |
@@ -78,45 +29,6 @@ def Typecheck(arg, arg_type, msg=None): | |||
| 78 | 29 | return arg | |
| 79 | 30 | ||
| 80 | 31 | ||
| 81 | - def ExpandRelativePath(method_config, params, relative_path=None): | ||
| 82 | - """Determine the relative path for request.""" | ||
| 83 | - path = relative_path or method_config.relative_path or '' | ||
| 84 | - | ||
| 85 | - for param in method_config.path_params: | ||
| 86 | - param_template = '{%s}' % param | ||
| 87 | - # For more details about "reserved word expansion", see: | ||
| 88 | - # http://tools.ietf.org/html/rfc6570#section-3.2.2 | ||
| 89 | - reserved_chars = '' | ||
| 90 | - reserved_template = '{+%s}' % param | ||
| 91 | - if reserved_template in path: | ||
| 92 | - reserved_chars = _RESERVED_URI_CHARS | ||
| 93 | - path = path.replace(reserved_template, param_template) | ||
| 94 | - if param_template not in path: | ||
| 95 | - raise exceptions.InvalidUserInputError( | ||
| 96 | - 'Missing path parameter %s' % param) | ||
| 97 | - try: | ||
| 98 | - # TODO(craigcitro): Do we want to support some sophisticated | ||
| 99 | - # mapping here? | ||
| 100 | - value = params[param] | ||
| 101 | - except KeyError: | ||
| 102 | - raise exceptions.InvalidUserInputError( | ||
| 103 | - 'Request missing required parameter %s' % param) | ||
| 104 | - if value is None: | ||
| 105 | - raise exceptions.InvalidUserInputError( | ||
| 106 | - 'Request missing required parameter %s' % param) | ||
| 107 | - try: | ||
| 108 | - if not isinstance(value, six.string_types): | ||
| 109 | - value = str(value) | ||
| 110 | - path = path.replace(param_template, | ||
| 111 | - urllib_parse.quote(value.encode('utf_8'), | ||
| 112 | - reserved_chars)) | ||
| 113 | - except TypeError as e: | ||
| 114 | - raise exceptions.InvalidUserInputError( | ||
| 115 | - 'Error setting required parameter %s to value %s: %s' % ( | ||
| 116 | - param, value, e)) | ||
| 117 | - return path | ||
| 118 | - | ||
| 119 | - | ||
| 120 | 32 | def CalculateWaitForRetry(retry_attempt, max_wait=60): | |
| 121 | 33 | """Calculates amount of time to wait before a retry attempt. | |
| 122 | 34 | ||
@@ -173,40 +85,3 @@ def MimeTypeMatches(pattern, mime_type): | |||
| 173 | 85 | ||
| 174 | 86 | return any(MimeTypeMatches(pattern, mime_type) | |
| 175 | 87 | for pattern in accept_patterns) | |
| 176 | - | ||
| 177 | - | ||
| 178 | - def MapParamNames(params, request_type): | ||
| 179 | - """Reverse parameter remappings for URL construction.""" | ||
| 180 | - return [encoding.GetCustomJsonFieldMapping(request_type, json_name=p) or p | ||
| 181 | - for p in params] | ||
| 182 | - | ||
| 183 | - | ||
| 184 | - def MapRequestParams(params, request_type): | ||
| 185 | - """Perform any renames/remappings needed for URL construction. | ||
| 186 | - | ||
| 187 | - Currently, we have several ways to customize JSON encoding, in | ||
| 188 | - particular of field names and enums. This works fine for JSON | ||
| 189 | - bodies, but also needs to be applied for path and query parameters | ||
| 190 | - in the URL. | ||
| 191 | - | ||
| 192 | - This function takes a dictionary from param names to values, and | ||
| 193 | - performs any registered mappings. We also need the request type (to | ||
| 194 | - look up the mappings). | ||
| 195 | - | ||
| 196 | - Args: | ||
| 197 | - params: (dict) Map from param names to values | ||
| 198 | - request_type: (protorpc.messages.Message) request type for this API call | ||
| 199 | - | ||
| 200 | - Returns: | ||
| 201 | - A new dict of the same size, with all registered mappings applied. | ||
| 202 | - """ | ||
| 203 | - new_params = dict(params) | ||
| 204 | - for param_name, value in params.items(): | ||
| 205 | - field_remapping = encoding.GetCustomJsonFieldMapping( | ||
| 206 | - request_type, python_name=param_name) | ||
| 207 | - if field_remapping is not None: | ||
| 208 | - new_params[field_remapping] = new_params.pop(param_name) | ||
| 209 | - if isinstance(value, messages.Enum): | ||
| 210 | - new_params[param_name] = encoding.GetCustomJsonEnumMapping( | ||
| 211 | - type(value), python_name=str(value)) or str(value) | ||
| 212 | - return new_params | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments