[Python-modules-commits] [google-api-python-client] 01/03: import google-api-python-client_1.5.5.orig.tar.gz

Scott Kitterman kitterman at moszumanska.debian.org
Fri Nov 11 00:41:18 UTC 2016


This is an automated email from the git hooks/post-receive script.

kitterman pushed a commit to branch master
in repository google-api-python-client.

commit dc44cddab7e25bfddaeafbb0c50246709157b34b
Author: Scott Kitterman <scott at kitterman.com>
Date:   Thu Nov 10 18:59:31 2016 -0500

    import google-api-python-client_1.5.5.orig.tar.gz
---
 CHANGELOG                                          |  253 +++
 LICENSE                                            |   22 +
 MANIFEST.in                                        |    6 +
 PKG-INFO                                           |   23 +
 apiclient/__init__.py                              |   42 +
 google_api_python_client.egg-info/PKG-INFO         |   23 +
 google_api_python_client.egg-info/SOURCES.txt      |   23 +
 .../dependency_links.txt                           |    1 +
 google_api_python_client.egg-info/requires.txt     |    4 +
 google_api_python_client.egg-info/top_level.txt    |    3 +
 googleapiclient/__init__.py                        |   27 +
 googleapiclient/channel.py                         |  293 ++++
 googleapiclient/discovery.py                       | 1123 +++++++++++++
 googleapiclient/discovery_cache/__init__.py        |   45 +
 .../discovery_cache/appengine_memcache.py          |   55 +
 googleapiclient/discovery_cache/base.py            |   45 +
 googleapiclient/discovery_cache/file_cache.py      |  141 ++
 googleapiclient/errors.py                          |  153 ++
 googleapiclient/http.py                            | 1730 ++++++++++++++++++++
 googleapiclient/mimeparse.py                       |  175 ++
 googleapiclient/model.py                           |  389 +++++
 googleapiclient/sample_tools.py                    |  103 ++
 googleapiclient/schema.py                          |  318 ++++
 setup.cfg                                          |    5 +
 setup.py                                           |  106 ++
 25 files changed, 5108 insertions(+)

diff --git a/CHANGELOG b/CHANGELOG
new file mode 100644
index 0000000..c0a6693
--- /dev/null
+++ b/CHANGELOG
@@ -0,0 +1,253 @@
+v1.5.5
+  Version 1.5.5
+
+  Bugfix release
+
+  - Allow explicit MIME type specification with media_mime_type keyword argument.
+  - Fix unprintable representation of BatchError with default constructor. (#165)
+  - Refresh all discovery docs, not just the preferred ones. (#298)
+  - Update minimum httplib2 dependency to >=0.9.2.
+
+v1.5.4
+  Version 1.5.4
+
+  Bugfix release
+
+  - Properly handle errors when the API returns a mapping or sequence. (#289)
+  - Upgrade to unified uritemplate 3.0.0. (#293)
+  - Allow oauth2client 4.0.0, with the caveat that file-based discovery
+    caching is disabled.
+
+v1.5.3
+  Version 1.5.3
+
+  Bugfix release
+
+  - Fixed import error with oauth2client >= 3.0.0. (#270)
+
+v1.5.2
+  Version 1.5.2
+
+  Bugfix release
+
+  - Allow using oauth2client >= 1.5.0, < 4.0.0. (#265)
+  - Fix project_id argument description. (#257)
+  - Retry chunk uploaded on rate limit exceeded errors. (#255)
+  - Obtain access token if necessary in BatchHttpRequest.execute(). (#232)
+  - Warn when running tests using HttpMock without having a cache. (#261)
+
+v1.5.1
+  Version 1.5.1
+
+  Bugfix release
+
+  - Allow using versions of oauth2client < 2.0.0. (#197)
+  - Check both current and new API discovery URL. (#202)
+  - Retry http requests on connection errors and timeouts. (#218)
+  - Retry http requests on rate limit responses. (#201)
+  - Import guards for ssl (for Google App Engine). (#220)
+  - Use named loggers instead of the root logger. (#206)
+  - New search console example. (#212)
+
+v1.5.0
+  Version 1.5.0
+
+  Release to support oauth2client >= 2.0.0.
+
+  - Fix file stream recognition in Python 3 (#141)
+  - Fix non-resumable binary uploads in Python 3 (#147)
+  - Default to 'octet-stream' if mimetype detection fails (#157)
+  - Handle SSL errors with retries (#160)
+  - Fix incompatibility with oauth2client v2.0.0 (#182)
+
+v1.4.2
+  Version 1.4.2
+
+  Add automatic caching for the discovery docs.
+
+v1.4.1
+  Version 1.4.1
+
+  Add the googleapiclient.discovery.Resource.new_batch_http_request method.
+
+v1.4.0
+  Version 1.4.0
+
+  Python 3 support.
+
+v1.3.2
+  Version 1.3.2
+
+  Small bugfix release.
+
+  - Fix an infinite loop for downloading small files.
+  - Fix a unicode error in error encoding.
+  - Better handling of `content-length` in media requests.
+  - Add support for methodPath entries containing colon.
+
+v1.3.1
+  Version 1.3.1
+
+  Quick release for a fix around aliasing in v1.3.
+
+v1.3
+  Version 1.3
+
+  Add support for the Google Application Default Credentials.
+  Require python 2.6 as a minimum version.
+  Update several API samples.
+  Finish splitting out oauth2client repo and update tests.
+  Various doc cleanup and bugfixes.
+
+  Two important notes:
+    * We've added `googleapiclient` as the primary suggested import
+      name, and kept `apiclient` as an alias, in order to have a more
+      appropriate import name. At some point, we will remove `apiclient`
+      as an alias.
+    * Due to an issue around in-place upgrades for Python packages,
+      it's not possible to do an upgrade from version 1.2 to 1.3. Instead,
+      setup.py attempts to detect this and prevents it. Simply remove
+      the previous version and reinstall to fix this.
+
+v1.2
+  Version 1.2
+
+  The use of the gflags library is now deprecated, and is no longer a
+    dependency. If you are still using the oauth2client.tools.run() function
+    then include gflags as a dependency of your application or switch to
+    oauth2client.tools.run_flow.
+  Samples have been updated to use the new apiclient.sample_tools, and no
+    longer use gflags.
+  Added support for the experimental Object Change Notification, as found in
+    the Cloud Storage API.
+  The oauth2client App Engine decorators are now threadsafe.
+
+  - Use the following redirects feature of httplib2 where it returns the
+    ultimate URL after a series of redirects to avoid multiple hops for every
+    resumable media upload request.
+  - Updated AdSense Management API samples to V1.3
+  - Add option to automatically retry requests.
+  - Ability to list registered keys in multistore_file.
+  - User-agent must contain (gzip).
+  - The 'method' parameter for httplib2 is not positional. This would cause
+    spurious warnings in the logging.
+  - Making OAuth2Decorator more extensible. Fixes Issue 256.
+  - Update AdExchange Buyer API examples to version v1.2.
+
+
+v1.1
+  Version 1.1
+
+  Add PEM support to SignedJWTAssertionCredentials (used to only support
+  PKCS12 formatted keys). Note that if you use PEM formatted keys you can use
+  PyCrypto 2.6 or later instead of OpenSSL.
+
+  Allow deserialized discovery docs to be passed to build_from_document().
+
+  - Make ResumableUploadError derive from HttpError.
+  - Many changes to move all the closures in apiclient.discovery into real
+  -  classes and objects.
+  - Make from_json behavior inheritable.
+  - Expose the full token response in OAuth2Client and OAuth2Decorator.
+  - Handle reasons that are None.
+  - Added support for NDB based storing of oauth2client objects.
+  - Update grant_type for AssertionCredentials.
+  - Adding a .revoke() to Credentials. Closes issue 98.
+  - Modify oauth2client.multistore_file to store and retrieve credentials
+    using an arbitrary key.
+  - Don't accept 403 challenges by default for auth challenges.
+  - Set httplib2.RETRIES to 1.
+  - Consolidate handling of scopes.
+  - Upgrade to httplib2 version 0.8.
+  - Allow setting the response_type in OAuth2WebServerFlow.
+  - Ensure that dataWrapper feature is checked before using the 'data' value.
+  - HMAC verification does not use a constant time algorithm.
+
+v1.0
+ Version 1.0
+
+  - Changes to the code for running tests and building releases.
+
+v1.0c3
+ Version 1.0 Release Candidate 3
+
+  - In samples and oauth2 decorator, escape untrusted content before displaying it.
+  - Do not allow credentials files to be symlinks.
+  - Add XSRF protection to oauth2decorator callback 'state'.
+  - Handle uploading chunked media by stream.
+  - Handle passing streams directly to httplib2.
+  - Add support for Google Compute Engine service accounts.
+  - Flows no longer need to be saved between uses.
+  - Change GET to POST if URI is too long. Fixes issue #96.
+  - Add a keyring based Storage.
+  - More robust picking up JSON error responses.
+  - Make batch errors align with normal errors.
+  - Add a Google Compute sample.
+  - Token refresh to work with 'old' GData API
+  - Loading of client_secrets JSON file backed by a cache.
+  - Switch to new discovery path parameters.
+  - Add support for additionalProperties when printing schema'd objects.
+  - Fix media upload parameter names. Reviewed in http://codereview.appspot.com/6374062/
+  - oauth2client support for URL-encoded format of exchange token response (e.g.  Facebook)
+  - Build cleaner and easier to read docs for dynamic surfaces.
+
+v1.0c2
+ Version 1.0 Release Candidate 2
+
+  - Parameter values of None should be treated as missing. Fixes issue #144.
+  - Distribute the samples separately from the library source. Fixes issue #155.
+  - Move all remaining samples over to client_secrets.json. Fixes issue #156.
+  - Make locked_file.py understand win32file primitives for better awesomeness.
+
+v1.0c1
+ Version 1.0 Release Candidate 1
+
+ - Documentation for the library has switched to epydoc:
+     http://google-api-python-client.googlecode.com/hg/docs/epy/index.html
+ - Many improvements for media support:
+   * Added media download support, including resumable downloads.
+   * Better handling of streams that report their size as 0.
+   * Update Media Upload to include io.Base and also fix some bugs.
+ - OAuth bug fixes and improvements.
+   * Remove OAuth 1.0 support.
+   * Added credentials_from_code and credentials_from_clientsecrets_and_code.
+   * Make oauth2client support Windows-friendly locking.
+   * Fix bug in StorageByKeyName.
+   * Fix None handling in Django fields. Reviewed in http://codereview.appspot.com/6298084/. Fixes issue #128.
+ - Add epydoc generated docs. Reviewed in http://codereview.appspot.com/6305043/
+ - Move to PEP386 compliant version numbers.
+ - New and updated samples
+   * Ad Exchange Buyer API v1 code samples.
+   * Automatically generate Samples wiki page from README files.
+   * Update Google Prediction samples.
+   * Add a Tasks sample that demonstrates Service accounts.
+   * new analytics api samples. Reviewed here: http://codereview.appspot.com/5494058/
+ - Convert all inline samples to the Farm API for consistency.
+
+v1.0beta8
+ - Updated meda upload support.
+ - Many fixes for batch requests.
+ - Better handling for requests that don't require a body.
+ - Fix issues with Google App Engine Python 2.7 runtime.
+ - Better support for proxies.
+ - All Storages now have a .delete() method.
+ - Important changes which might break your code:
+    * apiclient.anyjson has moved to oauth2client.anyjson.
+    * Some calls, for example, taskqueue().lease() used to require a parameter
+      named body. In this new release only methods that really need to send a body
+      require a body parameter, and so you may get errors about an unknown
+      'body' parameter in your call. The solution is to remove the unneeded
+      body={} parameter.
+
+v1.0beta7
+ - Support for batch requests.  http://code.google.com/p/google-api-python-client/wiki/Batch
+ - Support for media upload.  http://code.google.com/p/google-api-python-client/wiki/MediaUpload
+ - Better handling for APIs that return something other than JSON.
+ - Major cleanup and consolidation of the samples.
+ - Bug fixes and other enhancements:
+   72  Defect  Appengine OAuth2Decorator: Convert redirect address to string
+   22  Defect  Better error handling for unknown service name or version
+   48  Defect  StorageByKeyName().get() has side effects
+   50  Defect  Need sample client code for Admin Audit API
+   28  Defect  better comments for app engine sample   Nov 9
+   63  Enhancement Let OAuth2Decorator take a list of scope
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..2987b3b
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,22 @@
+ Copyright 2014 Google Inc. All Rights Reserved.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+Dependent Modules
+=================
+
+This code has the following dependencies
+above and beyond the Python standard library:
+
+uritemplates - Apache License 2.0
+httplib2 - MIT License
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..cc692b3
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,6 @@
+recursive-include apiclient *.json *.py
+include CHANGELOG
+include LICENSE
+include README
+include FAQ
+include setpath.sh
diff --git a/PKG-INFO b/PKG-INFO
new file mode 100644
index 0000000..8f54f12
--- /dev/null
+++ b/PKG-INFO
@@ -0,0 +1,23 @@
+Metadata-Version: 1.1
+Name: google-api-python-client
+Version: 1.5.5
+Summary: Google API Client Library for Python
+Home-page: http://github.com/google/google-api-python-client/
+Author: Google Inc.
+Author-email: UNKNOWN
+License: Apache 2.0
+Description: The Google API Client for Python is a client library for
+        accessing the Plus, Moderator, and many other Google APIs.
+Keywords: google api client
+Platform: UNKNOWN
+Classifier: Programming Language :: Python :: 2
+Classifier: Programming Language :: Python :: 2.6
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3
+Classifier: Programming Language :: Python :: 3.3
+Classifier: Programming Language :: Python :: 3.4
+Classifier: Development Status :: 5 - Production/Stable
+Classifier: Intended Audience :: Developers
+Classifier: License :: OSI Approved :: Apache Software License
+Classifier: Operating System :: OS Independent
+Classifier: Topic :: Internet :: WWW/HTTP
diff --git a/apiclient/__init__.py b/apiclient/__init__.py
new file mode 100644
index 0000000..d75e7a1
--- /dev/null
+++ b/apiclient/__init__.py
@@ -0,0 +1,42 @@
+"""Retain apiclient as an alias for googleapiclient."""
+
+from six import iteritems
+
+import googleapiclient
+
+try:
+  import oauth2client
+except ImportError:
+  raise RuntimeError(
+      'Previous version of google-api-python-client detected; due to a '
+      'packaging issue, we cannot perform an in-place upgrade. To repair, '
+      'remove and reinstall this package, along with oauth2client and '
+      'uritemplate. One can do this with pip via\n'
+      '  pip install -I google-api-python-client'
+  )
+
+from googleapiclient import channel
+from googleapiclient import discovery
+from googleapiclient import errors
+from googleapiclient import http
+from googleapiclient import mimeparse
+from googleapiclient import model
+from googleapiclient import sample_tools
+from googleapiclient import schema
+
+__version__ = googleapiclient.__version__
+
+_SUBMODULES = {
+    'channel': channel,
+    'discovery': discovery,
+    'errors': errors,
+    'http': http,
+    'mimeparse': mimeparse,
+    'model': model,
+    'sample_tools': sample_tools,
+    'schema': schema,
+}
+
+import sys
+for module_name, module in iteritems(_SUBMODULES):
+  sys.modules['apiclient.%s' % module_name] = module
diff --git a/google_api_python_client.egg-info/PKG-INFO b/google_api_python_client.egg-info/PKG-INFO
new file mode 100644
index 0000000..8f54f12
--- /dev/null
+++ b/google_api_python_client.egg-info/PKG-INFO
@@ -0,0 +1,23 @@
+Metadata-Version: 1.1
+Name: google-api-python-client
+Version: 1.5.5
+Summary: Google API Client Library for Python
+Home-page: http://github.com/google/google-api-python-client/
+Author: Google Inc.
+Author-email: UNKNOWN
+License: Apache 2.0
+Description: The Google API Client for Python is a client library for
+        accessing the Plus, Moderator, and many other Google APIs.
+Keywords: google api client
+Platform: UNKNOWN
+Classifier: Programming Language :: Python :: 2
+Classifier: Programming Language :: Python :: 2.6
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3
+Classifier: Programming Language :: Python :: 3.3
+Classifier: Programming Language :: Python :: 3.4
+Classifier: Development Status :: 5 - Production/Stable
+Classifier: Intended Audience :: Developers
+Classifier: License :: OSI Approved :: Apache Software License
+Classifier: Operating System :: OS Independent
+Classifier: Topic :: Internet :: WWW/HTTP
diff --git a/google_api_python_client.egg-info/SOURCES.txt b/google_api_python_client.egg-info/SOURCES.txt
new file mode 100644
index 0000000..75ed621
--- /dev/null
+++ b/google_api_python_client.egg-info/SOURCES.txt
@@ -0,0 +1,23 @@
+CHANGELOG
+LICENSE
+MANIFEST.in
+setup.py
+apiclient/__init__.py
+google_api_python_client.egg-info/PKG-INFO
+google_api_python_client.egg-info/SOURCES.txt
+google_api_python_client.egg-info/dependency_links.txt
+google_api_python_client.egg-info/requires.txt
+google_api_python_client.egg-info/top_level.txt
+googleapiclient/__init__.py
+googleapiclient/channel.py
+googleapiclient/discovery.py
+googleapiclient/errors.py
+googleapiclient/http.py
+googleapiclient/mimeparse.py
+googleapiclient/model.py
+googleapiclient/sample_tools.py
+googleapiclient/schema.py
+googleapiclient/discovery_cache/__init__.py
+googleapiclient/discovery_cache/appengine_memcache.py
+googleapiclient/discovery_cache/base.py
+googleapiclient/discovery_cache/file_cache.py
\ No newline at end of file
diff --git a/google_api_python_client.egg-info/dependency_links.txt b/google_api_python_client.egg-info/dependency_links.txt
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/google_api_python_client.egg-info/dependency_links.txt
@@ -0,0 +1 @@
+
diff --git a/google_api_python_client.egg-info/requires.txt b/google_api_python_client.egg-info/requires.txt
new file mode 100644
index 0000000..e9154f2
--- /dev/null
+++ b/google_api_python_client.egg-info/requires.txt
@@ -0,0 +1,4 @@
+httplib2>=0.9.2,<1dev
+oauth2client>=1.5.0,<5.0.0dev
+six>=1.6.1,<2dev
+uritemplate>=3.0.0,<4dev
diff --git a/google_api_python_client.egg-info/top_level.txt b/google_api_python_client.egg-info/top_level.txt
new file mode 100644
index 0000000..f907e7e
--- /dev/null
+++ b/google_api_python_client.egg-info/top_level.txt
@@ -0,0 +1,3 @@
+apiclient
+googleapiclient
+googleapiclient/discovery_cache
diff --git a/googleapiclient/__init__.py b/googleapiclient/__init__.py
new file mode 100644
index 0000000..e80f447
--- /dev/null
+++ b/googleapiclient/__init__.py
@@ -0,0 +1,27 @@
+# Copyright 2014 Google Inc. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+__version__ = "1.5.5"
+
+# Set default logging handler to avoid "No handler found" warnings.
+import logging
+
+try:  # Python 2.7+
+    from logging import NullHandler
+except ImportError:
+    class NullHandler(logging.Handler):
+        def emit(self, record):
+            pass
+
+logging.getLogger(__name__).addHandler(NullHandler())
diff --git a/googleapiclient/channel.py b/googleapiclient/channel.py
new file mode 100644
index 0000000..a38b4ff
--- /dev/null
+++ b/googleapiclient/channel.py
@@ -0,0 +1,293 @@
+"""Channel notifications support.
+
+Classes and functions to support channel subscriptions and notifications
+on those channels.
+
+Notes:
+  - This code is based on experimental APIs and is subject to change.
+  - Notification does not do deduplication of notification ids, that's up to
+    the receiver.
+  - Storing the Channel between calls is up to the caller.
+
+
+Example setting up a channel:
+
+  # Create a new channel that gets notifications via webhook.
+  channel = new_webhook_channel("https://example.com/my_web_hook")
+
+  # Store the channel, keyed by 'channel.id'. Store it before calling the
+  # watch method because notifications may start arriving before the watch
+  # method returns.
+  ...
+
+  resp = service.objects().watchAll(
+    bucket="some_bucket_id", body=channel.body()).execute()
+  channel.update(resp)
+
+  # Store the channel, keyed by 'channel.id'. Store it after being updated
+  # since the resource_id value will now be correct, and that's needed to
+  # stop a subscription.
+  ...
+
+
+An example Webhook implementation using webapp2. Note that webapp2 puts
+headers in a case insensitive dictionary, as headers aren't guaranteed to
+always be upper case.
+
+  id = self.request.headers[X_GOOG_CHANNEL_ID]
+
+  # Retrieve the channel by id.
+  channel = ...
+
+  # Parse notification from the headers, including validating the id.
+  n = notification_from_headers(channel, self.request.headers)
+
+  # Do app specific stuff with the notification here.
+  if n.resource_state == 'sync':
+    # Code to handle sync state.
+  elif n.resource_state == 'exists':
+    # Code to handle the exists state.
+  elif n.resource_state == 'not_exists':
+    # Code to handle the not exists state.
+
+
+Example of unsubscribing.
+
+  service.channels().stop(channel.body())
+"""
+from __future__ import absolute_import
+
+import datetime
+import uuid
+
+from googleapiclient import errors
+import six
+
+# Oauth2client < 3 has the positional helper in 'util', >= 3 has it
+# in '_helpers'.
+try:
+  from oauth2client import util
+except ImportError:
+  from oauth2client import _helpers as util
+
+
+# The unix time epoch starts at midnight 1970.
+EPOCH = datetime.datetime.utcfromtimestamp(0)
+
+# Map the names of the parameters in the JSON channel description to
+# the parameter names we use in the Channel class.
+CHANNEL_PARAMS = {
+    'address': 'address',
+    'id': 'id',
+    'expiration': 'expiration',
+    'params': 'params',
+    'resourceId': 'resource_id',
+    'resourceUri': 'resource_uri',
+    'type': 'type',
+    'token': 'token',
+    }
+
+X_GOOG_CHANNEL_ID     = 'X-GOOG-CHANNEL-ID'
+X_GOOG_MESSAGE_NUMBER = 'X-GOOG-MESSAGE-NUMBER'
+X_GOOG_RESOURCE_STATE = 'X-GOOG-RESOURCE-STATE'
+X_GOOG_RESOURCE_URI   = 'X-GOOG-RESOURCE-URI'
+X_GOOG_RESOURCE_ID    = 'X-GOOG-RESOURCE-ID'
+
+
+def _upper_header_keys(headers):
+  new_headers = {}
+  for k, v in six.iteritems(headers):
+    new_headers[k.upper()] = v
+  return new_headers
+
+
+class Notification(object):
+  """A Notification from a Channel.
+
+  Notifications are not usually constructed directly, but are returned
+  from functions like notification_from_headers().
+
+  Attributes:
+    message_number: int, The unique id number of this notification.
+    state: str, The state of the resource being monitored.
+    uri: str, The address of the resource being monitored.
+    resource_id: str, The unique identifier of the version of the resource at
+      this event.
+  """
+  @util.positional(5)
+  def __init__(self, message_number, state, resource_uri, resource_id):
+    """Notification constructor.
+
+    Args:
+      message_number: int, The unique id number of this notification.
+      state: str, The state of the resource being monitored. Can be one
+        of "exists", "not_exists", or "sync".
+      resource_uri: str, The address of the resource being monitored.
+      resource_id: str, The identifier of the watched resource.
+    """
+    self.message_number = message_number
+    self.state = state
+    self.resource_uri = resource_uri
+    self.resource_id = resource_id
+
+
+class Channel(object):
+  """A Channel for notifications.
+
+  Usually not constructed directly, instead it is returned from helper
+  functions like new_webhook_channel().
+
+  Attributes:
+    type: str, The type of delivery mechanism used by this channel. For
+      example, 'web_hook'.
+    id: str, A UUID for the channel.
+    token: str, An arbitrary string associated with the channel that
+      is delivered to the target address with each event delivered
+      over this channel.
+    address: str, The address of the receiving entity where events are
+      delivered. Specific to the channel type.
+    expiration: int, The time, in milliseconds from the epoch, when this
+      channel will expire.
+    params: dict, A dictionary of string to string, with additional parameters
+      controlling delivery channel behavior.
+    resource_id: str, An opaque id that identifies the resource that is
+      being watched. Stable across different API versions.
+    resource_uri: str, The canonicalized ID of the watched resource.
+  """
+
+  @util.positional(5)
+  def __init__(self, type, id, token, address, expiration=None,
+               params=None, resource_id="", resource_uri=""):
+    """Create a new Channel.
+
+    In user code, this Channel constructor will not typically be called
+    manually since there are functions for creating channels for each specific
+    type with a more customized set of arguments to pass.
+
+    Args:
+      type: str, The type of delivery mechanism used by this channel. For
+        example, 'web_hook'.
+      id: str, A UUID for the channel.
+      token: str, An arbitrary string associated with the channel that
+        is delivered to the target address with each event delivered
+        over this channel.
+      address: str,  The address of the receiving entity where events are
+        delivered. Specific to the channel type.
+      expiration: int, The time, in milliseconds from the epoch, when this
+        channel will expire.
+      params: dict, A dictionary of string to string, with additional parameters
+        controlling delivery channel behavior.
+      resource_id: str, An opaque id that identifies the resource that is
+        being watched. Stable across different API versions.
+      resource_uri: str, The canonicalized ID of the watched resource.
+    """
+    self.type = type
+    self.id = id
+    self.token = token
+    self.address = address
+    self.expiration = expiration
+    self.params = params
+    self.resource_id = resource_id
+    self.resource_uri = resource_uri
+
+  def body(self):
+    """Build a body from the Channel.
+
+    Constructs a dictionary that's appropriate for passing into watch()
+    methods as the value of body argument.
+
+    Returns:
+      A dictionary representation of the channel.
+    """
+    result = {
+        'id': self.id,
+        'token': self.token,
+        'type': self.type,
+        'address': self.address
+        }
+    if self.params:
+      result['params'] = self.params
+    if self.resource_id:
+      result['resourceId'] = self.resource_id
+    if self.resource_uri:
+      result['resourceUri'] = self.resource_uri
+    if self.expiration:
+      result['expiration'] = self.expiration
+
+    return result
+
+  def update(self, resp):
+    """Update a channel with information from the response of watch().
+
+    When a request is sent to watch() a resource, the response returned
+    from the watch() request is a dictionary with updated channel information,
+    such as the resource_id, which is needed when stopping a subscription.
+
+    Args:
+      resp: dict, The response from a watch() method.
+    """
+    for json_name, param_name in six.iteritems(CHANNEL_PARAMS):
+      value = resp.get(json_name)
+      if value is not None:
+        setattr(self, param_name, value)
+
+
+def notification_from_headers(channel, headers):
+  """Parse a notification from the webhook request headers, validate
+    the notification, and return a Notification object.
+
+  Args:
+    channel: Channel, The channel that the notification is associated with.
+    headers: dict, A dictionary like object that contains the request headers
+      from the webhook HTTP request.
+
+  Returns:
+    A Notification object.
+
+  Raises:
+    errors.InvalidNotificationError if the notification is invalid.
+    ValueError if the X-GOOG-MESSAGE-NUMBER can't be converted to an int.
+  """
+  headers = _upper_header_keys(headers)
+  channel_id = headers[X_GOOG_CHANNEL_ID]
+  if channel.id != channel_id:
+    raise errors.InvalidNotificationError(
+        'Channel id mismatch: %s != %s' % (channel.id, channel_id))
+  else:
+    message_number = int(headers[X_GOOG_MESSAGE_NUMBER])
+    state = headers[X_GOOG_RESOURCE_STATE]
+    resource_uri = headers[X_GOOG_RESOURCE_URI]
+    resource_id = headers[X_GOOG_RESOURCE_ID]
+    return Notification(message_number, state, resource_uri, resource_id)
+
+
+ at util.positional(2)
+def new_webhook_channel(url, token=None, expiration=None, params=None):
+    """Create a new webhook Channel.
+
+    Args:
+      url: str, URL to post notifications to.
+      token: str, An arbitrary string associated with the channel that
+        is delivered to the target address with each notification delivered
+        over this channel.
+      expiration: datetime.datetime, A time in the future when the channel
+        should expire. Can also be None if the subscription should use the
+        default expiration. Note that different services may have different
+        limits on how long a subscription lasts. Check the response from the
+        watch() method to see the value the service has set for an expiration
+        time.
+      params: dict, Extra parameters to pass on channel creation. Currently
+        not used for webhook channels.
+    """
+    expiration_ms = 0
+    if expiration:
+      delta = expiration - EPOCH
+      expiration_ms = delta.microseconds/1000 + (
+          delta.seconds + delta.days*24*3600)*1000
+      if expiration_ms < 0:
+        expiration_ms = 0
+
+    return Channel('web_hook', str(uuid.uuid4()),
+                   token, url, expiration=expiration_ms,
+                   params=params)
+
diff --git a/googleapiclient/discovery.py b/googleapiclient/discovery.py
new file mode 100644
index 0000000..4e7b736
--- /dev/null
+++ b/googleapiclient/discovery.py
@@ -0,0 +1,1123 @@
+# Copyright 2014 Google Inc. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Client for discovery based APIs.
+
+A client library for Google's discovery based APIs.
+"""
+from __future__ import absolute_import
+import six
+from six.moves import zip
+
+__author__ = 'jcgregorio at google.com (Joe Gregorio)'
+__all__ = [
+    'build',
+    'build_from_document',
+    'fix_method_name',
+    'key2param',
+    ]
+
+from six import BytesIO
+from six.moves import http_client
+from six.moves.urllib.parse import urlencode, urlparse, urljoin, \
+  urlunparse, parse_qsl
+
+# Standard library imports
+import copy
+try:
+  from email.generator import BytesGenerator
+except ImportError:
+  from email.generator import Generator as BytesGenerator
+from email.mime.multipart import MIMEMultipart
+from email.mime.nonmultipart import MIMENonMultipart
+import json
+import keyword
+import logging
+import mimetypes
+import os
+import re
+
+# Third-party imports
+import httplib2
+import uritemplate
+
+# Local imports
+from googleapiclient import mimeparse
+from googleapiclient.errors import HttpError
+from googleapiclient.errors import InvalidJsonError
+from googleapiclient.errors import MediaUploadSizeError
+from googleapiclient.errors import UnacceptableMimeTypeError
+from googleapiclient.errors import UnknownApiNameOrVersion
+from googleapiclient.errors import UnknownFileType
+from googleapiclient.http import BatchHttpRequest
+from googleapiclient.http import HttpMock
+from googleapiclient.http import HttpMockSequence
+from googleapiclient.http import HttpRequest
+from googleapiclient.http import MediaFileUpload
+from googleapiclient.http import MediaUpload
+from googleapiclient.model import JsonModel
+from googleapiclient.model import MediaModel
+from googleapiclient.model import RawModel
+from googleapiclient.schema import Schemas
+from oauth2client.client import GoogleCredentials
+
+# Oauth2client < 3 has the positional helper in 'util', >= 3 has it
+# in '_helpers'.
+try:
+  from oauth2client.util import _add_query_parameter
+  from oauth2client.util import positional
+except ImportError:
+  from oauth2client._helpers import _add_query_parameter
+  from oauth2client._helpers import positional
+
+
+# The client library requires a version of httplib2 that supports RETRIES.
+httplib2.RETRIES = 1
+
+logger = logging.getLogger(__name__)
+
+URITEMPLATE = re.compile('{[^}]*}')
+VARNAME = re.compile('[a-zA-Z0-9_-]+')
+DISCOVERY_URI = ('https://www.googleapis.com/discovery/v1/apis/'
+                 '{api}/{apiVersion}/rest')
+V1_DISCOVERY_URI = DISCOVERY_URI
+V2_DISCOVERY_URI = ('https://{api}.googleapis.com/$discovery/rest?'
+                    'version={apiVersion}')
+DEFAULT_METHOD_DOC = 'A description of how to use this function'
+HTTP_PAYLOAD_METHODS = frozenset(['PUT', 'POST', 'PATCH'])
+_MEDIA_SIZE_BIT_SHIFTS = {'KB': 10, 'MB': 20, 'GB': 30, 'TB': 40}
+BODY_PARAMETER_DEFAULT_VALUE = {
+    'description': 'The request body.',
+    'type': 'object',
+    'required': True,
+}
+MEDIA_BODY_PARAMETER_DEFAULT_VALUE = {
+    'description': ('The filename of the media request body, or an instance '
+                    'of a MediaUpload object.'),
+    'type': 'string',
+    'required': False,
+}
+MEDIA_MIME_TYPE_PARAMETER_DEFAULT_VALUE = {
+    'description': ('The MIME type of the media request body, or an instance '
+                    'of a MediaUpload object.'),
+    'type': 'string',
+    'required': False,
+}
+
+# Parameters accepted by the stack, but not visible via discovery.
+# TODO(dhermes): Remove 'userip' in 'v2'.
+STACK_QUERY_PARAMETERS = frozenset(['trace', 'pp', 'userip', 'strict'])
+STACK_QUERY_PARAMETER_DEFAULT_VALUE = {'type': 'string', 'location': 'query'}
+
+# Library-specific reserved words beyond Python keywords.
+RESERVED_WORDS = frozenset(['body'])
+
+# patch _write_lines to avoid munging '\r' into '\n'
+# ( https://bugs.python.org/issue18886 https://bugs.python.org/issue19003 )
+class _BytesGenerator(BytesGenerator):
+  _write_lines = BytesGenerator.write
+
+def fix_method_name(name):
+  """Fix method names to avoid reserved word conflicts.
+
+  Args:
+    name: string, method name.
+
+  Returns:
+    The name with a '_' prefixed if the name is a reserved word.
+  """
+  if keyword.iskeyword(name) or name in RESERVED_WORDS:
+    return name + '_'
+  else:
+    return name
+
+
+def key2param(key):
+  """Converts key names into parameter names.
+
+  For example, converting "max-results" -> "max_results"
+
+  Args:
+    key: string, the method key name.
+
+  Returns:
+    A safe method name based on the key name.
+  """
+  result = []
+  key = list(key)
+  if not key[0].isalpha():
+    result.append('x')
+  for c in key:
+    if c.isalnum():
+      result.append(c)
+    else:
+      result.append('_')
+
+  return ''.join(result)
+
... 4292 lines suppressed ...

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/google-api-python-client.git



More information about the Python-modules-commits mailing list