<s> try : <EOL> from urllib . parse import urlencode <EOL> except ImportError : <EOL> from urllib import urlencode <EOL> from . filepost import encode_multipart_formdata <EOL> __all__ = [ '<STR_LIT>' ] <EOL> class RequestMethods ( object ) : <EOL> """<STR_LIT>""" <EOL> _encode_url_methods = set ( [ '<STR_LIT>' , '<STR_LIT:GET>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> _encode_body_methods = set ( [ '<STR_LIT>' , '<STR_LIT:POST>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def urlopen ( self , method , url , body = None , headers = None , <EOL> encode_multipart = True , multipart_boundary = None , <EOL> ** kw ) : <EOL> raise NotImplemented ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> def request ( self , method , url , fields = None , headers = None , ** urlopen_kw ) : <EOL> """<STR_LIT>""" <EOL> method = method . upper ( ) <EOL> if method in self . _encode_url_methods : <EOL> return self . request_encode_url ( method , url , fields = fields , <EOL> headers = headers , <EOL> ** urlopen_kw ) <EOL> else : <EOL> return self . request_encode_body ( method , url , fields = fields , <EOL> headers = headers , <EOL> ** urlopen_kw ) <EOL> def request_encode_url ( self , method , url , fields = None , ** urlopen_kw ) : <EOL> """<STR_LIT>""" <EOL> if fields : <EOL> url += '<STR_LIT:?>' + urlencode ( fields ) <EOL> return self . urlopen ( method , url , ** urlopen_kw ) <EOL> def request_encode_body ( self , method , url , fields = None , headers = None , <EOL> encode_multipart = True , multipart_boundary = None , <EOL> ** urlopen_kw ) : <EOL> """<STR_LIT>""" <EOL> if encode_multipart : <EOL> body , content_type = encode_multipart_formdata ( fields or { } , <EOL> boundary = multipart_boundary ) <EOL> else : <EOL> body , content_type = ( urlencode ( fields or { } ) , <EOL> '<STR_LIT>' ) <EOL> headers = headers or { } <EOL> headers . update ( { '<STR_LIT:Content-Type>' : content_type } ) <EOL> return self . urlopen ( method , url , body = body , headers = headers , <EOL> ** urlopen_kw ) <EOL> def get_url ( self , url , fields = None , ** urlopen_kw ) : <EOL> """<STR_LIT>""" <EOL> return self . request_encode_url ( '<STR_LIT:GET>' , url , fields = fields , <EOL> ** urlopen_kw ) <EOL> def post_url ( self , url , fields = None , headers = None , ** urlopen_kw ) : <EOL> """<STR_LIT>""" <EOL> return self . request_encode_body ( '<STR_LIT:POST>' , url , fields = fields , <EOL> headers = headers , <EOL> ** urlopen_kw ) </s>
