<s> """<STR_LIT>""" <EOL> __all__ = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:GET>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:POST>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> from re import match <EOL> from flask import current_app , json , url_for , g <EOL> from werkzeug . datastructures import Headers <EOL> from tentd . lib . flask import JSONEncoder <EOL> def authorization_header ( ) : <EOL> """<STR_LIT>""" <EOL> macid = "<STR_LIT>" <EOL> tstamp = <NUM_LIT> <EOL> nonce = "<STR_LIT>" <EOL> mac = "<STR_LIT>" <EOL> return '<STR_LIT>' . format ( <EOL> macid , tstamp , nonce , mac ) <EOL> def build_url ( endpoint , base_url = None , ** kwargs ) : <EOL> if endpoint [ <NUM_LIT:0> ] == '<STR_LIT:/>' : <EOL> return endpoint , base_url <EOL> try : <EOL> url = url_for ( endpoint , ** kwargs ) <EOL> except KeyError : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> result = match ( "<STR_LIT>" , url ) <EOL> if result : <EOL> base_url , url = result . groups ( ) <EOL> return url , base_url <EOL> def HTTP ( type , endpoint , data = None , secure = False , <EOL> headers = None , content_type = '<STR_LIT>' , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> url , base_url = build_url ( endpoint , ** kwargs ) <EOL> if isinstance ( data , ( dict , list ) ) : <EOL> data = json . dumps ( data , cls = JSONEncoder ) <EOL> content_type = '<STR_LIT:application/json>' <EOL> if not hasattr ( current_app , '<STR_LIT>' ) : <EOL> raise NotImplementedError ( <EOL> "<STR_LIT>" ) <EOL> if not isinstance ( headers , Headers ) : <EOL> headers = Headers ( headers or { } ) <EOL> if secure : <EOL> headers . set ( '<STR_LIT>' , authorization_header ( ) ) <EOL> return getattr ( current_app . client , type ) ( <EOL> url , base_url = base_url , <EOL> data = data , headers = headers , content_type = content_type ) <EOL> def _wrap_http ( method_name ) : <EOL> return lambda * a , ** k : HTTP ( method_name , * a , ** k ) <EOL> def _wrap_http_secure ( method_name ) : <EOL> return lambda * a , ** k : HTTP ( method_name , * a , secure = True , ** k ) <EOL> DELETE = _wrap_http ( '<STR_LIT>' ) <EOL> GET = _wrap_http ( '<STR_LIT>' ) <EOL> HEAD = _wrap_http ( '<STR_LIT>' ) <EOL> POST = _wrap_http ( '<STR_LIT>' ) <EOL> PUT = _wrap_http ( '<STR_LIT>' ) <EOL> SDELETE = _wrap_http_secure ( '<STR_LIT>' ) <EOL> SGET = _wrap_http_secure ( '<STR_LIT>' ) <EOL> SHEAD = _wrap_http_secure ( '<STR_LIT>' ) <EOL> SPOST = _wrap_http_secure ( '<STR_LIT>' ) <EOL> SPUT = _wrap_http_secure ( '<STR_LIT>' ) </s>
