1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# coding=utf-8
import multiprocessing.managers
from . import user_session
from . import prolog_session
import server.problems
__all__ = ['user_session', 'prolog_session', 'problems', 'start']
class Codeq(object):
_method_to_typeid_ = {
'get_session_by_id': 'UserSession',
'get_or_create_session': 'UserSession',
'authenticate_and_create_session': 'UserSession'
}
def get_session_by_id(self, sid):
return user_session.get_session_by_id(sid)
def get_or_create_session(self, uid, username, sid=None):
return user_session.get_or_create_session(uid, username, sid)
def authenticate_and_create_session(self, username, password):
return user_session.authenticate_and_create_session(username, password)
def list_problems_in_groups(self, language):
return server.problems.list_problems_in_groups(language)
class CodeqManager(multiprocessing.managers.BaseManager):
pass
class UserSessionProxy(multiprocessing.managers.BaseProxy):
_method_to_typeid_ = {'get_prolog':'PrologSession'}
CodeqManager.register('PrologSession')
CodeqManager.register('UserSession', proxytype=UserSessionProxy)
#CodeqManager.register('get_session_by_id', callable=user_session.get_session_by_id, proxytype=UserSessionProxy)
#CodeqManager.register('get_or_create_session', callable=user_session.get_or_create_session, proxytype=UserSessionProxy)
#CodeqManager.register('authenticate_and_create_session', callable=user_session.authenticate_and_create_session, proxytype=UserSessionProxy)
#CodeqManager.register('list_problems_in_groups', callable=server.problems.list_problems_in_groups)
CodeqManager.register('Codeq', callable=Codeq, method_to_typeid=Codeq._method_to_typeid_)
def start():
m = CodeqManager(address=('localhost', 16231), authkey=b'c0d3q3y')
m.get_server().serve_forever()
|