def __init__(self, app): """Create both a file and a memory store.""" SessionStore.__init__(self, app) self._fileStore = SessionFileStore.SessionFileStore(app) self._memoryStore = SessionMemoryStore.SessionMemoryStore( app, restoreFiles=False) # session files are read on demand # moveToFileInterval specifies after what period of time # in seconds a session is automatically moved to a file self._moveToFileInterval = app.setting('DynamicSessionTimeout', 15) * 60 # maxDynamicMemorySessions is what the user actually sets # in Application.config, the maximum number of in memory sessions self._maxDynamicMemorySessions = app.setting( 'MaxDynamicMemorySessions', 10000) # Used to keep track of sweeping the file store self._fileSweepCount = 0 # Create a re-entrant lock for thread synchronization. The lock is used # to protect all code that modifies the contents of the file store and # all code that moves sessions between the file and memory stores, and # is also used to protect code that searches in the file store for a # session. Using the lock in this way avoids a bug that used to be in # this code, where a session was temporarily neither in the file store # nor in the memory store while it was being moved from file to memory. self._lock = threading.RLock() if debug: print("SessionDynamicStore Initialized")
def __init__(self, app): # Create both a file store and a memory store SessionStore.__init__(self, app) self._fileStore = SessionFileStore.SessionFileStore(app) self._memoryStore = SessionMemoryStore.SessionMemoryStore(app, restoreFiles=0) self._memoryStore.clear() #fileStore will have the files on disk # moveToFileInterval specifies after what period of time a session is automatically moved to file self._moveToFileInterval = self.application().setting('DynamicSessionTimeout', 15) * 60 # maxDynamicMemorySessions is what the user actually sets in Application.config self._maxDynamicMemorySessions = self.application().setting('MaxDynamicMemorySessions', 10000) # Used to keep track of sweeping the file store self._fileSweepCount = 0 # Create a re-entrant lock for thread synchronization. The lock is used to protect # all code that modifies the contents of the file store and all code that moves sessions # between the file and memory stores, and is also used to protect code that searches in # the file store for a session. Using the lock in this way avoids a bug that used to # be in this code, where a session was temporarily neither in the file store nor in # the memory store while it was being moved from file to memory. self._lock = threading.RLock() if debug: print "SessionDynamicStore Initialized"
def __init__(self, app): """Create both a file and a memory store.""" SessionStore.__init__(self, app) self._fileStore = SessionFileStore.SessionFileStore(app) self._memoryStore = SessionMemoryStore.SessionMemoryStore(app, restoreFiles=False) # session files are read on demand # moveToFileInterval specifies after what period of time # in seconds a session is automatically moved to a file self._moveToFileInterval = app.setting( 'DynamicSessionTimeout', 15) * 60 # maxDynamicMemorySessions is what the user actually sets # in Application.config, the maximum number of in memory sessions self._maxDynamicMemorySessions = app.setting( 'MaxDynamicMemorySessions', 10000) # Used to keep track of sweeping the file store self._fileSweepCount = 0 # Create a re-entrant lock for thread synchronization. The lock is used # to protect all code that modifies the contents of the file store and # all code that moves sessions between the file and memory stores, and # is also used to protect code that searches in the file store for a # session. Using the lock in this way avoids a bug that used to be in #this code, where a session was temporarily neither in the file store # nor in the memory store while it was being moved from file to memory. self._lock = threading.RLock() if debug: print "SessionDynamicStore Initialized"
def __init__(self, app, restoreFiles=1): SessionStore.__init__(self, app) self._store = {} if restoreFiles == 1: filestore = SessionFileStore(app) keys = filestore.keys() for i in keys: self[i] = filestore[i] filestore.clear()
def __init__(self, app, restoreFiles=True): """Initialize the session file store. If restoreFiles is true, and sessions have been saved to file, the store will be initialized from these files. """ SessionStore.__init__(self, app) self._sessionDir = app._sessionDir self._lock = threading.RLock() if not restoreFiles: self.clear()
def __init__(self, app, restoreFiles=True, filename=None): """Initialize the session shelf. If restoreFiles is true, existing shelve file(s) will be reused. """ SessionStore.__init__(self, app) filename = os.path.join(app._sessionDir, filename or self._filename) flag = 'c' if restoreFiles else 'n' self._store = shelve.open(filename, flag=flag, protocol=maxPickleProtocol) self._lock = threading.RLock()
def __init__(self, app, restoreFiles=1): SessionStore.__init__(self, app) self._store = {} if restoreFiles == 1: filestore = SessionFileStore(app) keys = filestore.keys() for i in keys: try: self[i] = filestore[i] except Exception: app.handleException() filestore.clear()
def __init__(self, app, restoreFiles=True, filename=None): """Initialize the session shelf. If restoreFiles is true, existing shelve file(s) will be reused. """ SessionStore.__init__(self, app) filename = os.path.join(app._sessionDir, filename or self._filename) flag = restoreFiles and 'c' or 'n' self._store = shelve.open(filename, flag=flag, protocol=maxPickleProtocol) self._lock = threading.RLock()
def __init__(self, app, restoreFiles=True): """Initialize the session memory store. If restoreFiles is true, and sessions have been saved to file, the store will be initialized from these files. """ SessionStore.__init__(self, app) self._store = {} if restoreFiles: filestore = SessionFileStore(app) for key in filestore: try: self[key] = filestore[key] except Exception: app.handleException() filestore.clear()
def __init__(self, app): SessionStore.__init__(self, app) # the list of redis servers self._host = app.setting('RedisHost', 'localhost') self._port = app.setting('RedisPort', 6379) self._db = app.setting('RedisDb', 0) self._password = app.setting('RedisPassword', None) # timeout in seconds self._sessionTimeout = app.setting('SessionTimeout', 180) * 60 # the redis "namespace" used by our store self._namespace = app.setting('RedisNamespace', 'WebwareSession:') or '' self._redis = redis.StrictRedis(self._host, self._port, self._db, self._password)
def __init__(self, app): SessionStore.__init__(self, app) # the list of redis servers self._host = app.setting('RedisHost', 'localhost') self._port = app.setting('RedisPort', 6379) self._db = app.setting('RedisDb', 0) self._password = app.setting('RedisPassword', None) # timeout in seconds self._sessionTimeout = app.setting( 'SessionTimeout', 180) * 60 # the redis "namespace" used by our store self._namespace = app.setting( 'RedisNamespace', 'WebwareSession:') or '' self._redis = redis.StrictRedis(self._host, self._port, self._db, self._password)
def __init__(self, app): SessionStore.__init__(self, app) # the list of memcached servers self._servers = app.setting('MemcachedServers', ['localhost:11211']) # timeout in seconds self._sessionTimeout = app.setting('SessionTimeout', 180) * 60 # the memcached "namespace" used by our store # you can add an integer counter for expiration self._namespace = app.setting('MemcachedNamespace', 'WebwareSession:') or '' # when trying to iterate over the Memcached store, # you can trigger an error or a warning self._onIteration = app.setting('MemcachedOnIteration', 'Warning') self._client = memcache.Client(self._servers, debug=debug, pickleProtocol=maxPickleProtocol)
def __init__(self, app): SessionStore.__init__(self, app) # the list of memcached servers self._servers = app.setting('MemcachedServers', ['localhost:11211']) # timeout in seconds self._sessionTimeout = app.setting( 'SessionTimeout', 180) * 60 # the memcached "namespace" used by our store # you can add an integer counter for expiration self._namespace = app.setting( 'MemcachedNamespace', 'WebwareSession') or '' # when trying to iterate over the Memcached store, # you can trigger an error or a warning self._onIteration = app.setting('MemcachedOnIteration', 'Warning') self._client = memcache.Client(self._servers, debug=debug, pickleProtocol=maxPickleProtocol)
def render(): local_results = [] atomic_index = 1 # set this for having it in GET requests # check session or redirect to register SessionHandler.print() alias = get_alias_from_cookie() print("alias is {0}".format(alias)) if alias is None or alias is "": #return fail('Please set an alias') return redirect(url_for('register')) if request.method == 'POST': # check uploaded files if len(request.files) == 0: return fail('No files were uploaded') # creating a new, atomic value for this upload atomic_index = SessionStore.fetch_add() for file in request.files.getlist("file[]"): if not allowed_file(file.filename): return fail('That file type is not supported') path = create_upload_path(alias, atomic_index) upload_file(file, path) try: # getting results from file data_input = read(get_input_path(file.filename)) data_output = read(os.path.join( path, file.filename)) #read(get_file_path(file.filename, False)) # creating the solver and fetching results solver = Solver(data_input, data_output) results = solver.get_points() # set results in local and global db local_results.append([file.filename, results]) DatabaseHandler.set(alias, file.filename, results) # storing json and uploading as well jc = JsonCreator(file.filename, solver.obj_in) jc.create_json(path) except Exception as e: return fail(str(e)) return success(alias, atomic_index, DatabaseHandler.get_entries(), local_results)
def __init__(self, app): SessionStore.__init__(self, app) self._sessionDir = app._sessionDir self._lock = threading.RLock()
""" Create a lot of fake data to enter into the data base """ from random import randint from numpy.random import random_integers from numpy.random import random_sample from UserStore import UserStore from SessionStore import SessionStore from FoodStore import FoodStore from datetime import datetime from RestaurantStore import RestaurantStore sessions = SessionStore( "config.json" ) users = UserStore( "config.json" ) restaurant = RestaurantStore( "config.json" ) foods = FoodStore( "config.json" ) numSessions = 100 menu = restaurant.getMenu( "mGoPS" ) us = users.collection.find() ut = [] for u in us: ut.append( u['uid'] ) for sess in range( numSessions ): us = random_integers( 1, len( ut ) - 1, randint( 1, 5 ) )
def setEncoderDecoder(self, encoder, decoder): """Set the serializer and deserializer for the store.""" SessionStore.setEncoderDecoder(self, encoder, decoder) self._fileStore.setEncoderDecoder(encoder, decoder)
def cleanStaleSessions(self, task=None): """Clean stale sessions.""" SessionStore.cleanStaleSessions(self, task) self.intervalSweep()
from http.server import BaseHTTPRequestHandler, HTTPServer import json from urllib.parse import parse_qs from sportevents_db import SportEventsDB from http import cookies from passlib.hash import bcrypt import hashlib from SessionStore import SessionStore import sys SESSION_STORE = SessionStore() class MyRequestHandler(BaseHTTPRequestHandler): def end_headers(self): self.sendCookie() self.send_header("Access-Control-Allow-Origin",self.headers["Origin"]) self.send_header("Access-Control-Allow-Credentials","true") BaseHTTPRequestHandler.end_headers(self) # goal: load cookie into self.cookie def loadcookie(self): if "Cookie" in self.headers: self.cookie = cookies.SimpleCookie(self.headers["Cookie"]) else: self.cookie = cookies.SimpleCookie() def sendCookie(self): for morsel in self.cookie.values(): self.send_header("Set-Cookie",morsel.OutputString())
def setEncoderDecoder(self, encoder, decoder): # @@ 2002-11-26 jdh: # propogate the encoder/decoder to the # underlying SessionFileStore self._fileStore.setEncoderDecoder(encoder, decoder) SessionStore.setEncoderDecoder(self, encoder, decoder)
def setEncoderDecoder(self, encoder, decoder): # @@ 2002-11-26 jdh: # propogate the encoder/decoder to the # underlying SessionFileStore self._fileStore.setEncoderDecoder(encoder, decoder) SessionStore.setEncoderDecoder(self,encoder,decoder)
def __init__(self, app): SessionStore.__init__(self, app) self._sessionDir = app.serverSidePath('Sessions') self._lock = threading.Lock()
from http.server import BaseHTTPRequestHandler, HTTPServer from urllib.parse import parse_qs from data import dataDB from data import UsersDB import json import datetime from passlib.hash import bcrypt from http import cookies from SessionStore import SessionStore from http import cookies #from file import class # paragraphs = [] gSessionStore = SessionStore() class MyHandler(BaseHTTPRequestHandler): def load_cookie(self): if "Cookie" in self.headers: self.cookie = cookies.SimpleCookie(self.headers["Cookie"]) else: self.cookie = cookies.SimpleCookie() def send_cookie(self): for morsel in self.cookie.values(): self.send_header("Set-Cookie", morsel.OutputString()) def load_session(self): #GOAL assign self.session according to sessionId self.load_cookie() if "sessionId" in self.cookie: