def params(self): """ A combined :class:`MultiDict` with values from :attr:`forms` and :attr:`GET`. File-uploads are not included. """ params = MultiDict(self.GET) for key, value in self.forms.iterallitems(): params[key] = value return params
def GET(self): """ The QUERY_STRING parsed into an instance of :class:`MultiDict`. """ data = parse_qs(self.query_string, keep_blank_values=True) get = self.environ['mole.get'] = MultiDict() for key, values in data.iteritems(): for value in values: get[key] = value return get
def files(self): """ File uploads parsed into an instance of :class:`MultiDict`. This property contains file uploads parsed from an `multipart/form-data` encoded POST request body. The values are instances of :class:`cgi.FieldStorage`. """ files = MultiDict() for name, item in self.POST.iterallitems(): if hasattr(item, 'filename'): files[name] = item return files
def forms(self): """ POST form values parsed into an instance of :class:`MultiDict`. This property contains form values parsed from an `url-encoded` or `multipart/form-data` encoded POST request bidy. The values are native strings. """ forms = MultiDict() for name, item in self.POST.iterallitems(): if not hasattr(item, 'filename'): forms[name] = item return forms
def POST(self): """ The combined values from :attr:`forms` and :attr:`files`. Values are either strings (form values) or instances of :class:`cgi.FieldStorage` (file uploads). """ post = MultiDict() safe_env = {'QUERY_STRING': ''} # Build a safe environment for cgi for key in ('REQUEST_METHOD', 'CONTENT_TYPE', 'CONTENT_LENGTH'): if key in self.environ: safe_env[key] = self.environ[key] if NCTextIOWrapper: fb = NCTextIOWrapper(self.body, encoding='ISO-8859-1', newline='\n') else: fb = self.body data = cgi.FieldStorage(fp=fb, environ=safe_env, keep_blank_values=True) for item in data.list or []: post[item.name] = item if item.filename else item.value return post
def append(self, key, value): return MultiDict.append(self, self.httpkey(key), str(value))
def get(self, key, default=None, index=-1): return MultiDict.get(self, self.httpkey(key), default, index)
def __delitem__(self, key): return MultiDict.__delitem__(self, self.httpkey(key))
def __contains__(self, key): return MultiDict.__contains__(self, self.httpkey(key))
def __getitem__(self, key): return MultiDict.__getitem__(self, self.httpkey(key)) def __delitem__(self, key): return MultiDict.__delitem__(self, self.httpkey(key))
def getall(self, key): return MultiDict.getall(self, self.httpkey(key)) def httpkey(self, key): return str(key).replace('_','-').title()
def replace(self, key, value): return MultiDict.replace(self, self.httpkey(key), str(value)) def getall(self, key): return MultiDict.getall(self, self.httpkey(key))
def append(self, key, value): return MultiDict.append(self, self.httpkey(key), str(value)) def replace(self, key, value): return MultiDict.replace(self, self.httpkey(key), str(value))
def get(self, key, default=None, index=-1): return MultiDict.get(self, self.httpkey(key), default, index) def append(self, key, value): return MultiDict.append(self, self.httpkey(key), str(value))
def __delitem__(self, key): return MultiDict.__delitem__(self, self.httpkey(key)) def __setitem__(self, key, value): self.replace(key, value)
def replace(self, key, value): return MultiDict.replace(self, self.httpkey(key), str(value))
def getall(self, key): return MultiDict.getall(self, self.httpkey(key))
def __contains__(self, key): return MultiDict.__contains__(self, self.httpkey(key)) def __getitem__(self, key): return MultiDict.__getitem__(self, self.httpkey(key))