home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1611 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  1.5 KB  |  41 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __all__ = [
  5.     '_defaultFetcher']
  6. __docformat__ = 'restructuredtext'
  7. __version__ = '$Id: tokenize2.py 1547 2008-12-10 20:42:26Z cthedot $'
  8. from cssutils import VERSION
  9. import encutils
  10. import errorhandler
  11. import urllib2
  12. import util
  13. log = errorhandler.ErrorHandler()
  14.  
  15. def _defaultFetcher(url):
  16.     request = urllib2.Request(url)
  17.     request.add_header('User-agent', 'cssutils %s (http://www.cthedot.de/cssutils/)' % VERSION)
  18.     
  19.     try:
  20.         res = urllib2.urlopen(request)
  21.     except OSError:
  22.         e = None
  23.         log.warn(e, error = OSError)
  24.     except (OSError, ValueError):
  25.         e = None
  26.         log.warn(u'ValueError, %s' % e.args[0], error = ValueError)
  27.     except urllib2.HTTPError:
  28.         e = None
  29.         log.warn(u'HTTPError opening url=%r: %s %s' % (url, e.code, e.msg), error = e)
  30.     except urllib2.URLError:
  31.         e = None
  32.         log.warn(u'URLError, %s' % e.reason, error = e)
  33.  
  34.     if res:
  35.         (mimeType, encoding) = encutils.getHTTPInfo(res)
  36.         if mimeType != u'text/css':
  37.             log.error(u'Expected "text/css" mime type for url=%r but found: %r' % (url, mimeType), error = ValueError)
  38.         
  39.         return (encoding, res.read())
  40.  
  41.