Python urllib2.addinfourl() Examples
The following are 7
code examples of urllib2.addinfourl().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
urllib2
, or try the search function
.
Example #1
Source File: api.py From plugin.video.youtube with GNU General Public License v2.0 | 5 votes |
def http_error_default(self, req, fp, code, msg, hdrs): infourl = urllib.addinfourl(fp, hdrs, req.get_full_url()) infourl.status = code infourl.code = code return infourl
Example #2
Source File: api.py From plugin.video.youtube with GNU General Public License v2.0 | 5 votes |
def http_error_302(self, req, fp, code, msg, headers): infourl = urllib.addinfourl(fp, headers, req.get_full_url()) infourl.status = code infourl.code = code return infourl
Example #3
Source File: api.py From ecmwf-api-client with Apache License 2.0 | 5 votes |
def http_error_303(self, req, fp, code, msg, headers): infourl = addinfourl(fp, headers, req.get_full_url()) infourl.status = code infourl.code = code return infourl
Example #4
Source File: api.py From Start-MAJA with GNU General Public License v3.0 | 5 votes |
def http_error_303(self, req, fp, code, msg, headers): infourl = addinfourl(fp, headers, req.get_full_url()) infourl.status = code infourl.code = code return infourl
Example #5
Source File: appengine_rpc.py From browserscope with Apache License 2.0 | 4 votes |
def http_response(self, req, resp): """Handle encodings in the order that they are encountered.""" encodings = [] headers = resp.headers for header in headers: if header.lower() == "content-encoding": for encoding in headers.get(header, "").split(","): encoding = encoding.strip() if encoding: encodings.append(encoding) break if not encodings: return resp del headers[header] fp = resp while encodings and encodings[-1].lower() == "gzip": fp = cStringIO.StringIO(fp.read()) fp = gzip.GzipFile(fileobj=fp, mode="r") encodings.pop() if encodings: headers[header] = ", ".join(encodings) logger.warning("Unrecognized Content-Encoding: %s", encodings[-1]) msg = resp.msg if sys.version_info >= (2, 6): resp = urllib2.addinfourl(fp, headers, resp.url, resp.code) else: response_code = resp.code resp = urllib2.addinfourl(fp, headers, resp.url) resp.code = response_code resp.msg = msg return resp
Example #6
Source File: utils.py From kelner with MIT License | 4 votes |
def s3_open(self, req): # The implementation was inspired mainly by the code behind # urllib.request.FileHandler.file_open(). # # recipe copied from: # http://code.activestate.com/recipes/578957-urllib-handler-for-amazon-s3-buckets/ # converted to boto3 if version_info[0] < 3: bucket_name = req.get_host() key_name = url2pathname(req.get_selector())[1:] else: bucket_name = req.host key_name = url2pathname(req.selector)[1:] if not bucket_name or not key_name: raise URLError('url must be in the format s3://<bucket>/<key>') s3 = boto3.resource('s3') key = s3.Object(bucket_name, key_name) client = boto3.client('s3') obj = client.get_object(Bucket=bucket_name, Key=key_name) filelike = _FileLikeKey(obj['Body']) origurl = 's3://{}/{}'.format(bucket_name, key_name) if key is None: raise URLError('no such resource: {}'.format(origurl)) headers = [ ('Content-type', key.content_type), ('Content-encoding', key.content_encoding), ('Content-language', key.content_language), ('Content-length', key.content_length), ('Etag', key.e_tag), ('Last-modified', key.last_modified), ] headers = email.message_from_string( '\n'.join('{}: {}'.format(key, value) for key, value in headers if value is not None)) return addinfourl(filelike, headers, origurl)
Example #7
Source File: appengine_rpc.py From python-compat-runtime with Apache License 2.0 | 4 votes |
def http_response(self, req, resp): """Handle encodings in the order that they are encountered.""" encodings = [] headers = resp.headers encoding_header = None for header in headers: if header.lower() == "content-encoding": encoding_header = header for encoding in headers[header].split(","): encoding = encoding.strip() if encoding: encodings.append(encoding) break if not encodings: return resp del headers[encoding_header] fp = resp while encodings and encodings[-1].lower() == "gzip": fp = cStringIO.StringIO(fp.read()) fp = gzip.GzipFile(fileobj=fp, mode="r") encodings.pop() if encodings: headers[encoding_header] = ", ".join(encodings) logger.warning("Unrecognized Content-Encoding: %s", encodings[-1]) msg = resp.msg if sys.version_info >= (2, 6): resp = urllib2.addinfourl(fp, headers, resp.url, resp.code) else: response_code = resp.code resp = urllib2.addinfourl(fp, headers, resp.url) resp.code = response_code resp.msg = msg return resp