def update_info(new_info): """Updates session info.""" session_id = get_session_id() session_key = SESSION_DIR + session_id info = get_session() info.update(new_info) info.id = session_id # this should not change file_storage.setItem(session_key, info) return info
def doLoadURLFast(url, cache_dir=CACHE_DIR, aged=AGED, timeout=TIMEOUT): headers, fh = _doRead(url) req_dig_key = cache_dir + request_digest(url) req_dig_md_key = file_storage.metadata(req_dig_key) file_storage.setItem(req_dig_key, fh) file_storage.setItem(req_dig_md_key, {"datetime": datetime.datetime.now(), "headers": headers}) return headers, file_storage.getItem(req_dig_key, mode="file")
def start(info): """ Starts a session. Remember not to redirect after this. """ session_id = _new_session_id() session_key = SESSION_DIR + session_id info = Storage(info) info.id = session_id info.added = time.time() info.referer = web.ctx.environ.get("HTTP_REFERER", "") info.entry = request_uri() file_storage.setItem(session_key, info) web.setcookie(COOKIE_NAME, session_id) web.ctx.current_session_id = session_id # !!!TODO: session own log? (take care of UM instances with shared fsstorage) return info
def remove_info(new_info): session_id = get_session_id() session_key = SESSION_DIR + session_id info = get_session() for k in new_info: try: del info[k] except KeyError: pass info.id = session_id # this should not change file_storage.setItem(session_key, info) return info
def storeParsedURL(url, parsed_data): req_dig_key = CACHE_DIR + request_digest(url) req_dig_md_key = file_storage.metadata(req_dig_key) try: file_storage.setItem(req_dig_md_key, {"datetime": datetime.datetime.now(), "parsed": parsed_data}) #!!! is pickle fails? return True except: try: file_storage.setItem(req_dig_md_key, {"datetime": datetime.datetime.now(),} ) except: pass return False
def _upload_captcha(file_contents, secret_word, filename="NotKnown.jpg"): file_key = CAPTCHA_PREFIX + md5.new(file_contents).hexdigest() file_storage.setItem(file_key, file_contents) content_type = mimetypes.guess_type(filename)[0] # mostly technical metadata used to show file quickly file_storage.setItem( file_storage.metadata(file_key), { 'Owner': 'NotimplementedYet', 'secret': secret_word, 'added': time.time(), 'OriginalFilename': filename, #!!! 'Last-Modified': rfc822.formatdate(time.time()), 'Content-Type': content_type, #!!! 'Content-Length': len(file_contents), }) return file_key
def uploadMediaFile(file_contents="", filename="NotKnown.jpg", content_type=None): if file_contents: file_key = storeMediaFile(file_contents) content_type = content_type or guess_content_type(filename) # mostly technical metadata used to show file quickly file_storage.setItem(file_storage.metadata(file_key), { 'Owner': 'NotimplementedYet', 'OriginalFilename': filename, #!!! 'Last-Modified': rfc822.formatdate(time.time()), 'Content-Type': content_type, #!!! 'Content-Length': str(len(file_contents)), } ) return "/media?file_key=" + file_key # print "FILE SUCCESSFULLY UPLOADED", file_key, len(file_contents) else: return ""
def storeMediaFile(file_contents, prefix=""): file_key = md5.new(file_contents).hexdigest() file_storage.setItem(prefix + file_key, file_contents) return prefix + file_key