<s> import re <EOL> from django . core . handlers . wsgi import WSGIRequest <EOL> from django . http import HttpResponse <EOL> from webob import Request <EOL> from webob . descriptors import * <EOL> from webob . datetime_utils import * <EOL> from webob . headers import ResponseHeaders <EOL> _PARAM_RE = re . compile ( r'<STR_LIT>' , re . I ) <EOL> _OK_PARAM_RE = re . compile ( r'<STR_LIT>' , re . I ) <EOL> class WMRequest ( WSGIRequest , Request ) : <EOL> environ = None <EOL> path = None <EOL> method = None <EOL> META = None <EOL> def __init__ ( self , environ , * args , ** kwargs ) : <EOL> Request . __init__ ( self , environ ) <EOL> WSGIRequest . __init__ ( self , environ ) <EOL> self . url_args = args or [ ] <EOL> self . url_kwargs = kwargs or { } <EOL> webob_POST = Request . POST <EOL> webob_WGET = Request . GET <EOL> @ property <EOL> def str_POST ( self ) : <EOL> clength = self . environ . get ( '<STR_LIT>' ) <EOL> try : <EOL> return super ( WMRequest , self ) . str_POST <EOL> finally : <EOL> self . environ [ '<STR_LIT>' ] = clength <EOL> self . _seek_input ( ) <EOL> def _load_post_and_files ( self ) : <EOL> try : <EOL> return WSGIRequest . _load_post_and_files ( self ) <EOL> finally : <EOL> self . _seek_input ( ) <EOL> def _seek_input ( self ) : <EOL> if "<STR_LIT>" in self . environ : <EOL> try : <EOL> self . environ [ '<STR_LIT>' ] . seek ( <NUM_LIT:0> ) <EOL> except AttributeError : <EOL> pass <EOL> class WMResponse ( HttpResponse ) : <EOL> """<STR_LIT>""" <EOL> status_code = <NUM_LIT:200> <EOL> default_content_type = '<STR_LIT>' <EOL> default_charset = '<STR_LIT>' <EOL> unicode_errors = '<STR_LIT:strict>' <EOL> default_conditional_response = False <EOL> def __init__ ( self , content = '<STR_LIT>' , mimetype = None , status = None , <EOL> content_type = None , request = None ) : <EOL> if isinstance ( status , basestring ) : <EOL> ( status_code , status_reason ) = status . split ( "<STR_LIT:U+0020>" , <NUM_LIT:1> ) <EOL> status_code = int ( status_code ) <EOL> self . status_reason = status_reason or None <EOL> else : <EOL> status_code = status <EOL> self . status_reason = None <EOL> self . request = request <EOL> self . _headerlist = [ ] <EOL> HttpResponse . __init__ ( self , content = content , <EOL> status = status_code , content_type = content_type ) <EOL> def _headerlist__get ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _headers . values ( ) <EOL> def _headerlist__set ( self , value ) : <EOL> self . _headers = { } <EOL> if not isinstance ( value , list ) : <EOL> if hasattr ( value , '<STR_LIT>' ) : <EOL> value = value . items ( ) <EOL> value = list ( value ) <EOL> headers = ResponseHeaders . view_list ( self . headerlist ) <EOL> for hname in headers . keys ( ) : <EOL> self . _headers [ hname . lower ( ) ] = ( hname , headers [ hname ] ) <EOL> self . _headerlist = value <EOL> def _headerlist__del ( self ) : <EOL> self . headerlist = [ ] <EOL> self . _headers = { } <EOL> headerlist = property ( _headerlist__get , _headerlist__set , _headerlist__del , doc = _headerlist__get . __doc__ ) <EOL> def __setitem__ ( self , header , value ) : <EOL> header , value = self . _convert_to_ascii ( header , value ) <EOL> self . _headers [ header . lower ( ) ] = ( header , value ) <EOL> def __delitem__ ( self , header ) : <EOL> try : <EOL> del self . _headers [ header . lower ( ) ] <EOL> except KeyError : <EOL> return <EOL> def __getitem__ ( self , header ) : <EOL> return self . _headers [ header . lower ( ) ] [ <NUM_LIT:1> ] <EOL> allow = list_header ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> vary = list_header ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> content_length = converter ( <EOL> header_getter ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> parse_int , serialize_int , '<STR_LIT:int>' ) <EOL> content_encoding = header_getter ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> content_language = list_header ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> content_location = header_getter ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> content_md5 = header_getter ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> content_disposition = header_getter ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> accept_ranges = header_getter ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> content_range = converter ( <EOL> header_getter ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> parse_content_range , serialize_content_range , '<STR_LIT>' ) <EOL> date = date_header ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> expires = date_header ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> last_modified = date_header ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> etag = converter ( <EOL> header_getter ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> parse_etag_response , serialize_etag_response , '<STR_LIT>' ) <EOL> location = header_getter ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> pragma = header_getter ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> age = converter ( <EOL> header_getter ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> parse_int_safe , serialize_int , '<STR_LIT:int>' ) <EOL> retry_after = converter ( <EOL> header_getter ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> parse_date_delta , serialize_date_delta , '<STR_LIT>' ) <EOL> server = header_getter ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def _convert_to_ascii ( self , header , value ) : <EOL> def convert ( s ) : <EOL> try : <EOL> return s . decode ( '<STR_LIT:ascii>' ) <EOL> except AttributeError : <EOL> return s <EOL> return convert ( header ) , convert ( value ) <EOL> def _charset__get ( self ) : <EOL> """<STR_LIT>""" <EOL> header = self . _headers . get ( '<STR_LIT>' ) <EOL> if not header : <EOL> return None <EOL> match = CHARSET_RE . search ( header [ <NUM_LIT:1> ] ) <EOL> if match : <EOL> return match . group ( <NUM_LIT:1> ) <EOL> return None <EOL> def _charset__set ( self , charset ) : <EOL> if charset is None : <EOL> del self . charset <EOL> return <EOL> try : <EOL> hname , header = self . _headers . pop ( '<STR_LIT>' ) <EOL> except KeyError : <EOL> raise AttributeError ( <EOL> "<STR_LIT>" ) <EOL> match = CHARSET_RE . search ( header ) <EOL> if match : <EOL> header = header [ : match . start ( ) ] + header [ match . end ( ) : ] <EOL> header += '<STR_LIT>' % charset <EOL> self . _headers [ '<STR_LIT>' ] = hname , header <EOL> def _charset__del ( self ) : <EOL> try : <EOL> hname , header = self . _headers . pop ( '<STR_LIT>' ) <EOL> except KeyError : <EOL> return <EOL> match = CHARSET_RE . search ( header ) <EOL> if match : <EOL> header = header [ : match . start ( ) ] + header [ match . end ( ) : ] <EOL> self [ hname ] = header <EOL> charset = property ( _charset__get , _charset__set , _charset__del , doc = _charset__get . __doc__ ) <EOL> def _content_type__get ( self ) : <EOL> """<STR_LIT>""" <EOL> header = self . _headers . get ( '<STR_LIT>' ) <EOL> if not header : <EOL> return None <EOL> return header [ <NUM_LIT:1> ] . split ( '<STR_LIT:;>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> def _content_type__set ( self , value ) : <EOL> if '<STR_LIT:;>' not in value : <EOL> if '<STR_LIT>' in self . _headers : <EOL> header = self . _headers . get ( '<STR_LIT>' ) <EOL> if '<STR_LIT:;>' in header [ <NUM_LIT:1> ] : <EOL> params = header [ <NUM_LIT:1> ] . split ( '<STR_LIT:;>' , <NUM_LIT:1> ) [ <NUM_LIT:1> ] <EOL> value += '<STR_LIT:;>' + params <EOL> self [ '<STR_LIT:Content-Type>' ] = value <EOL> def _content_type__del ( self ) : <EOL> try : <EOL> del self . _headers [ '<STR_LIT>' ] <EOL> except KeyError : <EOL> pass <EOL> content_type = property ( _content_type__get , _content_type__set , <EOL> _content_type__del , doc = _content_type__get . __doc__ ) <EOL> def _content_type_params__get ( self ) : <EOL> """<STR_LIT>""" <EOL> if not '<STR_LIT>' in self . _headers : <EOL> return { } <EOL> params = self . _headers . get ( '<STR_LIT>' ) <EOL> if '<STR_LIT:;>' not in params [ <NUM_LIT:1> ] : <EOL> return { } <EOL> params = params [ <NUM_LIT:1> ] . split ( '<STR_LIT:;>' , <NUM_LIT:1> ) [ <NUM_LIT:1> ] <EOL> result = { } <EOL> for match in _PARAM_RE . finditer ( params ) : <EOL> result [ match . group ( <NUM_LIT:1> ) ] = match . group ( <NUM_LIT:2> ) or match . group ( <NUM_LIT:3> ) or '<STR_LIT>' <EOL> return result <EOL> def _content_type_params__set ( self , value_dict ) : <EOL> if not value_dict : <EOL> del self . content_type_params <EOL> return <EOL> params = [ ] <EOL> for k , v in sorted ( value_dict . items ( ) ) : <EOL> if not _OK_PARAM_RE . search ( v ) : <EOL> v = '<STR_LIT>' % v . replace ( '<STR_LIT:">' , '<STR_LIT>' ) <EOL> params . append ( '<STR_LIT>' % ( k , v ) ) <EOL> ct = self . _headers . pop ( '<STR_LIT>' ) <EOL> if not ct : <EOL> ct = '<STR_LIT>' <EOL> else : <EOL> ct = ct [ <NUM_LIT:1> ] . split ( '<STR_LIT:;>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> ct += '<STR_LIT>' . join ( params ) <EOL> self . _headers [ '<STR_LIT>' ] = '<STR_LIT:Content-Type>' , ct <EOL> def _content_type_params__del ( self , value ) : <EOL> try : <EOL> header = self . _headers [ '<STR_LIT>' ] <EOL> except KeyError : <EOL> return <EOL> self . _headers [ '<STR_LIT>' ] = header [ <NUM_LIT:0> ] , header [ <NUM_LIT:1> ] . split ( '<STR_LIT:;>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> content_type_params = property ( <EOL> _content_type_params__get , <EOL> _content_type_params__set , <EOL> _content_type_params__del , <EOL> doc = _content_type_params__get . __doc__ <EOL> ) </s>
