示例#1
0
 def save(self, session):
     if not os.path.isdir(self.config['data_dir']):
         libel.mkdir(self.config['data_dir'])
     file = open(os.path.join(self.config['data_dir'],
                              session.uuid), 'w+')
     file.write(json.dumps(session))
     file.close()
示例#2
0
 def _extract_post(self, environ):
     form_data = cgi.FieldStorage(fp=environ["wsgi.input"], environ=environ)
     form_values = {}
     for name in form_data:
         # type==file
         if form_data[name].filename:
             dir_ = os.path.join(config["paths"]["tmp"],
                                 str(uuid.uuid1()))
             filename = form_data[name].filename
             libel.mkdir(dir_)
             file = open(os.path.join(dir_, filename), "wb")
             file.write(form_data[name].file.read())
             file.close()
             form_values[name] = os.path.join(dir_, filename)
         # anything "normal"
         else:
             # TODO: should the encoding be hard-coded ?
             form_values[name] = form_data[name].value.decode('utf-8')
     return form_values