models cleanup
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 5f83471 · Browse files · 1 file·+11 added−27 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+11 added−27 removed
- other:+11 added−27 removed
Provenance
- Commit
e7efce9- Tree
ffa2044- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
5f83471
1 file changed+11 added−27 removed
modified:requests/models.py+11 added-27 removed
24 unmodified lines25 ConnectionError, HTTPError, RequestException, Timeout, TooManyRedirects,26 URLRequired, SSLError)27 from .utils import (28 get_encoding_from_headers, stream_untransfer, guess_filename, requote_uri,29- dict_from_string, supported_schemes)29+ dict_from_string, supported_schemes, stream_decode_response_unicode)30+from .compat import (31+ urlparse, urlunparse, urljoin, urlsplit, urlencode, str, bytes,32+ SimpleCookie, is_py2)33 31-from .compat import urlparse, urlunparse, urljoin, urlsplit, urlencode, quote, unquote, str, bytes, SimpleCookie, is_py3, is_py232-34 # Import chardet if it is available.35 try:36 import chardet37 except ImportError:1 unmodified line39 40 REDIRECT_STATI = (codes.moved, codes.found, codes.other, codes.temporary_moved)41 42 42-43 class Request(object):44 """The :class:`Request <Request>` object. It carries out all functionality of45 Requests. Recommended interface is with the Requests functions.46 """99 unmodified lines146 147 self.headers = headers148 self._poolmanager = _poolmanager149 150-150 def __repr__(self):151 return '<Request [%s]>' % (self.method)152 154-153 def _build_response(self, resp):154 """Build internal :class:`Response <Response>` object155 from given response.156 """95 unmodified lines252 redirect=True,253 config=self.config,254 timeout=self.timeout,255 _poolmanager=self._poolmanager,258- proxies = self.proxies,259- verify = self.verify,260- session = self.session256+ proxies=self.proxies,257+ verify=self.verify,258+ session=self.session259 )260 261 request.send()262 r = request.response4 unmodified lines267 self.response = r268 self.response.request = self269 self.response.cookies.update(self.cookies)270 273-271 @staticmethod272 def _encode_params(data):273 """Encode parameters in a piece of data.274 10 unmodified lines285 286 if hasattr(data, '__iter__') and not isinstance(data, str):287 data = dict(data)288 292-289 if hasattr(data, 'items'):290 result = []291 for k, vs in list(data.items()):292 for v in isinstance(vs, list) and vs or [vs]:14 unmodified lines307 308 # Support for unicode domain names and paths.309 scheme, netloc, path, params, query, fragment = urlparse(url)310 315-311 if not scheme:312 raise ValueError("Invalid URL %r: No schema supplied" % url)313 314 if not scheme in supported_schemes():54 unmodified lines369 url.append(query)370 371 return ''.join(url)372 378-373 def register_hook(self, event, hook):374 """Properly register a hook."""375 376 return self.hooks[event].append(hook)377 384-378 def send(self, anyway=False, prefetch=False):379 """Sends the request. Returns True of successful, false if not.380 If there was an HTTPError during transmission,381 self.response.status_code will contain the HTTPError code.88 unmodified lines470 # Allow self-specified cert location.471 if self.verify is not True:472 cert_loc = self.verify473 481-474 # Look for configuration.475 if not cert_loc:476 cert_loc = os.environ.get('REQUESTS_CA_BUNDLE')477 136 unmodified lines614 615 #: Dictionary of configurations for this request.616 self.config = {}617 626-618 def __repr__(self):619 return '<Response [%s]>' % (self.status_code)620 621 def __bool__(self):11 unmodified lines633 except HTTPError:634 return False635 return True636 646-637 def iter_content(self, chunk_size=10 * 1024, decode_unicode=False):638 """Iterates over the response data. This avoids reading the content639 at once into memory for large responses. The chunk size is the number640 of bytes it should read into memory. This is not necessarily the18 unmodified lines659 if resp.chunk_left is not None:660 pending_bytes = resp.chunk_left661 while pending_bytes:662 chunk = fp.read(min(chunk_size, pending_bytes))673- pending_bytes-=len(chunk)663+ pending_bytes -= len(chunk)664 yield chunk675- fp.read(2) # throw away crlf665+ fp.read(2) # throw away crlf666 while 1:667 #XXX correct line size? (httplib has 64kb, seems insane)668 pending_bytes = fp.readline(40).strip()669 pending_bytes = int(pending_bytes, 16)670 if pending_bytes == 0:671 break672 while pending_bytes:673 chunk = fp.read(min(chunk_size, pending_bytes))684- pending_bytes-=len(chunk)674+ pending_bytes -= len(chunk)675 yield chunk686- fp.read(2) # throw away crlf676+ fp.read(2) # throw away crlf677 self._content_consumed = True678 fp.close()679 690-680 if getattr(getattr(self.raw, '_original_response', None), 'chunked', False):681 gen = generate_chunked()682 else:683 gen = generate()4 unmodified lines688 gen = stream_decode_response_unicode(gen, self)689 690 return gen691 703-692 def iter_lines(self, chunk_size=10 * 1024, decode_unicode=None):693 """Iterates over the response data, one line at a time. This694 avoids reading the content at once into memory for large695 responses.45 unmodified lines741 742 self._content_consumed = True743 return self._content744 757-745 @property746 def text(self):747 """Content of the response, in unicode.748 22 unmodified lines771 pass772 773 return content774 788-775 def raise_for_status(self):776 """Raises stored :class:`HTTPError` or :class:`URLError`, if one occurred."""777 778 if self.error:6 unmodified lines785 raise HTTPError('%s Client Error' % self.status_code)786 787 elif (self.status_code >= 500) and (self.status_code < 600):788 raise HTTPError('%s Server Error' % self.status_code)803-804-