Example #1
0
    def prepare(self, request, progress_callback=None, connect_callback=None):
        request.client = self

        self.header = []
        self.body = []

        self._apply_debug_setting(request)
        self._apply_progress_setting(progress_callback)

        domain, request.url = self._apply_dnscache_setting(request, connect_callback)

        profile = self.profile or SiteProfile.get(domain)
        profile.apply(self.curl)

        self.curl.setopt(pycurl.URL, request.url)

        self._apply_pagecache_setting(request)
        self._apply_request_setting(request)
        self._apply_timeout_setting(request)
        self._apply_network_setting(request)
        self._apply_http_setting(request)
        self._apply_ssl_setting(request)
        self._apply_redirect_setting(request)
        self._apply_auth_setting(request)
        self._apply_proxy_setting(request)
Example #2
0
def urlopen(url_or_request, data_or_reader=None, headers={}, method=None,
            guess_encoding=None, dnscache=None, pagecache=None,
            connect_callback=None, progress_callback=None,
            session_timeout=None, connect_timeout=None, *args, **kwds):

    if issubclass(type(url_or_request), HttpRequest):
        request = url_or_request
    else:
        request = HttpRequest(str(url_or_request), data_or_reader, headers, method, *args, **kwds)

    if session_timeout or connect_timeout:
        profile = SiteProfile.get(request.hostname)
        profile.timeout = session_timeout
        profile.connect_timeout = connect_timeout
    else:
        profile = None

    return HttpClient(dnscache=dnscache, pagecache=pagecache,
        profile=profile, guess_encoding=guess_encoding) \
            .perform(request, progress_callback, connect_callback)