<s> from __future__ import absolute_import <EOL> 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> def __init__ ( self , headers = None ) : <EOL> self . headers = headers or { } <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 , headers = None , <EOL> ** urlopen_kw ) : <EOL> """<STR_LIT>""" <EOL> if headers is None : <EOL> headers = self . headers <EOL> extra_kw = { '<STR_LIT>' : headers } <EOL> extra_kw . update ( urlopen_kw ) <EOL> if fields : <EOL> url += '<STR_LIT:?>' + urlencode ( fields ) <EOL> return self . urlopen ( method , url , ** extra_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 headers is None : <EOL> headers = self . headers <EOL> extra_kw = { '<STR_LIT>' : { } } <EOL> if fields : <EOL> if '<STR_LIT:body>' in urlopen_kw : <EOL> raise TypeError ( <EOL> "<STR_LIT>" ) <EOL> if encode_multipart : <EOL> body , content_type = encode_multipart_formdata ( fields , boundary = multipart_boundary ) <EOL> else : <EOL> body , content_type = urlencode ( fields ) , '<STR_LIT>' <EOL> extra_kw [ '<STR_LIT:body>' ] = body <EOL> extra_kw [ '<STR_LIT>' ] = { '<STR_LIT:Content-Type>' : content_type } <EOL> extra_kw [ '<STR_LIT>' ] . update ( headers ) <EOL> extra_kw . update ( urlopen_kw ) <EOL> return self . urlopen ( method , url , ** extra_kw ) </s>
