-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from pferate/python3-module_updates
Python 3 support.
- Loading branch information
Showing
10 changed files
with
183 additions
and
220 deletions.
There are no files selected for viewing
This file contains 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 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 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) | ||
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 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 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.