当前位置: 首页>>代码示例>>Python>>正文


Python errors.ConfigurationError方法代码示例

本文整理汇总了Python中pymongo.errors.ConfigurationError方法的典型用法代码示例。如果您正苦于以下问题:Python errors.ConfigurationError方法的具体用法?Python errors.ConfigurationError怎么用?Python errors.ConfigurationError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pymongo.errors的用法示例。


在下文中一共展示了errors.ConfigurationError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _build_credentials_tuple

# 需要导入模块: from pymongo import errors [as 别名]
# 或者: from pymongo.errors import ConfigurationError [as 别名]
def _build_credentials_tuple(mech, source, user, passwd, extra):
    """Build and return a mechanism specific credentials tuple.
    """
    user = str(user)
    if mech == 'GSSAPI':
        gsn = 'mongodb'
        if "gssapiservicename" in extra:
            gsn = extra.get('gssapiservicename')
            msg = ('The gssapiServiceName option is deprecated. Use '
                   '"authMechanismProperties=SERVICE_NAME:%s" instead.' % gsn)
            warnings.warn(msg, DeprecationWarning, stacklevel=3)
        # SERVICE_NAME overrides gssapiServiceName.
        if 'authmechanismproperties' in extra:
            props = extra['authmechanismproperties']
            if 'SERVICE_NAME' in props:
                gsn = props.get('SERVICE_NAME')
        # No password, source is always $external.
        return (mech, '$external', user, gsn)
    elif mech == 'MONGODB-X509':
        return (mech, '$external', user)
    else:
        if passwd is None:
            raise ConfigurationError("A password is required.")
        return (mech, source, user, str(passwd)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:26,代码来源:auth.py

示例2: validate_positive_float

# 需要导入模块: from pymongo import errors [as 别名]
# 或者: from pymongo.errors import ConfigurationError [as 别名]
def validate_positive_float(option, value):
    """Validates that 'value' is a float, or can be converted to one, and is
       positive.
    """
    err = ConfigurationError("%s must be a positive int or float" % (option,))
    try:
        value = float(value)
    except (ValueError, TypeError):
        raise err

    # float('inf') doesn't work in 2.4 or 2.5 on Windows, so just cap floats at
    # one billion - this is a reasonable approximation for infinity
    if not 0 < value < 1e9:
        raise err

    return value 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:18,代码来源:common.py

示例3: validate_auth_mechanism_properties

# 需要导入模块: from pymongo import errors [as 别名]
# 或者: from pymongo.errors import ConfigurationError [as 别名]
def validate_auth_mechanism_properties(option, value):
    """Validate authMechanismProperties."""
    value = validate_basestring(option, value)
    props = {}
    for opt in value.split(','):
        try:
            key, val = opt.split(':')
            if key not in _MECHANISM_PROPS:
                raise ConfigurationError("%s is not a supported auth "
                                         "mechanism property. Must be one of "
                                         "%s." % (key, tuple(_MECHANISM_PROPS)))
            props[key] = val
        except ValueError:
            raise ConfigurationError("auth mechanism properties must be "
                                     "key:value pairs like SERVICE_NAME:"
                                     "mongodb, not %s." % (opt,))
    return props


# jounal is an alias for j,
# wtimeoutms is an alias for wtimeout,
# readpreferencetags is an alias for tag_sets. 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:24,代码来源:common.py

示例4: get_validated_options

# 需要导入模块: from pymongo import errors [as 别名]
# 或者: from pymongo.errors import ConfigurationError [as 别名]
def get_validated_options(options, warn=True):
    """Validate each entry in options and raise a warning if it is not valid.
    Returns a copy of options with invalid entries removed
    """
    validated_options = {}
    for opt, value in iteritems(options):
        lower = opt.lower()
        try:
            validator = URI_VALIDATORS.get(lower, raise_config_error)
            value = validator(opt, value)
        except (ValueError, ConfigurationError) as exc:
            if warn:
                warnings.warn(str(exc))
            else:
                raise
        else:
            validated_options[lower] = value
    return validated_options 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:20,代码来源:common.py

示例5: get_server_session

# 需要导入模块: from pymongo import errors [as 别名]
# 或者: from pymongo.errors import ConfigurationError [as 别名]
def get_server_session(self):
        """Start or resume a server session, or raise ConfigurationError."""
        with self._lock:
            session_timeout = self._description.logical_session_timeout_minutes
            if session_timeout is None:
                # Maybe we need an initial scan? Can raise ServerSelectionError.
                if self._description.topology_type == TOPOLOGY_TYPE.Single:
                    if not self._description.has_known_servers:
                        self._select_servers_loop(
                            any_server_selector,
                            self._settings.server_selection_timeout,
                            None)
                elif not self._description.readable_servers:
                    self._select_servers_loop(
                        readable_server_selector,
                        self._settings.server_selection_timeout,
                        None)

            session_timeout = self._description.logical_session_timeout_minutes
            if session_timeout is None:
                raise ConfigurationError(
                    "Sessions are not supported by this MongoDB deployment")

            return self._session_pool.get_server_session(session_timeout) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:26,代码来源:topology.py

示例6: _build_credentials_tuple

# 需要导入模块: from pymongo import errors [as 别名]
# 或者: from pymongo.errors import ConfigurationError [as 别名]
def _build_credentials_tuple(mech, source, user, passwd, extra):
    """Build and return a mechanism specific credentials tuple.
    """
    user = _unicode(user)
    if mech == 'GSSAPI':
        properties = extra.get('authmechanismproperties', {})
        service_name = properties.get('SERVICE_NAME', 'mongodb')
        props = GSSAPIProperties(service_name=service_name)
        # No password, source is always $external.
        return MongoCredential(mech, '$external', user, None, props)
    elif mech == 'MONGODB-X509':
        return MongoCredential(mech, '$external', user, None, None)
    else:
        if passwd is None:
            raise ConfigurationError("A password is required.")
        return MongoCredential(mech, source, user, _unicode(passwd), None) 
开发者ID:leancloud,项目名称:satori,代码行数:18,代码来源:auth.py

示例7: split_hosts

# 需要导入模块: from pymongo import errors [as 别名]
# 或者: from pymongo.errors import ConfigurationError [as 别名]
def split_hosts(hosts, default_port=DEFAULT_PORT):
    """Takes a string of the form host1[:port],host2[:port]... and
    splits it into (host, port) tuples. If [:port] isn't present the
    default_port is used.

    Returns a set of 2-tuples containing the host name (or IP) followed by
    port number.

    :Parameters:
        - `hosts`: A string of the form host1[:port],host2[:port],...
        - `default_port`: The port number to use when one wasn't specified
          for a host.
    """
    nodes = []
    for entity in hosts.split(','):
        if not entity:
            raise ConfigurationError("Empty host "
                                     "(or extra comma in host list).")
        port = default_port
        # Unix socket entities don't have ports
        if entity.endswith('.sock'):
            port = None
        nodes.append(parse_host(entity, port))
    return nodes 
开发者ID:leancloud,项目名称:satori,代码行数:26,代码来源:uri_parser.py

示例8: _get_srv_response_and_hosts

# 需要导入模块: from pymongo import errors [as 别名]
# 或者: from pymongo.errors import ConfigurationError [as 别名]
def _get_srv_response_and_hosts(self, encapsulate_errors):
        results = self._resolve_uri(encapsulate_errors)

        # Construct address tuples
        nodes = [
            (maybe_decode(res.target.to_text(omit_final_dot=True)), res.port)
            for res in results]

        # Validate hosts
        for node in nodes:
            try:
                nlist = node[0].split(".")[1:][-self.__slen:]
            except Exception:
                raise ConfigurationError("Invalid SRV host: %s" % (node[0],))
            if self.__plist != nlist:
                raise ConfigurationError("Invalid SRV host: %s" % (node[0],))

        return results, nodes 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:20,代码来源:srv_resolver.py

示例9: authenticate

# 需要导入模块: from pymongo import errors [as 别名]
# 或者: from pymongo.errors import ConfigurationError [as 别名]
def authenticate(credentials, sock_info, cmd_func):
    """Authenticate sock_info.
    """
    mechanism = credentials[0]
    if mechanism == 'GSSAPI':
        if not HAVE_KERBEROS:
            raise ConfigurationError('The "kerberos" module must be '
                                     'installed to use GSSAPI authentication.')
    auth_func = _AUTH_MAP.get(mechanism)
    auth_func(credentials[1:], sock_info, cmd_func) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:12,代码来源:auth.py

示例10: raise_config_error

# 需要导入模块: from pymongo import errors [as 别名]
# 或者: from pymongo.errors import ConfigurationError [as 别名]
def raise_config_error(key, dummy):
    """Raise ConfigurationError with the given key name."""
    raise ConfigurationError("Unknown option %s" % (key,))


# Mapping of URI uuid representation options to valid subtypes. 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:8,代码来源:common.py

示例11: validate_integer

# 需要导入模块: from pymongo import errors [as 别名]
# 或者: from pymongo.errors import ConfigurationError [as 别名]
def validate_integer(option, value):
    """Validates that 'value' is an integer (or basestring representation).
    """
    if isinstance(value, int):
        return value
    elif isinstance(value, str):
        if not value.isdigit():
            raise ConfigurationError("The value of %s must be "
                                     "an integer" % (option,))
        return int(value)
    raise TypeError("Wrong type for %s, value must be an integer" % (option,)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:13,代码来源:common.py

示例12: validate_positive_integer

# 需要导入模块: from pymongo import errors [as 别名]
# 或者: from pymongo.errors import ConfigurationError [as 别名]
def validate_positive_integer(option, value):
    """Validate that 'value' is a positive integer.
    """
    val = validate_integer(option, value)
    if val < 0:
        raise ConfigurationError("The value of %s must be "
                                 "a positive integer" % (option,))
    return val 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:10,代码来源:common.py

示例13: validate_cert_reqs

# 需要导入模块: from pymongo import errors [as 别名]
# 或者: from pymongo.errors import ConfigurationError [as 别名]
def validate_cert_reqs(option, value):
    """Validate the cert reqs are valid. It must be None or one of the three
    values ``ssl.CERT_NONE``, ``ssl.CERT_OPTIONAL`` or ``ssl.CERT_REQUIRED``"""
    if value is None:
        return value
    if HAS_SSL:
        if value in (ssl.CERT_NONE, ssl.CERT_OPTIONAL, ssl.CERT_REQUIRED):
            return value
        raise ConfigurationError("The value of %s must be one of: "
                                 "`ssl.CERT_NONE`, `ssl.CERT_OPTIONAL` or "
                                 "`ssl.CERT_REQUIRED" % (option,))
    else:
        raise ConfigurationError("The value of %s is set but can't be "
                                 "validated. The ssl module is not available"
                                 % (option,)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:17,代码来源:common.py

示例14: validate_read_preference

# 需要导入模块: from pymongo import errors [as 别名]
# 或者: from pymongo.errors import ConfigurationError [as 别名]
def validate_read_preference(dummy, value):
    """Validate read preference for a ReplicaSetConnection.
    """
    if value in read_preferences.modes:
        return value

    # Also allow string form of enum for uri_parser
    try:
        return read_preferences.mongos_enum(value)
    except ValueError:
        raise ConfigurationError("Not a valid read preference") 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:13,代码来源:common.py

示例15: validate_auth_mechanism

# 需要导入模块: from pymongo import errors [as 别名]
# 或者: from pymongo.errors import ConfigurationError [as 别名]
def validate_auth_mechanism(option, value):
    """Validate the authMechanism URI option.
    """
    # CRAM-MD5 is for server testing only. Undocumented,
    # unsupported, may be removed at any time. You have
    # been warned.
    if value not in MECHANISMS and value != 'CRAM-MD5':
        raise ConfigurationError("%s must be in "
                                 "%s" % (option, MECHANISMS))
    return value 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:12,代码来源:common.py


注:本文中的pymongo.errors.ConfigurationError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。