MCPcopy Index your code
hub / github.com/ddserver/ddserver / declare

Method declare

ddserver/config.py:55–88  ·  view source on GitHub ↗

Declare a section. The section declaration is a context manager where the context is a function, which can be used to declare a option. Example: with config_decl.declare('my_section') as my: my('my_option', conv = str, default = 'my_defa

(self, section_name)

Source from the content-addressed store, hash-verified

53
54 @contextlib.contextmanager
55 def declare(self, section_name):
56 ''' Declare a section.
57
58 The section declaration is a context manager where the context is a
59 function, which can be used to declare a option. Example:
60
61 with config_decl.declare('my_section') as my:
62 my('my_option',
63 conv = str,
64 default = 'my_default')
65 ...
66 '''
67
68 # Create a section declaration if it does not exists
69 if section_name not in self.__sections:
70 section = self.__sections[section_name] = {}
71
72 else:
73 section = self.__sections[section_name]
74
75 # The option declaration function returned as the context
76 def declarator(option_name,
77 conv = str,
78 default = self.REQUIRED):
79 # Check if the section already contains the option
80 if option_name in section:
81 raise KeyError('Duplicated option declaration %s:%s' % (section_name, option_name))
82
83 # Add the option to the section
84 self.__sections[section_name][option_name] = self.Option(conv = conv,
85 default = default)
86
87 # Return the function as context
88 yield declarator
89
90
91 @property

Callers 11

config_dbFunction · 0.80
config_webFunction · 0.80
config_emailFunction · 0.80
config_dnsFunction · 0.80
config_loggingFunction · 0.80
config_captchaFunction · 0.80
config_blacklistFunction · 0.80
config_signupFunction · 0.80
config_wsgiFunction · 0.80
config_authFunction · 0.80
config_authFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected