Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(2)  |  Call(1)  |  Derive(0)  |  Import(1)
Wrapper around ``urllib2.urlopen`` that uses the handlers and the
user agent string defined in the feedplatform configuration.

It further attempts to support unicode URLs, i.e. non-ascii characters
in both domain name and path.

This should be used whenever network access is required as part of the
aggregator functionality.

It also normalizes exception handling, which is slightly challenging,(more...)

        def urlopen(url, *args, **kwargs):
    """Wrapper around ``urllib2.urlopen`` that uses the handlers and the
    user agent string defined in the feedplatform configuration.

    It further attempts to support unicode URLs, i.e. non-ascii characters
    in both domain name and path.

    This should be used whenever network access is required as part of the
    aggregator functionality.

    It also normalizes exception handling, which is slightly challenging,
    and reraises ``UrlOpenError``s for exceptions that you likely want to
    handle was potentially expected.
    """
    opener = urllib2.build_opener(*config.URLLIB2_HANDLERS)
    try:
        url = asciify_url(url)
        request = urllib2.Request(url, *args, **kwargs)
        request.add_header('User-Agent', config.USER_AGENT)
        try:
            return opener.open(request)
        except Exception, e:
            # At least five different exceptions may occur here:
            #    - urllib2.URLError
            #    - httplib.HTTPException, e.g. "nun-numeric port"
            #    - IOError, e.g. "[Errno ftp error] 530 Login incorrect"
            #    - WindowsError, e.g. when opening from filesystem
            #    - ValueError, e.g. "unknown url type"
            # There are likely more. Instead of listing them explicitely,
            # we simple allow ourselves to capture everything.
            raise UrlOpenError("%s" % e)
    finally:
        opener.close()
        


src/f/e/feedplatform-HEAD/feedplatform/lib/addins/feeds/images.py   feedplatform(Download)
        if not hasattr(self, '_request'):
            try:
                self._request = util.urlopen(self.url)
            except util.UrlOpenError, e:
                raise ImageError('failed to download: %s' % e)

src/f/e/feedplatform-HEAD/tests/parsing/test_unicode_url.py   feedplatform(Download)
    def pass1(feed):
        from feedplatform.util import urlopen
        assert urlopen(UnicodeFile.query_url).read() == UnicodeFile.content