-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Python3 module updates #64
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
Merged
nathanielmanistaatgoogle
merged 11 commits into
googleapis:master
from
pferate:python3-module_updates
Mar 10, 2015
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ed9affd
Updating StringIO, BytesIO, and FileIO imports and usage. (Using six)
pferate d5b61bd
Updating urllib related imports and usage. (Using six)
pferate b240c17
Updating local imports (relative -> absolute)
pferate 9b0452c
Only decode if needed
pferate c9abbbd
Changed to use string explicitly
pferate 2b14022
Updating string buffers to byte buffers
pferate ca397a7
Encode UTF text only if in Python 2
pferate 73f8813
Changing tabs to spaces for consistency.
pferate c46e905
Verifying that media_upload.size() is not None
pferate c605087
Skipping tests in Python3
pferate 846befc
Changing iteritems() to six.iteritems()
pferate File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,34 +24,35 @@ | |
|
|
||
| __author__ = '[email protected] (Joe Gregorio)' | ||
|
|
||
| import StringIO | ||
| from six import BytesIO, StringIO | ||
| from six.moves.urllib.parse import urlparse, urlunparse, quote, unquote | ||
|
|
||
| import base64 | ||
| import copy | ||
| import gzip | ||
| import httplib2 | ||
| import json | ||
| import logging | ||
| from . import mimeparse | ||
| import mimetypes | ||
| import os | ||
| import random | ||
| import sys | ||
| import time | ||
| import urllib | ||
| import urlparse | ||
| import uuid | ||
|
|
||
| from email.generator import Generator | ||
| from email.mime.multipart import MIMEMultipart | ||
| from email.mime.nonmultipart import MIMENonMultipart | ||
| from email.parser import FeedParser | ||
| from .errors import BatchError | ||
| from .errors import HttpError | ||
| from .errors import InvalidChunkSizeError | ||
| from .errors import ResumableUploadError | ||
| from .errors import UnexpectedBodyError | ||
| from .errors import UnexpectedMethodError | ||
| from .model import JsonModel | ||
|
|
||
| from googleapiclient import mimeparse | ||
| from googleapiclient.errors import BatchError | ||
| from googleapiclient.errors import HttpError | ||
| from googleapiclient.errors import InvalidChunkSizeError | ||
| from googleapiclient.errors import ResumableUploadError | ||
| from googleapiclient.errors import UnexpectedBodyError | ||
| from googleapiclient.errors import UnexpectedMethodError | ||
| from googleapiclient.model import JsonModel | ||
| from oauth2client import util | ||
|
|
||
|
|
||
|
|
@@ -262,7 +263,7 @@ class MediaIoBaseUpload(MediaUpload): | |
| Note that the Python file object is compatible with io.Base and can be used | ||
| with this class also. | ||
|
|
||
| fh = io.BytesIO('...Some data to upload...') | ||
| fh = BytesIO('...Some data to upload...') | ||
| media = MediaIoBaseUpload(fh, mimetype='image/png', | ||
| chunksize=1024*1024, resumable=True) | ||
| farm.animals().insert( | ||
|
|
@@ -468,7 +469,7 @@ def __init__(self, body, mimetype='application/octet-stream', | |
| resumable: bool, True if this is a resumable upload. False means upload | ||
| in a single request. | ||
| """ | ||
| fd = StringIO.StringIO(body) | ||
| fd = BytesIO(body) | ||
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong. |
||
| super(MediaInMemoryUpload, self).__init__(fd, mimetype, chunksize=chunksize, | ||
| resumable=resumable) | ||
|
|
||
|
|
@@ -702,8 +703,8 @@ def execute(self, http=None, num_retries=0): | |
| self.method = 'POST' | ||
| self.headers['x-http-method-override'] = 'GET' | ||
| self.headers['content-type'] = 'application/x-www-form-urlencoded' | ||
| parsed = urlparse.urlparse(self.uri) | ||
| self.uri = urlparse.urlunparse( | ||
| parsed = urlparse(self.uri) | ||
| self.uri = urlunparse( | ||
| (parsed.scheme, parsed.netloc, parsed.path, parsed.params, None, | ||
| None) | ||
| ) | ||
|
|
@@ -1051,7 +1052,7 @@ def _id_to_header(self, id_): | |
| if self._base_id is None: | ||
| self._base_id = uuid.uuid4() | ||
|
|
||
| return '<%s+%s>' % (self._base_id, urllib.quote(id_)) | ||
| return '<%s+%s>' % (self._base_id, quote(id_)) | ||
|
|
||
| def _header_to_id(self, header): | ||
| """Convert a Content-ID header value to an id. | ||
|
|
@@ -1074,7 +1075,7 @@ def _header_to_id(self, header): | |
| raise BatchError("Invalid value for Content-ID: %s" % header) | ||
| base, id_ = header[1:-1].rsplit('+', 1) | ||
|
|
||
| return urllib.unquote(id_) | ||
| return unquote(id_) | ||
|
|
||
| def _serialize_request(self, request): | ||
| """Convert an HttpRequest object into a string. | ||
|
|
@@ -1086,9 +1087,9 @@ def _serialize_request(self, request): | |
| The request as a string in application/http format. | ||
| """ | ||
| # Construct status line | ||
| parsed = urlparse.urlparse(request.uri) | ||
| request_line = urlparse.urlunparse( | ||
| (None, None, parsed.path, parsed.params, parsed.query, None) | ||
| parsed = urlparse(request.uri) | ||
| request_line = urlunparse( | ||
| ('', '', parsed.path, parsed.params, parsed.query, '') | ||
| ) | ||
| status_line = request.method + ' ' + request_line + ' HTTP/1.1\n' | ||
| major, minor = request.headers.get('content-type', 'application/json').split('/') | ||
|
|
@@ -1113,7 +1114,7 @@ def _serialize_request(self, request): | |
| msg['content-length'] = str(len(request.body)) | ||
|
|
||
| # Serialize the mime message. | ||
| fp = StringIO.StringIO() | ||
| fp = StringIO() | ||
| # maxheaderlen=0 means don't line wrap headers. | ||
| g = Generator(fp, maxheaderlen=0) | ||
| g.flatten(msg, unixfrom=False) | ||
|
|
@@ -1123,7 +1124,7 @@ def _serialize_request(self, request): | |
| if request.body is None: | ||
| body = body[:-2] | ||
|
|
||
| return status_line.encode('utf-8') + body | ||
| return status_line + body | ||
|
|
||
| def _deserialize_response(self, payload): | ||
| """Convert string into httplib2 response and content. | ||
|
|
@@ -1236,7 +1237,7 @@ def _execute(self, http, order, requests): | |
|
|
||
| # encode the body: note that we can't use `as_string`, because | ||
| # it plays games with `From ` lines. | ||
| fp = StringIO.StringIO() | ||
| fp = StringIO() | ||
| g = Generator(fp, mangle_from_=False) | ||
| g.flatten(message, unixfrom=False) | ||
| body = fp.getvalue() | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.