<s> """<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> import atom . http_core <EOL> class Error ( Exception ) : <EOL> pass <EOL> class MissingHost ( Error ) : <EOL> pass <EOL> class AtomPubClient ( object ) : <EOL> host = None <EOL> auth_token = None <EOL> ssl = False <EOL> def __init__ ( self , http_client = None , host = None , <EOL> auth_token = None , source = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . http_client = http_client or atom . http_core . ProxiedHttpClient ( ) <EOL> if host is not None : <EOL> self . host = host <EOL> if auth_token is not None : <EOL> self . auth_token = auth_token <EOL> self . source = source <EOL> def request ( self , method = None , uri = None , auth_token = None , <EOL> http_request = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> http_request = self . modify_request ( http_request ) <EOL> if isinstance ( uri , ( str , unicode ) ) : <EOL> uri = atom . http_core . Uri . parse_uri ( uri ) <EOL> if uri is not None : <EOL> uri . modify_request ( http_request ) <EOL> if isinstance ( method , ( str , unicode ) ) : <EOL> http_request . method = method <EOL> for name , value in kwargs . iteritems ( ) : <EOL> if value is not None : <EOL> value . modify_request ( http_request ) <EOL> if http_request . uri . scheme is None : <EOL> http_request . uri . scheme = '<STR_LIT:http>' <EOL> if self . ssl : <EOL> http_request . uri . scheme = '<STR_LIT>' <EOL> if http_request . uri . path is None : <EOL> http_request . uri . path = '<STR_LIT:/>' <EOL> if auth_token : <EOL> auth_token . modify_request ( http_request ) <EOL> elif self . auth_token : <EOL> self . auth_token . modify_request ( http_request ) <EOL> if http_request . uri . host is None : <EOL> raise MissingHost ( '<STR_LIT>' % ( <EOL> http_request . method , str ( http_request . uri ) ) ) <EOL> return self . http_client . request ( http_request ) <EOL> Request = request <EOL> def get ( self , uri = None , auth_token = None , http_request = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . request ( method = '<STR_LIT:GET>' , uri = uri , auth_token = auth_token , <EOL> http_request = http_request , ** kwargs ) <EOL> Get = get <EOL> def post ( self , uri = None , data = None , auth_token = None , http_request = None , <EOL> ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . request ( method = '<STR_LIT:POST>' , uri = uri , auth_token = auth_token , <EOL> http_request = http_request , data = data , ** kwargs ) <EOL> Post = post <EOL> def put ( self , uri = None , data = None , auth_token = None , http_request = None , <EOL> ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . request ( method = '<STR_LIT>' , uri = uri , auth_token = auth_token , <EOL> http_request = http_request , data = data , ** kwargs ) <EOL> Put = put <EOL> def delete ( self , uri = None , auth_token = None , http_request = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . request ( method = '<STR_LIT>' , uri = uri , auth_token = auth_token , <EOL> http_request = http_request , ** kwargs ) <EOL> Delete = delete <EOL> def modify_request ( self , http_request ) : <EOL> """<STR_LIT>""" <EOL> if http_request is None : <EOL> http_request = atom . http_core . HttpRequest ( ) <EOL> if self . host is not None and http_request . uri . host is None : <EOL> http_request . uri . host = self . host <EOL> if self . source : <EOL> http_request . headers [ '<STR_LIT>' ] = '<STR_LIT>' % self . source <EOL> else : <EOL> http_request . headers [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> return http_request <EOL> ModifyRequest = modify_request </s>
