示例#1
0
 def __init__(
     self,
     name,
     default=None,
     deprecated=False,
     cmdline=['pyff', 'pyffd'],
     typeconv=as_string,
     info='',
     long=None,
     short=None,
     hidden=False,
 ):
     self.name = name
     self.default = default
     self.deprecated = deprecated
     self.cmdline = cmdline
     self.info = info
     self.short = short
     self.typeconv = typeconv
     self.value = None
     self.long = long
     self.hidden = hidden
     self.fallback = pyconfig.setting('pyff.{}'.format(self.name),
                                      default,
                                      allow_default=True)
示例#2
0
class Config(object):
    """
    This class holds a set of configuration parameters (using pyconfig) for pyXMLSecurity:

    :param default_signature_alg: The URI of the default signature algorithm (RSA_SHA1 by default)
    :param default_digest_alg: The URI of the default digest algorithm (SHA1 by default)
    :param default_c14n_alg: The URI of the default c14n algorithm (c14n exclusive by default)
    :param debug_write_to_files: Set to True to dump certain XML traces to /tmp. Danger! Not for production!
    :param same_document_is_root: Set to True to treat implicit null same-document-references as reference to the whole document.
    :param id_attributes: A list of attributes to be used as 'id's. By default set to ['ID','id']
    :param c14n_strip_ws: Set to True to strip whitespaces in c14n. Only use if you have very special needs.

    Refer to the pyconfig documentation for information on how to override these in your own project.
    """
    default_signature_alg = pyconfig.setting(
        "xmlsec.default_signature_alg",
        constants.ALGORITHM_SIGNATURE_RSA_SHA256)
    default_digest_alg = pyconfig.setting("xmlsec.default_digest_alg",
                                          constants.ALGORITHM_DIGEST_SHA256)
    default_c14n_alg = pyconfig.setting("xmlsec.default_c14n_alg",
                                        constants.TRANSFORM_C14N_INCLUSIVE)
    debug_write_to_files = pyconfig.setting(
        "xmlsec.config.debug_write_to_files", False)
    same_document_is_root = pyconfig.setting("xmlsec.same_document_is_root",
                                             False)
    id_attributes = pyconfig.setting("xmlsec.id_attributes", ['ID', 'id'])
    c14n_strip_ws = pyconfig.setting("xmlsec.c14n_strip_ws", False)
示例#3
0
 class Test(object):
     setting = pyconfig.setting('test_setting_shortcut', 'tested')
     setting_no_default = pyconfig.setting('setting_shortcut_no_default',
                                           allow_default=False)
示例#4
0
 def __init__(self, name, default, typeconv=as_string):
     self.name = name
     self.typeconv = typeconv
     self._fallback = pyconfig.setting('pyff.{}'.format(name), default, allow_default=True)
示例#5
0
 class Test(object):
     setting = pyconfig.setting('test_setting_shortcut', 'tested')
示例#6
0
文件: mongo.py 项目: shakefu/humbledb
class Mongo(object):
    """
    Singleton context manager class for managing a single
    :class:`pymongo.connection.Connection` instance.  It is necessary that
    there only be one connection instance for pymongo to work efficiently with
    gevent or threading by using its built in connection pooling.

    This class also manages connection scope, so that we can prevent
    :class:`~humbledb.document.Document` instances from accessing the
    connection outside the context manager scope. This is so that we always
    ensure that :meth:`~pymongo.connection.Connection.end_request` is always
    called to release the socket back into the connection pool, and to restrict
    the scope where a socket is in use from the pool to the absolute minimum
    necessary.

    This class is made to be thread safe.

    Example subclass::

        class MyConnection(Mongo):
            config_host = 'cluster1.mongo.mydomain.com'
            config_port = 27017

    Example usage::

        with MyConnection:
            doc = MyDoc.find_one()

    """
    _self = None

    config_uri = UNSET
    """ A MongoDB URI to connect to. """

    config_host = 'localhost'
    """ The host name or address to connect to. """

    config_port = 27017
    """ The port to connect to. """

    config_replica = None
    """ If you're connecting to a replica set, this holds its name. """

    config_connection_cls = UNSET
    """ This defines the connection class to use. HumbleDB will try to
    intelligently choose a class based on your replica settings and PyMongo
    version. """

    config_max_pool_size = pyconfig.setting('humbledb.connection_pool', 300)
    """ This specifies the max_pool_size of the connection. """

    config_auto_start_request = pyconfig.setting('humbledb.auto_start_request',
            True)
    """ This specifies the auto_start_request option to the connection. """

    config_use_greenlets = pyconfig.setting('humbledb.use_greenlets', False)
    """ This specifies the use_greenlets option to the connection. """

    config_tz_aware = pyconfig.setting('humbledb.tz_aware', True)
    """ This specifies the tz_aware option to the connection. """

    config_write_concern = pyconfig.setting('humbledb.write_concern', 1)
    """ This specifies the write concern (``w=``) for this connection. This was
        added so that Pymongo before 2.4 will by default use
        ``getLastError()``.

        .. versionadded: 4.0

    """

    config_ssl = pyconfig.setting('humbledb.ssl', False)
    """ Specifies whether or not to use SSL for a connection.
        .. versionadded: 5.5
    """

    config_mongo_client = pyconfig.setting('humbledb.mongo_client', {})
    """ Allows free-form ``pymongo.MongoClient`` constructor parameters to be
        passed to this connection to support new features.
        .. versionadded: 5.6
    """

    def __new__(cls):
        """ This class cannot be instantiated. """
        return cls

    @classmethod
    def _new_connection(cls):
        """ Return a new connection to this class' database. """
        kwargs = cls._connection_info()

        kwargs.update({
                'max_pool_size': cls.config_max_pool_size,
                'auto_start_request': cls.config_auto_start_request,
                'use_greenlets': cls.config_use_greenlets,
                'tz_aware': cls.config_tz_aware,
                'w': cls.config_write_concern,
                'ssl': cls.config_ssl,
                })

        kwargs.update(cls.config_mongo_client)

        if _version._gte('2.1.0') and _version._lt('2.2.0'):
            # This causes an error for the 2.1.x versions of Pymongo, so we
            # remove it
            kwargs.pop('auto_start_request')
            kwargs.pop('use_greenlets')

        if _version._gte('3.0.0'):
            # Handle removed keywords
            kwargs.pop('use_greenlets')
            kwargs.pop('auto_start_request')
            # Handle changed keywords
            kwargs['maxPoolSize'] = kwargs.pop('max_pool_size')
            # Handle other 3.0 stuff
            if kwargs.get('ssl') and ssl:
                kwargs.setdefault('ssl_cert_reqs', ssl.CERT_NONE)

        if cls.config_replica:
            kwargs['replicaSet'] = cls.config_replica
            logging.getLogger(__name__).info("Creating new MongoDB connection "
                    "to '{}:{}' replica: {}".format(cls.config_host,
                        cls.config_port, cls.config_replica))
        else:
            logging.getLogger(__name__).info("Creating new MongoDB connection "
                "to '{}:{}'".format(cls.config_host, cls.config_port))

        return cls.config_connection_cls(**kwargs)

    @classmethod
    def _connection_info(cls):
        """
        Return a dictionary containing the connection info based on
        `config_host` and `config_port` or `config_uri`. If `config_uri` is
        specified, it takes precedence.

        """
        if cls.config_uri:
            return {'host': cls.config_uri}

        return {'host': cls.config_host, 'port': cls.config_port}

    @classproperty
    def connection(cls):
        """ Return the current connection. If no connection exists, one is
            created.
        """
        if not cls._connection:
            cls._connection = cls._new_connection()
        return cls._connection

    @classproperty
    def contexts(cls):
        """ Return the current context stack. """
        if not hasattr(Mongo._self, 'contexts'):
            Mongo._self.contexts = []
        return Mongo._self.contexts

    @classproperty
    def context(cls):
        """ Return the current context (a :class:`.Mongo` subclass) if it
            exists or ``None``.
        """
        try:
            return Mongo.contexts[-1]
        except IndexError:
            return None

    @classproperty
    def database(cls):
        """
        Return the default database for this connection.

        .. versionadded:: 5.3.0

        .. note:: This requires ``pymongo >= 2.6.0``.

        """
        if _version._lt('2.6.0'):
            return None
        try:
            return cls.connection.get_default_database()
        except pymongo.errors.ConfigurationError:
            return None
示例#7
0
class DBTest(Mongo):
    config_host = pyconfig.setting('humbledb.test.db.host', 'localhost')
    config_port = pyconfig.setting('humbledb.test.db.port', 27017)
示例#8
0
文件: constants.py 项目: rhoerbe/pyFF
class Config(object):
    google_api_key = pyconfig.setting("pyff.google_api_key", "google+api+key+not+set")
    loglevel = pyconfig.setting("pyff.loglevel", logging.INFO)
    access_log = pyconfig.setting("pyff.access_log", None)
    error_log = pyconfig.setting("pyff.error_log", None)
    logfile = pyconfig.setting("pyff.log", None)
    port = pyconfig.setting("pyff.port", 8080)
    bind_address = pyconfig.setting("pyff.bind_address", "127.0.0.1")
    pid_file = pyconfig.setting("pyff.pid_file", "/var/run/pyff.pid")
    caching_enabled = pyconfig.setting("pyff.caching.enabled", True)
    caching_delay = pyconfig.setting("pyff.caching.delay", 300)
    daemonize = pyconfig.setting("pyff.daemonize", True)
    autoreload = pyconfig.setting("pyff.autoreload", False)
    aliases = pyconfig.setting("pyff.aliases", ATTRS)
    base_dir = pyconfig.setting("pyff.base_dir", None)
    proxy = pyconfig.setting("pyff.proxy", False)
    allow_shutdown = pyconfig.setting("pyff.allow_shutdown", False)
    modules = pyconfig.setting("pyff.modules", [])
    cache_ttl = pyconfig.setting("pyff.cache.ttl", 300)
    default_cache_duration = pyconfig.setting("pyff.default.cache_duration", "PT1H")
    respect_cache_duration = pyconfig.setting("pyff.respect_cache_duration", True)
    info_buffer_size = pyconfig.setting("pyff.info_buffer_size", 10)
    worker_pool_size = pyconfig.setting("pyff.worker_pool_size", 10)
    store_class = pyconfig.setting("pyff.store.class", "pyff.store:MemoryStore")
    update_frequency = pyconfig.setting("pyff.update_frequency", 600)
    cache_frequency = pyconfig.setting("pyff.cache_frequency", 200)
    request_timeout = pyconfig.setting("pyff.request_timeout", 10)
    request_cache_time = pyconfig.setting("pyff.request_cache_time", 300)
    request_cache_backend = pyconfig.setting("pyff.request_cache_backend", None)
    request_override_encoding = pyconfig.setting("pyff.request_override_encoding",
                                                 "utf8")  # set to non to enable chardet guessing
    devel_memory_profile = pyconfig.setting("pyff.devel_memory_profile", False)
    devel_write_xml_to_file = pyconfig.setting("pyff.devel_write_xml_to_file", False)
    ds_template = pyconfig.setting("pyff.ds_template", "ds.html")
    redis_host = pyconfig.setting("pyff.redis_host", "localhost")
    redis_port = pyconfig.setting("pyff.redis_port", 6379)
    rq_queue = pyconfig.setting("pyff.rq_queue", "pyff")
    cache_chunks = pyconfig.setting("pyff.cache_chunks", 10)
示例#9
0
class Config(object):
    google_api_key = pyconfig.setting("pyff.google_api_key",
                                      "google+api+key+not+set")
    loglevel = pyconfig.setting("pyff.loglevel", logging.INFO)
    access_log = pyconfig.setting("pyff.access_log", None)
    error_log = pyconfig.setting("pyff.error_log", None)
    logfile = pyconfig.setting("pyff.log", None)
    port = pyconfig.setting("pyff.port", 8080)
    bind_address = pyconfig.setting("pyff.bind_address", "127.0.0.1")
    pid_file = pyconfig.setting("pyff.pid_file", "/var/run/pyff.pid")
    caching_enabled = pyconfig.setting("pyff.caching.enabled", True)
    caching_delay = pyconfig.setting("pyff.caching.delay", 300)
    daemonize = pyconfig.setting("pyff.daemonize", True)
    autoreload = pyconfig.setting("pyff.autoreload", False)
    frequency = pyconfig.setting("pyff.frequency", 600)
    aliases = pyconfig.setting("pyff.aliases", ATTRS)
    base_dir = pyconfig.setting("pyff.base_dir", None)
    proxy = pyconfig.setting("pyff.proxy", False)
    store = pyconfig.setting("pyff.store", None)
    allow_shutdown = pyconfig.setting("pyff.allow_shutdown", False)
    modules = pyconfig.setting("pyff.modules", [])