4545from .types import NetProtocol
4646
4747class ServerConfig (Config ):
48- """Server configuration."""
49- def __init__ (self , name : str ):
50- super ().__init__ (name )
48+ """Server configuration.
49+ """
50+ def __init__ (self , name : str , * , optional : bool = False ):
51+ super ().__init__ (name , optional = optional )
5152 #: Server host machine specification
5253 self .host : StrOption = \
5354 StrOption ('host' , "Server host machine specification" )
@@ -59,7 +60,8 @@ def __init__(self, name: str):
5960 StrOption ('user' , "Defaul user name" , default = os .environ .get ('ISC_USER' , None ))
6061 #: Default user password, default is envar ISC_PASSWORD or None if not specified
6162 self .password : StrOption = \
62- StrOption ('password' , "Default user password" , default = os .environ .get ('ISC_PASSWORD' , None ))
63+ StrOption ('password' , "Default user password" ,
64+ default = os .environ .get ('ISC_PASSWORD' , None ))
6365 #: Configuration override
6466 self .config : StrOption = \
6567 StrOption ('config' , "Configuration override" )
@@ -71,9 +73,10 @@ def __init__(self, name: str):
7173 BoolOption ('trusted_auth' , "Use trusted authentication" , default = False )
7274
7375class DatabaseConfig (Config ):
74- "Database configuration."
75- def __init__ (self , name : str ):
76- super ().__init__ (name )
76+ """Database configuration.
77+ """
78+ def __init__ (self , name : str , * , optional : bool = False ):
79+ super ().__init__ (name , optional = optional )
7780 #: Name of server where database is located
7881 self .server : StrOption = \
7982 StrOption ('server' , "Name of server where database is located" )
@@ -94,7 +97,8 @@ def __init__(self, name: str):
9497 StrOption ('user' , "Defaul user name" , default = os .environ .get ('ISC_USER' , None ))
9598 #: Default user password, default is envar ISC_PASSWORD or None if not specified
9699 self .password : StrOption = \
97- StrOption ('password' , "Default user password" , default = os .environ .get ('ISC_PASSWORD' , None ))
100+ StrOption ('password' , "Default user password" ,
101+ default = os .environ .get ('ISC_PASSWORD' , None ))
98102 #: Use trusted authentication, default: False
99103 self .trusted_auth : BoolOption = \
100104 BoolOption ('trusted_auth' , "Use trusted authentication" , default = False )
@@ -118,7 +122,8 @@ def __init__(self, name: str):
118122 IntOption ('cache_size' , "Page cache size override for database connections" )
119123 #: Dummy packet interval for this database connection
120124 self .dummy_packet_interval : IntOption = \
121- IntOption ('dummy_packet_interval' , "Dummy packet interval for this database connections" )
125+ IntOption ('dummy_packet_interval' ,
126+ "Dummy packet interval for this database connections" )
122127 #: Configuration override
123128 self .config : StrOption = \
124129 StrOption ('config' , "Configuration override" )
@@ -150,10 +155,10 @@ def __init__(self, name: str):
150155 "Data page space usage (True = reserve space, False = Use all space)" )
151156
152157class DriverConfig (Config ):
153- "Driver configuration."
158+ """Driver configuration.
159+ """
154160 def __init__ (self , name : str ):
155161 super ().__init__ (name )
156- self ._parser : ConfigParser = ConfigParser (interpolation = ExtendedInterpolation ())
157162 #: Path to Firebird client library
158163 self .fb_client_library : StrOption = \
159164 StrOption ('fb_client_library' , "Path to Firebird client library" )
@@ -163,9 +168,11 @@ def __init__(self, name: str):
163168 "BLOB size threshold. Bigger BLOB will be returned as stream BLOBs." ,
164169 default = 65536 )
165170 #: Default database configuration ('firebird.db.defaults')
166- self .db_defaults : DatabaseConfig = DatabaseConfig ('firebird.db.defaults' )
171+ self .db_defaults : DatabaseConfig = DatabaseConfig ('firebird.db.defaults' ,
172+ optional = True )
167173 #: Default server configuration ('firebird.server.defaults')
168- self .server_defaults : ServerConfig = ServerConfig ('firebird.server.defaults' )
174+ self .server_defaults : ServerConfig = ServerConfig ('firebird.server.defaults' ,
175+ optional = True )
169176 #: Registered servers
170177 self .servers : ConfigListOption = \
171178 ConfigListOption ('servers' , "Registered servers" , ServerConfig )
@@ -184,22 +191,24 @@ def read(self, filenames: Union[str, Iterable], encoding: str=None):
184191
185192 Return list of successfully read files.
186193 """
187- read_ok = self . _parser . read ( filenames , encoding )
188- self . _parser . clear ( )
189- self .load_config (self . _parser )
194+ parser = ConfigParser ( interpolation = ExtendedInterpolation () )
195+ read_ok = parser . read ( filenames , encoding )
196+ self .load_config (parser )
190197 return read_ok
191198 def read_file (self , f ):
192199 """Read configuration from a file-like object.
193200
194201 The `f` argument must be iterable, returning one line at a time.
195202 """
196- self ._parser .clear ()
197- self ._parser .read_file (f )
203+ parser = ConfigParser (interpolation = ExtendedInterpolation ())
204+ parser .read_file (f )
205+ self .load_config (parser )
198206 def read_string (self , string : str ) -> None :
199- "Read configuration from a given string."
200- self ._parser .clear ()
201- self ._parser .read_string (string )
202- self .load_config (self ._parser )
207+ """Read configuration from a given string.
208+ """
209+ parser = ConfigParser (interpolation = ExtendedInterpolation ())
210+ parser .read_string (string )
211+ self .load_config (parser )
203212 def read_dict (self , dictionary : Dict ) -> None :
204213 """Read configuration from a dictionary.
205214
@@ -210,64 +219,66 @@ def read_dict(self, dictionary: Dict) -> None:
210219 All types held in the dictionary are converted to strings during
211220 reading, including section names, option names and keys.
212221 """
213- self . _parser . clear ( )
214- self . _parser .read_dict (dictionary )
215- self .load_config (self . _parser )
222+ parser = ConfigParser ( interpolation = ExtendedInterpolation () )
223+ parser .read_dict (dictionary )
224+ self .load_config (parser )
216225 def get_server (self , name : str ) -> ServerConfig :
217- "Return server configuration."
226+ """Returns server configuration.
227+ """
218228 for srv in self .servers .value :
219229 if srv .name == name :
220230 return srv
221231 return None
222232 def get_database (self , name : str ) -> DatabaseConfig :
223- "Return database configuration."
233+ """Returns database configuration.
234+ """
224235 for db in self .databases .value :
225236 if db .name == name :
226237 return db
227238 return None
228239 def register_server (self , name : str , config : str = None ) -> ServerConfig :
229240 """Register server.
230241
231- Arguments:
232- name: Server name.
233- config: Optional server configuration string in ConfigParser format in [name] section.
242+ Arguments:
243+ name: Server name.
244+ config: Optional server configuration string in ConfigParser format in [name] section.
234245
235- Returns:
236- ServerConfig: For newly registered server
246+ Returns:
247+ ServerConfig: For newly registered server
237248
238- Raises:
239- ValueError: If server is already registered.
240- """
249+ Raises:
250+ ValueError: If server is already registered.
251+ """
241252 if self .get_server (name ) is not None :
242253 raise ValueError (f"Server '{ name } ' already registered." )
243254 srv_config = ServerConfig (name )
244255 self .servers .value .append (srv_config )
245256 if config :
246- self . _parser . clear ( )
247- self . _parser .read_string (config )
248- srv_config .load_config (self . _parser , name )
257+ parser = ConfigParser ( interpolation = ExtendedInterpolation () )
258+ parser .read_string (config )
259+ srv_config .load_config (parser , name )
249260 return srv_config
250261 def register_database (self , name : str , config : str = None ) -> DatabaseConfig :
251262 """Register database.
252263
253- Arguments:
254- name: Database name.
255- config: Optional database configuration string in ConfigParser format in [name] section.
264+ Arguments:
265+ name: Database name.
266+ config: Optional database configuration string in ConfigParser format in [name] section.
256267
257- Returns:
258- DatabaseConfig: For newly registered database
268+ Returns:
269+ DatabaseConfig: For newly registered database
259270
260- Raises:
261- ValueError: If database is already registered.
262- """
271+ Raises:
272+ ValueError: If database is already registered.
273+ """
263274 if self .get_database (name ) is not None :
264275 raise ValueError (f"Database '{ name } ' already registered." )
265276 db_config = DatabaseConfig (name )
266277 self .databases .value .append (db_config )
267278 if config :
268- self . _parser . clear ( )
269- self . _parser .read_string (config )
270- db_config .load_config (self . _parser , name )
279+ parser = ConfigParser ( interpolation = ExtendedInterpolation () )
280+ parser .read_string (config )
281+ db_config .load_config (parser , name )
271282 return db_config
272283
273284# Configuration
0 commit comments