Пример #1
0
 def get(self, section, option, subsection=None):
     """Get an option"""
     if not section in self.sections():
         raise NoSectionError(section)
     if subsection:
         if not subsection in self._sections[section]:
             raise NoSectionError(subsection)
         if not option in self._sections[section][subsection]:
             raise NoOptionError(option, subsection)
         return self._sections[section][subsection][option]
     if not option in self._sections[section]:
         raise NoOptionError(option, section)
     return self._sections[section][option]
Пример #2
0
def includeme(config):

    try:
        datasources = config.registry.application_settings.ip_navigator.datasources
    except:
        raise NoOptionError('datasources', 'ip_navigator')

    if 'ops' in datasources:
        config.include("patzilla.access.epo.ops.client")

    if 'depatisconnect' in datasources:
        config.include("patzilla.access.dpma.depatisconnect")

    if 'ificlaims' in datasources:
        config.include("patzilla.access.ificlaims.clientpool")

    if 'depatech' in datasources:
        config.include("patzilla.access.depatech.clientpool")

    if 'sip' in datasources:
        config.include("patzilla.access.sip.concordance")
        config.include("patzilla.access.sip.clientpool")

    config.include('.office')
    config.scan()
Пример #3
0
    def has_comment(self, section, option=None):
        """
        Return if the given section heading or option within a section has an
        associated comment.

        @type section: str
        @type option: str or None
        @rtype: bool

        @raise NoSectionError: The provided section does not exist

        """
        if not section:
            section = DEFAULTSECT

        if not self.has_section(section) and section != DEFAULTSECT:
            raise NoSectionError(section)

        if option:
            option = self.optionxform(option)
            if not self.has_option(section, option):
                raise NoOptionError(option, section)
        else:
            # looking for section comment
            option = '__name__'

        return bool(
            self._comments.get(section, False)
            and self._comments[section].get(option, False))
Пример #4
0
    def set_comment(self, comment, section, option=None):
        """
        Set the comment for a section or option

        @type comment: str or None
        @type section: str
        @type option: str or None

        """
        if not section:
            section = DEFAULTSECT

        if not self.has_section(section) and section != DEFAULTSECT:
            raise NoSectionError(section)

        if section not in self._comments:
            self._comments[section] = self._dict()

        if option:
            option = self.optionxform(option)
            if not self.has_option(section, option):
                raise NoOptionError(option, section)
        else:
            # setting section comment
            option = '__name__'

        self._comments[section][option] = comment
Пример #5
0
 def get(self, section, option):
     if self.has_option(section, option):
         hkey = "%s:section:%s:option:%s" % (self.namespace, section, option)
         value = self.redis.get(hkey)
         return value
     else:
         raise NoOptionError(section, option)
Пример #6
0
    def remove_comment(self, section, option=None):
        """
        Remove the comment from a section or option.

        @type section: str
        @param section: The section to remove from.

        @type option: str or None
        @param option: The option to remove from or None to remove a section's
        comment.

        @rtype: bool
        @return: True if a comment was removed and False if no comment was
        removed.

        """
        if not section:
            section = DEFAULTSECT
        elif not self.has_section(section) and section != DEFAULTSECT:
            raise NoSectionError(section)

        if option:
            option = self.optionxform(option)
            if not self.has_option(section, option):
                raise NoOptionError(option, section)
        else:
            # setting section comment
            option = '__name__'

        del self._comments[section][option]
Пример #7
0
    def get(self, section, option, raw=False, vars=None, fallback=_UNSET):

        d = self._defaults.copy()
        try:
            d.update(self._sections[section])
        except KeyError:
            if section != DEFAULTSECT:
                raise NoSectionError(section)

        # Update the entry specific variables
        if vars:
            for key, value in vars.items():
                d[self.optionxform(key)] = value
        option = self.optionxform(option)
        try:
            value = d[option]
        except KeyError:
            if fallback is _UNSET:
                raise NoOptionError(option, section)
            else:
                return fallback

        if raw or value is None:
            return value
        else:
            return self._interpolate(section, option, value, d)
Пример #8
0
def _read_value(parser, section, option):
    if not parser.has_section(section):
        raise NoSectionError("%s (available sections: %s)"
            % (section, sorted(parser.sections())))
    if not parser.has_option(section, option):
        raise NoOptionError("%s (available options: %s)" % (option, sorted(parser.options(section))), section)
    else:
        return parser.get(section, option)
Пример #9
0
 def get(self, section, option):
     if section == 'memcache':
         if option == 'memcache_servers':
             return '1.2.3.4:5'
         else:
             raise NoOptionError(option)
     else:
         raise NoSectionError(option)
Пример #10
0
 def has_option(self, section, option):
     hkey = "%s:section:%s:option:%s" % (self.namespace, section, option)
     if self.has_section(section):
         if not self.redis.exists(hkey):
             raise NoOptionError(section, option)
     else:
         raise NoSectionError(section)
     return True
Пример #11
0
    def validate_config(self):
        if not self.has_section('input'):
            raise NoSectionError('input')

        must_haves = ('file', 'type', 'tags', 'pattern')
        for key in must_haves:
            if not self.has_option('input', key):
                raise NoOptionError(key, 'input')
Пример #12
0
 def _get(self, config_func, option):
   superclasses = [superclass.__name__ for superclass in self.__class__.__mro__]
   superclasses[-1] = 'DEFAULT'
   for i, superclass in enumerate(superclasses):
     superclasses[i] = superclass = re.sub('\B([A-Z][a-z])', r' \1', superclass)
     superclasses[i] = superclass = re.sub('([a-z])([A-Z])', r'\1 \2', superclass)
     if self._config.has_section(superclass) and self._config.has_option(superclass, option):
       return None if self._config.get(superclass, option) == 'None' else config_func(superclass, option)
   raise NoOptionError(option, superclasses)
Пример #13
0
 def get(self, section, option):
     if _section == section:
         if option == 'memcache_servers':
             if _srvs == 'error':
                 raise NoOptionError(option, section)
             return _srvs
         elif option == 'memcache_serialization_support':
             if _sers == 'error':
                 raise NoOptionError(option, section)
             return _sers
         elif option in ('memcache_max_connections', 'max_connections'):
             if _maxc == 'error':
                 raise NoOptionError(option, section)
             return _maxc
         else:
             raise NoOptionError(option, section)
     else:
         raise NoSectionError(option)
Пример #14
0
def includeme(config):
    datasource_settings = config.registry.datasource_settings
    try:
        api_uri = datasource_settings.datasource.sip.api_uri
    except:
        raise NoOptionError('api_uri', 'datasource:sip')

    config.registry.registerUtility(SipClientPool(api_uri=api_uri))
    config.add_subscriber(attach_sip_client, "pyramid.events.ContextFound")
Пример #15
0
 def get(self, section, option, vars=None):
     if not self.has_section(section):
         raise NoSectionError(section)
     if vars is not None and option in vars:
         value = vars[option]
     try:
         return self.data[section][option]
     except KeyError:
         raise NoOptionError(option, section)
Пример #16
0
 def get(self, section, option, raw=False, vars=None):
     try:
         return SafeConfigParser.get(self, section, option, raw, vars)
     except NoSectionError:
         try:
             section_defaults = config_defaults[section]
         except KeyError:
             raise NoSectionError(section)
         try:
             return section_defaults[option]
         except KeyError:
             raise NoOptionError(option, section)
     except NoOptionError:
         try:
             section_defaults = config_defaults[section]
             return section_defaults[option]
         except KeyError:
             raise NoOptionError(option, section)
Пример #17
0
    def get(self, section, option, default=NoDefault):
        """
        Get an option
        section=None: attribute a default section name
        default: default value (if not specified, an exception
        will be raised if option doesn't exist)
        """
        section = self.__check_section_option(section, option)

        if not self.has_section(section):
            if default is NoDefault:
                raise NoSectionError(section)
            else:
                self.add_section(section)

        if not self.has_option(section, option):
            if default is NoDefault:
                raise NoOptionError(option, section)
            else:
                self.set(section, option, default)
                return default

        value = ConfigParser.get(self, section, option, self.raw)
        default_value = self.get_default(section, option)

        try:   # really ugly
            from datetime import datetime
            value = datetime.strptime(value ,"%Y-%m-%d").date()
            return default_value
        except:
            pass

        if isinstance(default_value, bool):
            value = eval(value)
        elif isinstance(default_value, float):
            value = float(value)
        elif isinstance(default_value, int):
            value = int(value)
        else:

            if isinstance(default_value, basestring):
                try:
                    value = value.decode('utf-8')
                except (UnicodeEncodeError, UnicodeDecodeError):
                    pass
            try:
                # lists, tuples, ...
                value = eval(value)
            except:
                pass




        return value
Пример #18
0
    def test_get_repo_url_prefixes_from_config_no_entry(self):
        """
        If we can't read the options, assert that we get a default
        """
        mock_config = mock.Mock()
        mock_config.get.side_effect = NoOptionError(None, None)

        validator = oid_validation.OidValidator(mock_config)
        result = validator._get_repo_url_prefixes_from_config(mock_config)

        self.assertEquals(result, ["/pulp/repos", "/pulp/ostree/web"])
Пример #19
0
 def _read_netapp_config(self, attribute, zfscredconfig):
     # Try reading Netapp configuration first from the credentials file, then fail over to main configuration file
     value = None
     try:
         return zfscredconfig.get('netapp', attribute)
     except (NoOptionError, NoSectionError) as e:
         pass
     try:
         return Configuration.get(attribute, 'netapp')
     except (NoOptionError, NoSectionError) as e:
         raise NoOptionError("Attribute %s not found" % attribute)
Пример #20
0
    def get(self, section, option, vars=None):
        if not self.has_section(section):
            raise NoSectionError(section)
        if vars is not None and option in vars:
            value = vars[option]

        sec = self.data[section]
        if option in sec:
            return sec._compat_get(option)
        else:
            raise NoOptionError(option, section)
Пример #21
0
def includeme(config):
    global use_https
    global archive_service_baseurl
    datasource_settings = config.registry.datasource_settings

    try:
        archive_service_baseurl = datasource_settings.datasource.depatisconnect.api_uri
    except:
        raise NoOptionError('api_uri', 'datasource_depatisconnect')

    if archive_service_baseurl.startswith('https'):
        use_https = True
Пример #22
0
    def _get_default(self, section, option):
        # cater for 'special' sections
        if section == '__noschema__':
            value = super(SchemaConfigParser, self).get(section, option)
            return value

        # any other section
        opt = self.schema.section(section).option(option)
        if not opt.fatal:
            value = opt.default
            return value

        # no default value found, raise an error
        raise NoOptionError(option, section)
Пример #23
0
    def validate_config(self):
        if not self.has_section('default'):
            raise NoSectionError('default')

        for name in self.defaults():
            if not self.has_option('default', name):
                raise NoOptionError(name, 'default')

        sender = self.get('default', 'sender')
        if not self.has_section(sender):
            raise NoSectionError(sender)

        loglevel = self.get('default', 'loglevel')
        if not hasattr(logging, loglevel.upper()):
            raise ValueError('Unknown loglevel: %r' % (loglevel))
Пример #24
0
def includeme(config):
    datasource_settings = config.registry.datasource_settings
    try:
        api_uri = datasource_settings.datasource.ificlaims.api_uri
    except:
        raise NoOptionError('api_uri', 'datasource:ificlaims')

    api_uri_json = None
    if 'api_uri_json' in datasource_settings.datasource.ificlaims:
        api_uri_json = datasource_settings.datasource.ificlaims.api_uri_json

    config.registry.registerUtility(
        IFIClaimsClientPool(api_uri=api_uri, api_uri_json=api_uri_json))
    config.add_subscriber(attach_ificlaims_client,
                          "pyramid.events.ContextFound")
Пример #25
0
    def get(self, section, option):
        """
        return default values instead of breaking

        this is a drop-in replacement for standard get from ConfigParser
        """
        try:
            return SafeConfigParser.get(self, section, option)
        except NoOptionError:
            try:
                default_value = DEFAULT_CONF[section][option]
            except KeyError:
                raise NoOptionError(option, section)
            else:
                return default_value
Пример #26
0
 def getValueFromComp(self, component, cvar, lang=None, required=False,
                      default=None, override=None):
     if override:
         return override
     options = self.getComponentOptions(component)
     if lang:
         lcvar = cvar + '.' + lang
         if lcvar in options:
             return options[lcvar]
     if cvar in options:
         return options[cvar]
     else:
         if required:
             raise NoOptionError(cvar,component)
     return default
Пример #27
0
    def get_asiaq_option(self,
                         option,
                         section=DEFAULT_CONFIG_SECTION,
                         environment=None,
                         required=True,
                         default=None):
        """
        Get a value from the config, checking first for an environment-specific value, then
        a generic value, then an env-specific default value in the default section, then a
        non-env-specific default value in the default section.

        In the case where none of these options has been set, if the "required" option is False,
        return the value of the "default" option; otherwise, raise NoOptionError.
        """
        if required and (default is not None):
            raise ProgrammerError(
                "Using the 'default' option when 'required' is True makes no sense."
            )
        if not environment:
            environment = self.environment
        env_option = "{0}@{1}".format(option, environment)
        default_option = "default_{0}".format(option)
        default_env_option = "default_{0}".format(env_option)

        if self.has_option(section, env_option):
            return self.get(section, env_option)
        if self.has_option(section, option):
            return self.get(section, option)
        elif self.has_option(DEFAULT_CONFIG_SECTION, default_env_option):
            return self.get(DEFAULT_CONFIG_SECTION, default_env_option)
        elif self.has_option(DEFAULT_CONFIG_SECTION, default_option):
            return self.get(DEFAULT_CONFIG_SECTION, default_option)

        if required:
            raise NoOptionError(option, section)
        return default
Пример #28
0
    def get_comment(self, section, option=None):
        """
        Get the comment for a section[.option]

        @type section: str
        @param section: Section heading to check for a comment, or the section
        heading that the target option is located under.

        @type option: str or None
        @param option: If checking for an option's comment, this is the option
        under the given section to check. If checking for a section's comment,
        this should be None.

        @rtype: str or None
        @return: The section or option comment if there is one, or None if there
        is no comment for the specified section or option.

        """
        if not section:
            section = DEFAULTSECT

        if not self.has_section(section) and section != DEFAULTSECT:
            raise NoSectionError(section)

        if option:
            option = self.optionxform(option)
            if not self.has_option(section, option):
                raise NoOptionError(option, section)

        else:
            # looking for section comment
            option = '__name__'

        # Combined statement to handle both section and option requests.
        return (self._comments.get(section, None)
                and self._comments[section].get(option, None))
Пример #29
0
 def wrapped(self, option, *args, **kwargs):
     if self.config_obj.has_option(self.name, option):
         return func(self, option, *args, **kwargs)
     else:
         raise NoOptionError(option, self.name)
Пример #30
0
 def get(self, section, option, raw=False, vars=None):
     if section not in self.config_dict:
         raise NoSectionError(section)
     if option not in self.config_dict[section]:
         raise NoOptionError(option, section)
     return self.config_dict[section][option]