<s> try : <EOL> import urllib . parse as urllib_parse <EOL> from base64 import encodebytes <EOL> except ImportError : <EOL> import urllib as urllib_parse <EOL> from base64 import encodestring as encodebytes <EOL> class Auth ( object ) : <EOL> """<STR_LIT>""" <EOL> def encode_params ( self , base_url , method , params ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> def generate_headers ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> class UserPassAuth ( Auth ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , username , password ) : <EOL> self . username = username <EOL> self . password = password <EOL> def encode_params ( self , base_url , method , params ) : <EOL> return urllib_parse . urlencode ( params ) <EOL> def generate_headers ( self ) : <EOL> return { b"<STR_LIT>" : b"<STR_LIT>" + encodebytes ( <EOL> ( "<STR_LIT>" % ( self . username , self . password ) ) <EOL> . encode ( '<STR_LIT:utf8>' ) ) . strip ( b'<STR_LIT:\n>' ) <EOL> } <EOL> class NoAuth ( Auth ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> pass <EOL> def encode_params ( self , base_url , method , params ) : <EOL> return urllib_parse . urlencode ( params ) <EOL> def generate_headers ( self ) : <EOL> return { } <EOL> class MissingCredentialsError ( Exception ) : <EOL> pass </s>
