home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1612 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  1.4 KB  |  37 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 google.appengine.api import urlfetch
  9. import cgi
  10. import errorhandler
  11. import util
  12. log = errorhandler.ErrorHandler()
  13.  
  14. def _defaultFetcher(url):
  15.     
  16.     try:
  17.         r = urlfetch.fetch(url, method = urlfetch.GET)
  18.     except urlfetch.Error:
  19.         e = None
  20.         log.warn(u'Error opening url=%r: %s' % (url, e), error = IOError)
  21.  
  22.     if r.status_code == 200:
  23.         mimetype = 'application/octet-stream'
  24.         
  25.         try:
  26.             (mimetype, params) = cgi.parse_header(r.headers['content-type'])
  27.             encoding = params['charset']
  28.         except KeyError:
  29.             encoding = None
  30.  
  31.         if mimetype != u'text/css':
  32.             log.error(u'Expected "text/css" mime type for url %r but found: %r' % (url, mimetype), error = ValueError)
  33.         
  34.         return (encoding, r.content)
  35.     log.warn(u'Error opening url=%r: HTTP status %s' % (url, r.status_code), error = IOError)
  36.  
  37.