Exemple #1
0
 def listen_for_executable_payload(self, s):
     ssl_con, hostAddress = s.accept()
     s.settimeout(5)
     ssl_sock = ssl.wrap_socket(ssl_con,
                                server_side=True,
                                certfile=".keys/server.crt",
                                keyfile=".keys/server.key",
                                ssl_version=ssl.PROTOCOL_SSLv23)
     raw = ssl_sock.recv(256).decode()
     device_info = json.loads(raw)
     return session.Session(self, ssl_sock, device_info)
Exemple #2
0
    def __init__(self, environ=None, conf=None):
        # конфиг из конфигурационного файла
        self.path = self.req = self.session = self.environ = self.db = None
        self.conf = conf
        # входящие и исходящие печеньки
        self.cookie_in = Cookie.SimpleCookie()
        self.cookie_out = Cookie.SimpleCookie()
        # шаблонизатор
        self.jinja = jinja2.Environment(loader=jinja2.FileSystemLoader(
            self.conf.base_path + self.conf.template_path, 'utf-8'))
        # подключение MySQL, сюда можно что угодно вставить
        if self.conf.db_name and self.conf.db_user:
            self.db = mysql.AdvancedConnection(host=self.conf.db_host,
                                               user=self.conf.db_user,
                                               passwd=self.conf.db_passwd,
                                               db=self.conf.db_name)
        # код ответа
        self.return_code = "200 OK"
        # коллекция заголовков
        self.headers = [("Content-type", "text/html; charset=utf-8")]
        if environ:
            self.environ = environ
            # разбрать QUERY_STRING
            if self.environ.has_key("wsgi.input"):
                self.req = cgi.FieldStorage(fp=self.environ["wsgi.input"],
                                            environ=self.environ,
                                            keep_blank_values=True)
            # разобрать PATH_INFO
            if self.environ.has_key("PATH_INFO"):
                self.path = webpath(self.environ["PATH_INFO"])
            # подхватить печеньки
            if self.environ.has_key("HTTP_COOKIE"):
                self.cookie_in.load(self.environ["HTTP_COOKIE"])
            # создать сессию
            self.session = session.Session(
                self.environ, self.cookie_in, self.cookie_out,
                session.StorageFile(self.conf.base_path +
                                    self.conf.session_storage),
                self.conf.session_lifetime)


#			self.session = session.Session( self.environ, self.cookie_in, self.cookie_out, mysql.StorageMySQL(self.db),self.conf.session_lifetime)
        self.regions = {'regions': {}, 'id': {}}
        filename = self.conf.base_path + self.conf.region_conf + "/.regions_db"
        try:
            with open(filename, 'r') as f:
                self.regions = pickle.load(f)
                f.close()
        except:
            # ничего не делать при остуствии базы
            pass
Exemple #3
0
    def testAllInputs(self):
        env = environment.Environment(serializer.StandardSerializer(),
                                      SingleTaskScheduler(NullTask()),
                                      byte_mode=True)
        learner = TryAllInputsLearner()
        s = session.Session(env, learner)

        def on_time_updated(t):
            if t >= 600:
                s.stop()

        s.total_time_updated.register(on_time_updated)

        s.run()
    def testLimitReward(self):
        env = environment.Environment(serializer.StandardSerializer(),
                                      SingleTaskScheduler(NullTask()))
        learner = LearnerMock()
        s = session.Session(env, learner)

        def on_time_updated(t):
            if t >= 20:
                s.stop()

        s.total_time_updated.register(on_time_updated)

        s.run()
        self.assertLessEqual(s._total_reward, 10)