def POST(self, uri, data='', headers=Headers(), grep=True, cache=False, cookies=True, error_handling=True, timeout=None, _from=None): """ POST's data to a uri using a proxy, user agents, and other settings that where set previously. :param uri: This is the url where to post. :param data: A string with the data for the POST. :see: The GET() for documentation on the other parameters :return: An HTTPResponse object. """ if not isinstance(uri, URL): raise TypeError('The uri parameter of ExtendedUrllib.POST() must' ' be of url.URL type.') if not isinstance(headers, Headers): raise TypeError( 'The header parameter of ExtendedUrllib.POST() must' ' be of Headers type.') # Validate what I'm sending, init the library (if needed) self.setup() # # Create and send the request # # Please note that the cache=False overrides the user setting # since we *never* want to return cached responses for POST # requests. # data = str(data) new_connection = True if timeout is not None else False host = uri.get_domain() timeout = self.get_timeout(host) if timeout is None else timeout req = HTTPRequest(uri, data=data, cookies=cookies, cache=False, error_handling=error_handling, method='POST', retries=self.settings.get_max_retrys(), timeout=timeout, new_connection=new_connection) req = self.add_headers(req, headers) req._from = _from return self.send(req, grep=grep)
def GET(self, uri, data=None, headers=Headers(), cache=False, grep=True, cookies=True, respect_size_limit=True, error_handling=True, timeout=None, _from=None): """ HTTP GET a URI using a proxy, user agent, and other settings that where previously set in opener_settings.py . :param uri: This is the URI to GET, with the query string included. :param data: Only used if the uri parameter is really a URL. The data will be converted into a string and set as the URL object query string before sending. :param headers: Any special headers that will be sent with this request :param cache: Should the library search the local cache for a response before sending it to the wire? :param grep: Should grep plugins be applied to this request/response? :param timeout: If None we'll use the configured (opener settings) timeout or the auto-adjusted value. Otherwise we'll use the defined timeout as the socket timeout value for this request. The timeout is specified in seconds :param cookies: Send stored cookies in request (or not) :return: An HTTPResponse object. """ if not isinstance(uri, URL): raise TypeError('The uri parameter of ExtendedUrllib.GET() must be' ' of url.URL type.') if not isinstance(headers, Headers): raise TypeError('The header parameter of ExtendedUrllib.GET() must' ' be of Headers type.') # Validate what I'm sending, init the library (if needed) self.setup() if data: uri = uri.copy() uri.querystring = data new_connection = True if timeout is not None else False host = uri.get_domain() timeout = self.get_timeout(host) if timeout is None else timeout req = HTTPRequest(uri, cookies=cookies, cache=cache, error_handling=error_handling, method='GET', retries=self.settings.get_max_retrys(), timeout=timeout, new_connection=new_connection) req = self.add_headers(req, headers) req._from = _from with raise_size_limit(respect_size_limit): return self.send(req, grep=grep)