![]() # Note that prepare_auth must be last to enable authentication schemes # such as OAuth to work on a fully prepared request. Params=None, auth=None, cookies=None, hooks=None, json=None): """Prepares the entire request with the given parameters.""" Method=None, url=None, headers=None, files=None, data=None, Self._body_position = None def prepare (self, #: integer denoting starting position of a readable file-like body. Self.body = None #: dictionary of callback hooks, for internal usage. Self._cookies = None #: request body to send to the server. Self.headers = None # The `CookieJar` used to create the Cookie header will be stored here # after prepare_cookies is called Self.url = None #: dictionary of HTTP headers. thod = None #: HTTP URL to send the request to. """ def _init_ (self): #: HTTP verb to send to the server. Generated from either a :class:`Request ` object or manually. :param files: dictionary of if params is None else paramsĭef _repr_ (self): return '' % (thod)ĭef prepare (self): """Constructs a :class:`PreparedRequest ` for transmission and returns it."""Ĭlass PreparedRequest (RequestEncodingMixin, RequestHooksMixin): """The fully mutable :class:`PreparedRequest ` object,Ĭontaining the exact bytes that will be sent to the server. :param headers: dictionary of headers to send. Used to prepare a :class:`PreparedRequest `, which is sent to the server. Return False class Request (RequestHooksMixin): """A user-created :class:`Request ` object. Returns True if the hook existed, False if not. ![]() (h for h in hook if isinstance(h, Callable))ĭef deregister_hook (self, event, hook): """Deregister a previously registered hook. Raise ValueError( 'Unsupported event specified, with event name "%s"' % (event)) Rf = RequestField(name=k, data=fdata, filename=fn, headers=fh)īody, content_type = encode_multipart_formdata(new_fields)Ĭlass RequestHooksMixin (object): def register_hook (self, event, hook): """Properly register a hook.""" if event not in self.hooks: If isinstance(fp, (str, bytes, bytearray)): (code( 'utf-8') if isinstance(field, bytes) else field,įh = None if isinstance(v, (tuple, list)): ![]() # Don't call str() on bytestrings: in P圓 it all goes wrong. If isinstance(val, basestring) or not hasattr(val, '_iter_'): Raise ValueError( "Data must not be a string.") Raise ValueError( "Files must be provided.") Or 4-tuples (filename, fileobj, contentype, custom_headers). The tuples may be 2-tuples (filename, fileobj), 3-tuples (filename, fileobj, contentype) Order is retained if data is a list of tuples but arbitrary ![]() Will successfully encode files when passed as a dict or a list of Return def _encode_files (files, data): """Build the body for a multipart/form-data request. V.encode( 'utf-8') if isinstance(v, str) else v)) (k.encode( 'utf-8') if isinstance(k, str) else k, If isinstance(vs, basestring) or not hasattr(vs, '_iter_'): Order is retained if data is a list of 2-tuples but arbitrary Will successfully encode parameters when passed as a dict or a list ofĢ-tuples. Return def _encode_params (data): """Encode parameters in a piece of data. ITER_CHUNK_SIZE = 512 class RequestEncodingMixin (object): def path_url (self): """Build the path URL to use.""" #: The set of HTTP status codes that indicate an automatically #: processable redirect. Is_py2, chardet, builtin_str, basestring) Iter_slices, guess_json_utf, super_len, check_header_validity)Ĭookielib, urlunparse, urlsplit, urlencode, str, bytes, Stream_decode_response_unicode, to_key_val_list, parse_header_links, Guess_filename, get_auth_from_url, requote_uri, _internal_utils import to_native_string, unicode_is_ascii HTTPError, MissingSchema, InvalidURL, ChunkedEncodingError,ĬontentDecodingError, ConnectionError, StreamConsumedError)įrom. cookies import cookiejar_from_dict, get_cookie_header, _copy_cookie_jar structures import CaseInsensitiveDictįrom. import encodings.idnaįrom urllib3.filepost import encode_multipart_formdataĭecodeError, ReadTimeoutError, ProtocolError, LocationParseError)įrom. # Implicit import within threads may cause LookupError when standard library is in a ZIP, # such as in Embedded Python. # Import encoding now, to avoid implicit import later. This module contains the primary objects that power Requests.
0 Comments
Leave a Reply. |