@@ -90,17 +90,13 @@ class HBARecord:
9090 """Holds a HBA record composed of fields and a comment.
9191
9292 Common fields are accessible through attribute : ``conntype``,
93- ``databases ``, ``users ``, ``address``, ``netmask``, ``method``.
93+ ``database ``, ``user ``, ``address``, ``netmask``, ``method``.
9494 Auth-options fields are also accessible through attribute like ``map``,
9595 ``ldapserver``, etc.
9696
9797 ``address`` and ``netmask`` fields are not always defined. If not,
9898 accessing undefined attributes trigger an :exc:`AttributeError`.
9999
100- ``databases`` and ``users`` have a single value variant respectively
101- :attr:`database` and :attr:`user`, computed after the list representation
102- of the field.
103-
104100 .. automethod:: parse
105101 .. automethod:: __init__
106102 .. automethod:: __str__
@@ -112,8 +108,8 @@ class HBARecord:
112108
113109 COMMON_FIELDS = [
114110 "conntype" ,
115- "databases " ,
116- "users " ,
111+ "database " ,
112+ "user " ,
117113 "address" ,
118114 "netmask" ,
119115 "method" ,
@@ -137,7 +133,7 @@ def parse(cls, line: str) -> HBARecord:
137133
138134 """
139135 line = line .strip ()
140- record_fields = ["conntype" , "databases " , "users " ]
136+ record_fields = ["conntype" , "database " , "user " ]
141137
142138 # What the regexp below does is finding all elements separated by spaces
143139 # unless they are enclosed in double-quotes
@@ -146,9 +142,7 @@ def parse(cls, line: str) -> HBARecord:
146142 # double-quotes (alternative 1)
147143 # \S = any non-whitespace character (alternative 2)
148144 values = [p for p in re .findall (r"(?:\"+.*?\"+|\S)+" , line ) if p .strip ()]
149- # Split databases and users lists.
150- values [1 ] = values [1 ].split ("," )
151- values [2 ] = values [2 ].split ("," )
145+ assert len (values ) > 2
152146 try :
153147 hash_pos = values .index ("#" )
154148 except ValueError :
@@ -173,8 +167,8 @@ def parse(cls, line: str) -> HBARecord:
173167 return cls (options , comment = comment )
174168
175169 conntype : str | None
176- databases : list [ str ]
177- users : list [ str ]
170+ database : str
171+ user : str
178172
179173 def __init__ (
180174 self ,
@@ -188,10 +182,6 @@ def __init__(
188182 :param comment: Comment at the end of the line.
189183 """
190184 dict_values : dict [str , Any ] = dict (values or {}, ** kw_values )
191- if "database" in dict_values :
192- dict_values ["databases" ] = [dict_values .pop ("database" )]
193- if "user" in dict_values :
194- dict_values ["users" ] = [dict_values .pop ("user" )]
195185 self .__dict__ .update (dict_values )
196186 self .fields = [k for k , _ in dict_values .items ()]
197187 self .comment = comment
@@ -223,9 +213,7 @@ def __str__(self) -> str:
223213 fmt += "%%(%s)-%ds " % (field , width - 1 )
224214 else :
225215 fmt += f"%({ field } )s "
226- # Serialize database and user list using property.
227- values = dict (self .__dict__ , databases = self .database , users = self .user )
228- line = fmt .rstrip () % values
216+ line = fmt .rstrip () % self .__dict__
229217
230218 auth_options = ['%s="%s"' % i for i in self .auth_options ]
231219 if auth_options :
@@ -241,17 +229,13 @@ def __str__(self) -> str:
241229 def __eq__ (self , other : object ) -> bool :
242230 return str (self ) == str (other )
243231
244- def as_dict (self , serialized : bool = False ) -> dict [str , Any ]:
232+ def as_dict (self ) -> dict [str , Any ]:
245233 str_fields = self .COMMON_FIELDS [:]
246- if serialized :
247- str_fields [1 :3 ] = ["database" , "user" ]
248234 return {f : getattr (self , f ) for f in str_fields if hasattr (self , f )}
249235
250236 @property
251237 def common_values (self ) -> list [str ]:
252238 str_fields = self .COMMON_FIELDS [:]
253- # Use serialized variant.
254- str_fields [1 :3 ] = ["database" , "user" ]
255239 return [getattr (self , f ) for f in str_fields if f in self .fields ]
256240
257241 @property
@@ -260,26 +244,6 @@ def auth_options(self) -> list[tuple[str, str]]:
260244 (f , getattr (self , f )) for f in self .fields if f not in self .COMMON_FIELDS
261245 ]
262246
263- @property
264- def database (self ) -> str :
265- """Hold database column as a single value.
266-
267- Use `databases` attribute to get parsed database list. `database` is
268- guaranteed to be a string.
269-
270- """
271- return "," .join (self .databases )
272-
273- @property
274- def user (self ) -> str :
275- """Hold user column as a single value.
276-
277- Use ``users`` property to get parsed user list. ``user`` is guaranteed
278- to be a string.
279-
280- """
281- return "," .join (self .users )
282-
283247 def matches (self , ** attrs : str ) -> bool :
284248 """Tells if the current record is matching provided attributes.
285249
0 commit comments