Example #1
0
 def __init__(self, handler, store, config=session_parameters):
     self._get_cookie = handler.get_cookie
     self._set_cookie = handler.set_cookie
     self.remote_ip = handler.request.remote_ip
     self.store = store
     self.config = storage(config)
     self._data = {}
Example #2
0
 def __init__(self, handler, store, config=session_parameters):
     self._get_cookie = handler.get_cookie
     self._set_cookie = handler.set_cookie
     self.remote_ip = handler.request.remote_ip
     self.store = store
     self.config = storage(config)
     self._data = {}
Example #3
0
    def __getattr__(self, item):

        def get_settings(name):
            if not hasattr(self, '._setting'):
                try:
                    if os.environ.get("SETTINGS_MODULE",None):
                        settings_module =os.environ["SETTINGS_MODULE"]
                    else:
                        settings_module = '.'.join(["settings", options.setting])
                    self._config = import_object(settings_module)
                except AttributeError:
                    self._config = import_object('.'.join(["settings", "setting"]))
                except ImportError:
                    self._config = global_settings
                    warnings.warn(
                        'settings file import error. using global settings now. you need create "settings" module')

            if hasattr(self._config, name):
                return getattr(self._config, name)
            elif hasattr(self._config, name):
                return getattr(self._config, name)
            else:
                raise ConfigError('settings "%s" not exist!' % name)

        setting = get_settings(item)
        return storage(setting) if type(setting) is dict else setting
Example #4
0
    def __getattr__(self, item):
        setting = _Settings.settings_object()
        if hasattr(setting, item):
            config = getattr(setting, item)
        else:
            raise ConfigError('settings "%s" not exist!' % item)

        return storage(config) if type(config) is dict else config
Example #5
0
    def __getattr__(self, item):
        setting = _Settings.settings_object()
        if hasattr(setting, item):
            config = getattr(setting, item)
        else:
            raise ConfigError('settings "%s" not exist!' % item)

        return storage(config) if type(config) is dict else config
Example #6
0
    def __getattr__(self, item):
        setting = self._get_settings()

        if hasattr(setting, item):
            config = getattr(setting, item)
        elif hasattr(global_settings, item):
            config = getattr(global_settings, item)
        else:
            raise ConfigError('settings "%s" not exist!' % item)

        return storage(config) if type(config) is dict else config
Example #7
0
    def __getattr__(self, item):
        setting = self._get_settings()

        if hasattr(setting, item):
            config = getattr(setting, item)
        elif hasattr(global_settings, item):
            config = getattr(global_settings, item)
        else:
            raise ConfigError('settings "%s" not exist!' % item)

        return storage(config) if type(config) is dict else config
Example #8
0
    def __getattr__(self, item):
        setting = Settings.settings_object()

        if hasattr(setting, item):
            if item in ('TORNADO_CONF', 'LOG_CONFIG', 'SESSION', 'TEMPLATE_CONFIG',):
                config = getattr(global_settings, item)
                user_config = getattr(setting, item)
                config.update(user_config)
            else:
                config = getattr(setting, item)

        elif hasattr(global_settings, item):
            config = getattr(global_settings, item)
        else:
            raise ConfigError('settings "%s" not exist!' % item)

        return storage(config) if type(config) is dict else config
Example #9
0
    def connetion(self):
        if hasattr(SqlConnection, '_conn'):
            return SqlConnection._conn
        else:
            with SqlConnection._conn_lock:
                connection_pool = storage()
                connections = settings.DATABASE_CONNECTION

                config = settings.SQLALCHEMY_CONFIGURATION

                for connection_name, connection_item in connections.items():
                    master = []
                    slaves = []
                    kwargs = connection_item.get('kwargs', {})
                    connections_str = connection_item['connections']

                    for conn in connections_str:
                        dburl = url.URL(drivername=conn['DRIVER'],
                                        username=conn['UID'],
                                        password=conn['PASSWD'],
                                        host=conn['HOST'],
                                        port=conn['PORT'],
                                        database=conn['DATABASE'],
                                        query=conn['QUERY'])

                        if conn['ROLE'] == _CONNECTION_TYPE[0]:
                            master.append(dburl)
                        else:
                            slaves.append(dburl)

                    if not len(master):
                        raise ConfigError(
                            'conn:%s ,master connection not found.' %
                            connection_name)
                    try:
                        connection_pool[connection_name] = SQLAlchemy(
                            config,
                            master_url=master[0],
                            slaves_url=slaves,
                            **kwargs)
                    except Exception:
                        raise

                SqlConnection._conn = connection_pool
            return SqlConnection._conn
Example #10
0
    def get_connetion(self):
        if hasattr(self, "_conn"):
            return self._conn
        else:
            with self._conn_lock:
                connection_pool = storage()
                connections = settings.DATABASE_CONNECTION

                config = settings.SQLALCHEMY_CONFIGURATION
                for connection_name, connection_item in connections.items():
                    master = []
                    slaves = []
                    kwargs = connection_item.get("kwargs", {})
                    connections_str = connection_item["connections"]
                    for conn in connections_str:

                        dburl = url.URL(
                            drivername=conn["DRIVER"],
                            username=conn["UID"],
                            password=conn["PASSWD"],
                            host=conn["HOST"],
                            port=conn["PORT"],
                            database=conn["DATABASE"],
                            query=conn["QUERY"],
                        )
                        if conn["ROLE"] == _CONNECTION_TYPE[0]:
                            master.append(dburl)
                        else:
                            slaves.append(dburl)

                    if not len(master):
                        raise ConfigError("conn:%s ,master connection not found" % connection_name)

                    connection_pool[connection_name] = SQLAlchemy(
                        config, master_url=master[0], slaves_url=slaves, **kwargs
                    )

                self._conn = connection_pool
            return self._conn
Example #11
0
    def connetion(self):
        if hasattr(self, '_conn'):
            return self._conn
        else:
            with self._conn_lock:
                connection_pool = storage()
                connections = settings.DATABASE_CONNECTION

                config = settings.SQLALCHEMY_CONFIGURATION

                for connection_name, connection_item in connections.items():
                    master = []
                    slaves = []
                    kwargs = connection_item.get('kwargs', {})
                    connections_str = connection_item['connections']

                    for conn in connections_str:
                        dburl = url.URL(drivername=conn['DRIVER']
                            , username=conn['UID']
                            , password=conn['PASSWD']
                            , host=conn['HOST']
                            , port=conn['PORT']
                            , database=conn['DATABASE']
                            , query=conn['QUERY'])

                        if conn['ROLE'] == _CONNECTION_TYPE[0]:
                            master.append(dburl)
                        else:
                            slaves.append(dburl)

                    if not len(master):
                        raise ConfigError('conn:%s ,master connection not found' % connection_name)

                    connection_pool[connection_name] = SQLAlchemy(config, master_url=master[0], slaves_url=slaves,
                                                                  **kwargs)

                self._conn = connection_pool
            return self._conn
Example #12
0
    def process_response(self, handler):
        if hasattr(handler, "session"):
            handler.session.save()
            del handler.session


_DAY1 = 24 * 60 * 60
_DAY30 = _DAY1 * 30
_VERIFICATION_KEY = '__VERIFID'

session_parameters = storage({
    'session_name': '__TORNADOID',
    'cookie_domain': None,
    'cookie_path': '/',
    'expires': 0,  #24 * 60 * 60, # 24 hours in seconds
    'ignore_change_ip': False,
    'httponly': True,
    'secure': False,
    'secret_key': 'fLjUfxqXtfNoIldA0A0J',
    'session_version': ''
})


class SessionManager(object):
    _killed = False

    def __init__(self, handler, store, config=session_parameters):
        self._get_cookie = handler.get_cookie
        self._set_cookie = handler.set_cookie
        self.remote_ip = handler.request.remote_ip
        self.store = store
Example #13
0
 def __getattr__(self, item):
     setting = self.get_settings(item)
     return storage(setting) if type(setting) is dict else setting
Example #14
0
    def process_response(self, handler, chunk=None):
        if hasattr(handler, "session"):
            handler.session.save()
            del handler.session


_DAY1 = 24 * 60 * 60
_DAY30 = _DAY1 * 30
_VERIFICATION_KEY = '__VERIFSSID'

session_parameters = storage({
    'session_name': '__TORNADOSSID',
    'cookie_domain': None,
    'cookie_path': '/',
    'expires': 0,  #24 * 60 * 60, # 24 hours in seconds
    'ignore_change_ip': False,
    'httponly': True,
    'secure': False,
    'secret_key': 'fLjUfxqXtfNoIldA0A0J',
    'session_version': ''
})


class SessionManager(object):
    _killed = False

    def __init__(self, handler, store, config=session_parameters):
        self._get_cookie = handler.get_cookie
        self._set_cookie = handler.set_cookie
        self.remote_ip = handler.request.remote_ip
        self.store = store