Skip to content
Myr

cleanups, response.fo

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Kenneth Reitz · committed by Kenneth Reitz · parent 850e1c7 · Browse files · 1 file+42 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+42 added−10 removed

  • other:+42 added−10 removed

1 file+42 added−10 removed

modified:requests/models.py+42 added-10 removed
9 unmodified lines
10import urllib211import socket12import zlib131415from urllib2 import HTTPError16from urlparse import urlparse, urlunparse, urljoin17from datetime import datetime18
1 unmodified line
20from .monkeys import Request as _Request, HTTPBasicAuthHandler, HTTPForcedBasicAuthHandler, HTTPDigestAuthHandler, HTTPRedirectHandler21from .structures import CaseInsensitiveDict22from .packages.poster.encode import multipart_encode23from .packages.poster.streaminghttp import register_openers, get_handlers23from .utils import dict_from_cookiejar24from .exceptions import RequestException, AuthenticationError, Timeout, URLRequired, InvalidMethod, TooManyRedirects24from .utils import dict_from_cookiejar, get_unicode_from_response25from .status_codes import codes26from .exceptions import RequestException, AuthenticationError, Timeout, URLRequired, InvalidMethod, TooManyRedirects272829REDIRECT_STATI = (codes.moved, codes.found, codes.other, codes.temporary_moved)30
101 unmodified lines
132 if self.cookiejar is not None:133 _handlers.append(urllib2.HTTPCookieProcessor(self.cookiejar))134135 if self.auth:135 if not isinstance(self.auth.handler, (urllib2.AbstractBasicAuthHandler, urllib2.AbstractDigestAuthHandler)):136 if not isinstance(self.auth.handler,137 (urllib2.AbstractBasicAuthHandler,138 urllib2.AbstractDigestAuthHandler)):139140 # TODO: REMOVE THIS COMPLETELY137 auth_manager.add_password(self.auth.realm, self.url, self.auth.username, self.auth.password)141 auth_manager.add_password(142 self.auth.realm, self.url,143 self.auth.username,144 self.auth.password)145146 self.auth.handler = self.auth.handler(auth_manager)147 auth_manager.add_auth(self.url, self.auth)148149 _handlers.append(self.auth.handler)
23 unmodified lines
173 return opener.open174175176 def _build_response(self, resp, is_error=False):169 """Build internal :class:`Response <models.Response>` object from given response."""177 """Build internal :class:`Response <models.Response>` object178 from given response.179 """180181182 def build(resp):183184 response = Response()185 response.status_code = getattr(resp, 'code', None)186187 try:188 response.headers = CaseInsensitiveDict(getattr(resp.info(), 'dict', None))189 response.read = resp.read179 response.readline = resp.readline180 response._resp = resp190 response.fo = resp191 response._close = resp.close192193 if self.cookiejar:194
233 unmodified lines
428429430 def __nonzero__(self):431 """Returns true if :attr:`status_code` is 'OK'."""432433 return not self.error434435436 def __getattr__(self, name):426 """Read and returns the full stream when accessing to :attr: `content`"""437 """Read and returns the full stream when accessing to438 :attr: `content`439 """440441 if name == 'content':442 if self._content is not None:443 return self._content444445 # Read the contents.446 self._content = self.read()447448 # Decode GZip'd content.449 if self.headers.get('content-encoding', '') == 'gzip':450 try:451 self._content = zlib.decompress(self._content, 16+zlib.MAX_WBITS)452 except zlib.error:453 pass454455 # Decode unicode content.456 try:457 self._content = get_unicode_from_response(self)458 # Don't trust this stuff.459 except UserWarning, e:460 print e461462463 return self._content464465 else:466 raise AttributeError467468469470 def raise_for_status(self):471 """Raises stored :class:`HTTPError` or :class:`URLError`, if one occured."""472 if self.error:473 raise self.error474475476 def close(self):447 if self._resp.fp is not None and hasattr(self._resp.fp, '_sock'):448 self._resp.fp._sock.recv = None477 if self.fo.fp is not None and hasattr(self.fo.fp, '_sock'):478 self.fo.fp._sock.recv = None479 self._close()480481482483class AuthManager(object):484 """Requests Authentication Manager."""485486 def __new__(cls):
170 unmodified lines