<s> """<STR_LIT>""" <EOL> import time <EOL> import hashlib <EOL> import datetime <EOL> import mimetypes <EOL> from base64 import b64encode <EOL> from urllib import quote <EOL> from calendar import timegm <EOL> def _amz_canonicalize ( headers ) : <EOL> r"""<STR_LIT>""" <EOL> rv = { } <EOL> for header , value in headers . iteritems ( ) : <EOL> header = header . lower ( ) <EOL> if header . startswith ( "<STR_LIT>" ) : <EOL> rv . setdefault ( header , [ ] ) . append ( value ) <EOL> parts = [ ] <EOL> for key in sorted ( rv ) : <EOL> parts . append ( "<STR_LIT>" % ( key , "<STR_LIT:U+002C>" . join ( rv [ key ] ) ) ) <EOL> return "<STR_LIT>" . join ( parts ) <EOL> def metadata_headers ( metadata ) : <EOL> return dict ( ( "<STR_LIT>" + h , v ) for h , v in metadata . iteritems ( ) ) <EOL> def headers_metadata ( headers ) : <EOL> return dict ( ( h [ <NUM_LIT:11> : ] , v ) for h , v in headers . iteritems ( ) <EOL> if h . lower ( ) . startswith ( "<STR_LIT>" ) ) <EOL> iso8601_fmt = '<STR_LIT>' <EOL> def _iso8601_dt ( v ) : return datetime . datetime . strptime ( v , iso8601_fmt ) <EOL> def rfc822_fmtdate ( t = None ) : <EOL> from email . utils import formatdate <EOL> if t is None : <EOL> t = datetime . datetime . utcnow ( ) <EOL> return formatdate ( timegm ( t . timetuple ( ) ) , usegmt = True ) <EOL> def rfc822_parsedate ( v ) : <EOL> from email . utils import parsedate <EOL> return datetime . datetime . fromtimestamp ( time . mktime ( parsedate ( v ) ) ) <EOL> def expire2datetime ( expire , base = None ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( expire , "<STR_LIT>" ) : <EOL> return expire <EOL> if base is None : <EOL> base = datetime . datetime . now ( ) <EOL> try : <EOL> return base + expire <EOL> except TypeError : <EOL> unix_eighties = <NUM_LIT> <EOL> if expire < unix_eighties : <EOL> return base + datetime . timedelta ( seconds = expire ) <EOL> else : <EOL> return datetime . datetime . fromtimestamp ( expire ) <EOL> def aws_md5 ( data ) : <EOL> """<STR_LIT>""" <EOL> hasher = hashlib . new ( "<STR_LIT>" ) <EOL> if hasattr ( data , "<STR_LIT>" ) : <EOL> data . seek ( <NUM_LIT:0> ) <EOL> while True : <EOL> chunk = data . read ( <NUM_LIT> ) <EOL> if not chunk : <EOL> break <EOL> hasher . update ( chunk ) <EOL> data . seek ( <NUM_LIT:0> ) <EOL> else : <EOL> hasher . update ( data ) <EOL> return b64encode ( hasher . digest ( ) ) . decode ( "<STR_LIT:ascii>" ) <EOL> def aws_urlquote ( value ) : <EOL> r"""<STR_LIT>""" <EOL> if isinstance ( value , unicode ) : <EOL> value = value . encode ( "<STR_LIT:utf-8>" ) <EOL> return quote ( value , "<STR_LIT:/>" ) <EOL> def guess_mimetype ( fn , default = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> if "<STR_LIT:.>" not in fn : <EOL> return default <EOL> bfn , ext = fn . lower ( ) . rsplit ( "<STR_LIT:.>" , <NUM_LIT:1> ) <EOL> if ext == "<STR_LIT>" : ext = "<STR_LIT>" <EOL> return mimetypes . guess_type ( bfn + "<STR_LIT:.>" + ext ) [ <NUM_LIT:0> ] or default <EOL> def info_dict ( headers ) : <EOL> rv = { "<STR_LIT>" : headers , "<STR_LIT>" : headers_metadata ( headers ) } <EOL> if "<STR_LIT>" in headers : <EOL> rv [ "<STR_LIT:size>" ] = int ( headers [ "<STR_LIT>" ] ) <EOL> if "<STR_LIT>" in headers : <EOL> rv [ "<STR_LIT>" ] = headers [ "<STR_LIT>" ] <EOL> if "<STR_LIT:date>" in headers : <EOL> rv [ "<STR_LIT:date>" ] = rfc822_parsedate ( headers [ "<STR_LIT:date>" ] ) <EOL> if "<STR_LIT>" in headers : <EOL> rv [ "<STR_LIT>" ] = rfc822_parsedate ( headers [ "<STR_LIT>" ] ) <EOL> return rv <EOL> def name ( o ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( o , "<STR_LIT>" ) : <EOL> rv = o . __name__ <EOL> modname = getattr ( o , "<STR_LIT>" , None ) <EOL> if modname not in ( None , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> rv = o . __module__ + "<STR_LIT:.>" + rv <EOL> else : <EOL> for o in getattr ( o , "<STR_LIT>" , o . __class__ . __mro__ ) : <EOL> rv = name ( o ) <EOL> if rv is not None : <EOL> break <EOL> return rv </s>
