Skip to content
Myr

basic get request works

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 3127a34 · Browse files · 1 file+70 added−9 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+70 added−9 removed

  • other:+70 added−9 removed

1 file+70 added−9 removed

modified:requests/models.py+70 added-9 removed
14 unmodified lines
15from urllib2 import HTTPError16from urlparse import urlparse, urlunparse, urljoin17from datetime import datetime181920from .packages import urllib321print dir(urllib3)2223from .config import settings24from .monkeys import Request as _Request, HTTPBasicAuthHandler, HTTPForcedBasicAuthHandler, HTTPDigestAuthHandler, HTTPRedirectHandler25from .structures import CaseInsensitiveDict22from .packages.poster.encode import multipart_encode23from .packages.poster.streaminghttp import register_openers, get_handlers26# from .packages.poster.encode import multipart_encode27# from .packages.poster.streaminghttp import register_openers, get_handlers28from .utils import dict_from_cookiejar, get_unicode_from_response, stream_decode_response_unicode, decode_gzip, stream_decode_gzip29from .status_codes import codes30from .exceptions import RequestException, AuthenticationError, Timeout, URLRequired, TooManyRedirects31
153 unmodified lines
185186 def build(resp):187188 response = Response()185 response.status_code = getattr(resp, 'code', None)189 response.status_code = getattr(resp, 'status', None)190191 try:188 response.headers = CaseInsensitiveDict(getattr(resp.info(), 'dict', None))189 response.fo = resp192 response.headers = CaseInsensitiveDict(getattr(resp, 'headers', None))193 # response.fo = resp194191 if self.cookiejar:195 # if self.cookiejar:196193 response.cookies = dict_from_cookiejar(self.cookiejar)197 # response.cookies = dict_from_cookiejar(self.cookiejar)198195199 except AttributeError:200 pass201202 if is_error:
15 unmodified lines
218 ((r.status_code is codes.see_other) or219 (self.allow_redirects))220 ):221219 r.fo.close()222 # r.fo.close()223224 if not len(history) < settings.max_redirects:225 raise TooManyRedirects()226
77 unmodified lines
304 return self.url305306307 def send(self, anyway=False):308 """Sends the shit."""309310 # Safety check.311 self._checks()312313 # Build the final URL.314 url = self._build_url()315316 # Setup Files.317 # Setup form data.318 #319 # def urlopen(self, method, url, body=None, headers=None, retries=3,320 # redirect=True, assert_same_host=True):321 # req = _Request(url, data=self._enc_data, method=self.method)322323324 if not self.sent or anyway:325326 try:327328 pool = urllib3.connection_from_url(url, timeout=self.timeout)329330 r = pool.urlopen(331 method=self.method,332 url=url,333 body=self.data,334 headers=self.headers,335 redirect=False,336 assert_same_host=False337 )338339 r.socket = pool._get_conn().sock340341 # if self.cookiejar is not None:342 # self.cookiejar.extract_cookies(resp, req)343344 # except (urllib2.HTTPError, urllib2.URLError), why:345 except Exception, why:346 # if hasattr(why, 'reason'):347 # if isinstance(why.reason, socket.timeout):348 # why = Timeout(why)349350 # self._build_response(why, is_error=True)351 print 'FUCK'352 print why353354 else:355 self._build_response(r)356 self.response.ok = True357358359 self.sent = self.response.ok360361 return self.sent362363364365 def old_send(self, anyway=False):366 """Sends the request. Returns True of successful, false if not.367 If there was an HTTPError during transmission,368 self.response.status_code will contain the HTTPError code.369
371 unmodified lines