Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python3 #45

Closed
wants to merge 47 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
f1542f7
Updating exception variable naming to be Python3 compatible.
pferate Dec 24, 2014
80f9281
Updating StringIO -> io.BytesIO. Also updated urlparse imports to ap…
pferate Dec 24, 2014
0727747
Updated built in function: file() -> open()
pferate Dec 24, 2014
fa8a6f4
Adding long() for compatibility
pferate Dec 24, 2014
10c20b4
Updating more import calls
pferate Dec 24, 2014
73328fb
Adding is_string() to handle both Python2 and Python3 easily (Maybe m…
pferate Dec 24, 2014
d4a189a
Fixing more urllib imports.
pferate Dec 24, 2014
bb67eae
Adding python 2 and 3 compatibility for iteritems().
pferate Dec 24, 2014
50026bd
Adding python 2 and 3 compatibility for iteritems() and iterkeys().
pferate Dec 24, 2014
2a1e5d3
Changing None to empty string for urlunparse().
pferate Dec 24, 2014
65c4874
Fixed inconsistent white space
pferate Dec 24, 2014
3de8a2f
Fixed urllib imports and unicode encoding attempt.
pferate Dec 24, 2014
8664fd4
Adding python 2 and 3 compatibility for iteritems().
pferate Jan 5, 2015
18a6d94
Updating BytesIO() input from string to bytestring
pferate Jan 5, 2015
38d281b
Updating xrange() to range().
pferate Jan 5, 2015
c0b5250
Updating `dict.has_key(key)` to `key in dict`, and importing reduce()…
pferate Jan 6, 2015
d994957
Allowing JSON content if already a str
pferate Jan 6, 2015
250d8ec
Updating `dict.has_key(key)` to `key in dict`, and changing strings t…
pferate Jan 6, 2015
202c5cb
Changing the file pointer for the MultiPartMessage: StringIO if pytho…
pferate Jan 6, 2015
539a651
Fixed None value assumption as 0.
pferate Jan 6, 2015
3489471
Cleaning up more unicode/bytes conflicts.
pferate Jan 7, 2015
836ede9
Removing questionable test (Not sure if we really want to open a bina…
pferate Jan 7, 2015
96c84ef
Fixed urllib import.
pferate Jan 7, 2015
391df3c
Tried and failed to get this test working for all python versions. S…
pferate Jan 7, 2015
58a7962
Fixed a unicode encoding case
pferate Jan 7, 2015
9b0a996
Adding branches to tox whitelist
pferate Jan 8, 2015
2defcf1
Adding travis-ci config file (based off of google/oauth2client)
pferate Jan 8, 2015
2c54788
Fixing formatting.
pferate Jan 8, 2015
e7f9739
Fixing more formatting (tox.ini).
pferate Jan 8, 2015
7df848c
Removing Tox Environment, docs (not yet implemented)
pferate Jan 8, 2015
9bbc85a
Cleaning up some excess commented out options.
pferate Jan 8, 2015
abb41b5
Changing different dictionary iterators to simpler syntax. That mean…
pferate Jan 8, 2015
5c622e3
Making mostly PEP8 compliant. A few lines were left over 80 characte…
pferate Jan 8, 2015
a1deda6
Some more PEP8 compliance.
pferate Jan 8, 2015
257cf90
First pass at coveralls integration.
pferate Jan 9, 2015
f2b69c5
Adding IDE (PyCharm) directory to `.gitignore`
pferate Jan 9, 2015
f23afee
Trying to have coveralls run in both 2.7 and 3.4.
pferate Jan 9, 2015
1ea731f
Another attempt to have coveralls run in 2.7 and 3.4.
pferate Jan 9, 2015
015fee2
Changing long to int
pferate Jan 14, 2015
65869b8
Changing long to int (Including missing conversion to int)
pferate Jan 14, 2015
5434b7a
Cleaning up imports (using six)
pferate Jan 14, 2015
ce5c5cf
Added `six` requirement and cleaned up lines for PEP8.
pferate Jan 16, 2015
4c44841
Remove unused imports
maxwell-k Jan 27, 2015
9513711
Remove unnecessary assignments
maxwell-k Jan 27, 2015
08dfb1f
Decode request result if on Python 3
maxwell-k Jan 27, 2015
15babeb
Merge pull request #2 from maxwell-k/python3
pferate Jan 28, 2015
49b3bf0
Convert JSON content to str if it is bytes.
pferate Feb 18, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[report]
omit = */samples/*
exclude_lines =
# Re-enable the standard pragma
pragma: NO COVER
# Ignore debug-only repr
def __repr__
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@ dist/

# Test files
.tox/

# Coverage files
.coverage
coverage.xml
nosetests.xml

# IDE files
.idea/
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
language: python
python: 2.7
sudo: false
env:
matrix:
- TOX_ENV=py26
- TOX_ENV=py27
- TOX_ENV=py33
- TOX_ENV=py34
- TOX_ENV=pypy
install:
- pip install tox
script:
- tox -e $TOX_ENV
after_success:
- if [[ "${TOX_ENV}" == "py27" ]]; then tox -e coveralls27; fi
- if [[ "${TOX_ENV}" == "py34" ]]; then tox -e coveralls34; fi
notifications:
email: false
2 changes: 1 addition & 1 deletion apiclient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@
}

import sys
for module_name, module in _SUBMODULES.iteritems():
for module_name, module in _SUBMODULES.items():
sys.modules['apiclient.%s' % module_name] = module
27 changes: 12 additions & 15 deletions describe.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@
help='Directory name to write documents into.')



def safe_version(version):
"""Create a safe version of the verion string.

Expand Down Expand Up @@ -192,11 +191,11 @@ def method_params(doc):
doclines = doc.splitlines()
if 'Args:' in doclines:
begin = doclines.index('Args:')
if 'Returns:' in doclines[begin+1:]:
if 'Returns:' in doclines[begin + 1:]:
end = doclines.index('Returns:', begin)
args = doclines[begin+1: end]
args = doclines[begin + 1: end]
else:
args = doclines[begin+1:]
args = doclines[begin + 1:]

parameters = []
for line in args:
Expand All @@ -206,7 +205,7 @@ def method_params(doc):
pname = m.group(1)
desc = m.group(2)
if '(required)' not in desc:
pname = pname + '=None'
pname += '=None'
parameters.append(pname)
parameters = ', '.join(parameters)
else:
Expand Down Expand Up @@ -271,12 +270,11 @@ def document_collection(resource, path, root_discovery, discovery, css=CSS):
collections = []
methods = []
resource_name = path.split('.')[-2]
html = [
'<html><body>',
css,
'<h1>%s</h1>' % breadcrumbs(path[:-1], root_discovery),
'<h2>Instance Methods</h2>'
]
html = ['<html><body>',
css,
'<h1>%s</h1>' % breadcrumbs(path[:-1], root_discovery),
'<h2>Instance Methods</h2>'
]

# Which methods are for collections.
for name in dir(resource):
Expand All @@ -286,7 +284,6 @@ def document_collection(resource, path, root_discovery, discovery, css=CSS):
else:
methods.append(name)


# TOC
if collections:
for name in collections:
Expand Down Expand Up @@ -330,7 +327,8 @@ def document_collection_recursive(resource, path, root_discovery, discovery):
dname = name.rsplit('_')[0]
collection = getattr(resource, name)()
document_collection_recursive(collection, path + name + '.', root_discovery,
discovery['resources'].get(dname, {}))
discovery['resources'].get(dname, {}))


def document_api(name, version):
"""Document the given API.
Expand All @@ -344,8 +342,7 @@ def document_api(name, version):
uritemplate.expand(
FLAGS.discovery_uri_template, {
'api': name,
'apiVersion': version})
)
'apiVersion': version}))
discovery = json.loads(content)

version = safe_version(version)
Expand Down
3 changes: 1 addition & 2 deletions expandsymlinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ def _ignore(path, names):


def main():
copytree(FLAGS.source, FLAGS.dest, symlinks=True,
ignore=_ignore)
copytree(FLAGS.source, FLAGS.dest, symlinks=True, ignore=_ignore)


if __name__ == '__main__':
Expand Down
51 changes: 24 additions & 27 deletions googleapiclient/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,27 +68,26 @@

# 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'
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'
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 headers.iteritems():
for k, v in headers.items():
new_headers[k.upper()] = v
return new_headers

Expand Down Expand Up @@ -167,8 +166,8 @@ def __init__(self, type, id, token, address, expiration=None,
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.
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.
Expand All @@ -191,12 +190,11 @@ def body(self):
Returns:
A dictionary representation of the channel.
"""
result = {
'id': self.id,
'token': self.token,
'type': self.type,
'address': self.address
}
result = {'id': self.id,
'token': self.token,
'type': self.type,
'address': self.address
}
if self.params:
result['params'] = self.params
if self.resource_id:
Expand All @@ -218,7 +216,7 @@ def update(self, resp):
Args:
resp: dict, The response from a watch() method.
"""
for json_name, param_name in CHANNEL_PARAMS.iteritems():
for json_name, param_name in CHANNEL_PARAMS.items():
value = resp.get(json_name)
if value is not None:
setattr(self, param_name, value)
Expand Down Expand Up @@ -274,12 +272,11 @@ def new_webhook_channel(url, token=None, expiration=None, params=None):
expiration_ms = 0
if expiration:
delta = expiration - EPOCH
expiration_ms = delta.microseconds/1000 + (
delta.seconds + delta.days*24*3600)*1000
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)

Loading