/usr/share/pyshared/cssutils/_fetchgae.py is in python-cssutils 0.9.10-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | """GAE specific URL reading functions"""
__all__ = ['_defaultFetcher']
__docformat__ = 'restructuredtext'
__version__ = '$Id: tokenize2.py 1547 2008-12-10 20:42:26Z cthedot $'
# raises ImportError of not on GAE
from google.appengine.api import urlfetch
import cgi
import errorhandler
import util
log = errorhandler.ErrorHandler()
def _defaultFetcher(url):
"""
uses GoogleAppEngine (GAE)
fetch(url, payload=None, method=GET, headers={}, allow_truncated=False)
Response
content
The body content of the response.
content_was_truncated
True if the allow_truncated parameter to fetch() was True and
the response exceeded the maximum response size. In this case,
the content attribute contains the truncated response.
status_code
The HTTP status code.
headers
The HTTP response headers, as a mapping of names to values.
Exceptions
exception InvalidURLError()
The URL of the request was not a valid URL, or it used an
unsupported method. Only http and https URLs are supported.
exception DownloadError()
There was an error retrieving the data.
This exception is not raised if the server returns an HTTP
error code: In that case, the response data comes back intact,
including the error code.
exception ResponseTooLargeError()
The response data exceeded the maximum allowed size, and the
allow_truncated parameter passed to fetch() was False.
"""
#from google.appengine.api import urlfetch
try:
r = urlfetch.fetch(url, method=urlfetch.GET)
except urlfetch.Error, e:
log.warn(u'Error opening url=%r: %s' % (url, e),
error=IOError)
else:
if r.status_code == 200:
# find mimetype and encoding
mimetype = 'application/octet-stream'
try:
mimetype, params = cgi.parse_header(r.headers['content-type'])
encoding = params['charset']
except KeyError:
encoding = None
if mimetype != u'text/css':
log.error(u'Expected "text/css" mime type for url %r but found: %r' %
(url, mimetype), error=ValueError)
return encoding, r.content
else:
# TODO: 301 etc
log.warn(u'Error opening url=%r: HTTP status %s' %
(url, r.status_code), error=IOError)
|