def __init__(self, url, data=None, headers=Headers(),
                 origin_req_host=None, unverifiable=False,
                 cookies=True, cache=False, method=None,
                 ignore_errors=False, retries=MAX_HTTP_RETRIES):
        """
        This is a simple wrapper around a urllib2 request object which helps
        with some common tasks like serialization, cache, etc.

        :param method: None means choose the default (POST if data is not None)
        :param data: The post_data as a string
        """
        #
        # Save some information for later access in an easier way
        #
        self.url_object = url
        self.cookies = cookies
        self.get_from_cache = cache
        self.ignore_errors = ignore_errors
        self.retries_left = retries

        self.method = method
        if self.method is None:
            self.method = 'POST' if data else 'GET'

        if isinstance(headers, Headers):
            headers.tokens_to_value()
            
        headers = dict(headers)

        # Call the base class constructor
        urllib2.Request.__init__(self, url.url_encode(), data,
                                 headers, origin_req_host, unverifiable)
        RequestMixIn.__init__(self)
Exemple #2
0
    def __init__(self, url, data=None, headers=Headers(),
                 origin_req_host=None, unverifiable=False,
                 cookies=True, cache=False, method=None,
                 ignore_errors=False):
        """
        This is a simple wrapper around a urllib2 request object which helps
        with some common tasks like serialization, cache, etc.

        :param method: None means "choose the method in the default way":
                            if self.has_data():
                                return "POST"
                            else:
                                return "GET"
        """
        #
        # Save some information for later access in an easier way
        #
        self.url_object = url
        self.cookies = cookies
        self.get_from_cache = cache
        self.ignore_errors = ignore_errors

        self.method = method
        if self.method is None:
            self.method = 'POST' if data else 'GET'
        
        headers = dict(headers)

        # Call the base class constructor
        urllib2.Request.__init__(self, url.url_encode(), data,
                                 headers, origin_req_host, unverifiable)
        RequestMixIn.__init__(self)
Exemple #3
0
    def __init__(self,
                 url,
                 data=None,
                 headers=None,
                 origin_req_host=None,
                 unverifiable=False,
                 cookies=True,
                 session=None,
                 cache=False,
                 method=None,
                 error_handling=True,
                 retries=MAX_HTTP_RETRIES,
                 timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
                 new_connection=False,
                 follow_redirects=False,
                 use_basic_auth=True,
                 use_proxy=True,
                 debugging_id=None,
                 binary_response=False):
        """
        This is a simple wrapper around a urllib2 request object which helps
        with some common tasks like serialization, cache, etc.

        :param method: None means choose the default (POST if data is not None)
        :param data: The post_data as a string
        """
        headers = headers or Headers()
        #
        # Save some information for later access in an easier way
        #
        self.url_object = url
        self.cookies = cookies
        self.session = session
        self.get_from_cache = cache
        self.error_handling = error_handling
        self.retries_left = retries
        self.timeout = timeout
        self.new_connection = new_connection
        self.follow_redirects = follow_redirects
        self.use_basic_auth = use_basic_auth
        self.use_proxy = use_proxy
        self.debugging_id = debugging_id
        self._binary_response = binary_response

        self.method = method
        if self.method is None:
            self.method = 'POST' if data else 'GET'

        if isinstance(headers, Headers):
            headers.tokens_to_value()

        headers = dict(headers)

        # Call the base class constructor
        urllib2.Request.__init__(self, url.url_encode(), data, headers,
                                 origin_req_host, unverifiable)
        RequestMixIn.__init__(self)
Exemple #4
0
    def __init__(self, url, data=None, headers=Headers(),
                 origin_req_host=None, unverifiable=False,
                 cookies=True, cache=False, method=None,
                 error_handling=True, retries=MAX_HTTP_RETRIES,
                 timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
                 new_connection=False, follow_redirects=False,
                 use_basic_auth=True, use_proxy=True,
                 debugging_id=None, binary_response=False):
        """
        This is a simple wrapper around a urllib2 request object which helps
        with some common tasks like serialization, cache, etc.

        :param method: None means choose the default (POST if data is not None)
        :param data: The post_data as a string
        """
        #
        # Save some information for later access in an easier way
        #
        self.url_object = url
        self.cookies = cookies
        self.get_from_cache = cache
        self.error_handling = error_handling
        self.retries_left = retries
        self.timeout = timeout
        self.new_connection = new_connection
        self.follow_redirects = follow_redirects
        self.use_basic_auth = use_basic_auth
        self.use_proxy = use_proxy
        self.debugging_id = debugging_id
        self._binary_response = binary_response

        self.method = method
        if self.method is None:
            self.method = 'POST' if data else 'GET'

        if isinstance(headers, Headers):
            headers.tokens_to_value()
            
        headers = dict(headers)

        # Call the base class constructor
        urllib2.Request.__init__(self, url.url_encode(), data,
                                 headers, origin_req_host, unverifiable)
        RequestMixIn.__init__(self)
Exemple #5
0
    def __init__(self,
                 url,
                 data=None,
                 headers=Headers(),
                 origin_req_host=None,
                 unverifiable=False,
                 cookies=True,
                 cache=False,
                 method=None,
                 ignore_errors=False,
                 retries=None):
        """
        This is a simple wrapper around a urllib2 request object which helps
        with some common tasks like serialization, cache, etc.

        :param method: None means choose the default (POST if data is not None)
        :param data: The post_data as a string
        """
        #
        # Save some information for later access in an easier way
        #
        self.url_object = url
        self.cookies = cookies
        self.get_from_cache = cache
        self.ignore_errors = ignore_errors
        self.retries_left = retries

        self.method = method
        if self.method is None:
            self.method = 'POST' if data else 'GET'

        if isinstance(headers, Headers):
            headers.tokens_to_value()

        headers = dict(headers)

        # Call the base class constructor
        urllib2.Request.__init__(self, url.url_encode(), data, headers,
                                 origin_req_host, unverifiable)
        RequestMixIn.__init__(self)
Exemple #6
0
    def __init__(self,
                 url,
                 data=None,
                 headers=Headers(),
                 origin_req_host=None,
                 unverifiable=False,
                 cookies=True,
                 cache=False,
                 method=None,
                 ignore_errors=False):
        """
        This is a simple wrapper around a urllib2 request object which helps
        with some common tasks like serialization, cache, etc.

        :param method: None means "choose the method in the default way":
                            if self.has_data():
                                return "POST"
                            else:
                                return "GET"
        """
        #
        # Save some information for later access in an easier way
        #
        self.url_object = url
        self.cookies = cookies
        self.get_from_cache = cache
        self.ignore_errors = ignore_errors

        self.method = method
        if self.method is None:
            self.method = 'POST' if data else 'GET'

        headers = dict(headers)

        # Call the base class constructor
        urllib2.Request.__init__(self, url.url_encode(), data, headers,
                                 origin_req_host, unverifiable)
        RequestMixIn.__init__(self)