@@ -88,15 +88,15 @@ def filter(self, cond, warn=None) -> TagGroup:
8888 new_group .append (e )
8989 else :
9090 if warn :
91- warnings .warn ("Filtered {} element ({})" . format ( self . tag , warn ) )
91+ warnings .warn (f "Filtered { self . tag } element ({ warn } )", stacklevel = 1 )
9292 return TagGroup (self .tag , new_group )
9393
9494 def force_singleton (self , warn = True ) -> TagGroup :
9595 if len (self .group ) == 1 :
9696 return self
9797 else :
9898 if warn :
99- warnings .warn ("Forced single instance of {}" . format ( self .tag ) )
99+ warnings .warn (f "Forced single instance of { self .tag } " , stacklevel = 1 )
100100 return TagGroup (self .tag , self .group [:1 ])
101101
102102 RE_ISO8601_DATE = r"^\d{2}(\d{2}|XX)(-\d{2}-\d{2})?$" # Note: Includes non-specific century dates like '18XX'
@@ -106,31 +106,33 @@ def fix_date(self) -> TagGroup:
106106 for e in self .group :
107107 if e .attrib .get ("encoding" ) == "w3cdtf" :
108108 # This should be 'iso8601' according to MODS-AP 2.3.1
109- warnings .warn ("Changed w3cdtf encoding to iso8601" )
109+ warnings .warn ("Changed w3cdtf encoding to iso8601" , stacklevel = 1 )
110110 e .attrib ["encoding" ] = "iso8601"
111111
112112 new_group = []
113113 for e in self .group :
114114 if e .text is None :
115- warnings .warn ("Empty date" )
115+ warnings .warn ("Empty date" , stacklevel = 1 )
116116 continue
117117 if e .attrib .get ("encoding" ) == "iso8601" and re .match (
118118 self .RE_ISO8601_DATE , e .text
119119 ):
120120 new_group .append (e )
121121 elif re .match (self .RE_ISO8601_DATE , e .text ):
122- warnings .warn ("Added iso8601 encoding to date {}" . format ( e .text ) )
122+ warnings .warn (f "Added iso8601 encoding to date { e .text } " , stacklevel = 1 )
123123 e .attrib ["encoding" ] = "iso8601"
124124 new_group .append (e )
125125 elif m := re .match (self .RE_GERMAN_DATE , e .text ):
126- warnings .warn ("Converted date {} to iso8601 encoding" .format (e .text ))
126+ warnings .warn (
127+ f"Converted date { e .text } to iso8601 encoding" , stacklevel = 1
128+ )
127129 e .text = "{}-{}-{}" .format (
128130 m .group ("yyyy" ), m .group ("mm" ), m .group ("dd" )
129131 )
130132 e .attrib ["encoding" ] = "iso8601"
131133 new_group .append (e )
132134 else :
133- warnings .warn ('Not a iso8601 date: "{}"' . format ( e .text ) )
135+ warnings .warn (f 'Not a iso8601 date: "{ e .text } "' , stacklevel = 1 )
134136 new_group .append (e )
135137 self .group = new_group
136138
@@ -159,21 +161,27 @@ def fix_event_type(self) -> TagGroup:
159161 and e .find ("mods:edition" , ns ).text == "[Electronic ed.]"
160162 ):
161163 e .attrib ["eventType" ] = "digitization"
162- warnings .warn ("Fixed eventType for electronic ed." )
164+ warnings .warn (
165+ "Fixed eventType for electronic ed." , stacklevel = 1
166+ )
163167 continue
164168 except AttributeError :
165169 pass
166170 try :
167171 if e .find ("mods:dateIssued" , ns ) is not None :
168172 e .attrib ["eventType" ] = "publication"
169- warnings .warn ("Fixed eventType for an issued origin" )
173+ warnings .warn (
174+ "Fixed eventType for an issued origin" , stacklevel = 1
175+ )
170176 continue
171177 except AttributeError :
172178 pass
173179 try :
174180 if e .find ("mods:dateCreated" , ns ) is not None :
175181 e .attrib ["eventType" ] = "production"
176- warnings .warn ("Fixed eventType for a created origin" )
182+ warnings .warn (
183+ "Fixed eventType for a created origin" , stacklevel = 1
184+ )
177185 continue
178186 except AttributeError :
179187 pass
@@ -184,20 +192,25 @@ def fix_script_term(self) -> TagGroup:
184192 # MODS-AP 2.3.1 is not clear about this, but it looks like that this should be lower case.
185193 if e .attrib ["authority" ] == "ISO15924" :
186194 e .attrib ["authority" ] = "iso15924"
187- warnings .warn ("Changed scriptTerm authority to lower case" )
195+ warnings .warn (
196+ "Changed scriptTerm authority to lower case" , stacklevel = 1
197+ )
188198 return self
189199
190200 def fix_language_term (self ) -> TagGroup :
191201 for e in self .group :
192202 if e .attrib ["authority" ] == "iso639-2" :
193203 e .attrib ["authority" ] = "iso639-2b"
194- warnings .warn ("Changed languageTerm authority to iso639-2b" )
204+ warnings .warn (
205+ "Changed languageTerm authority to iso639-2b" , stacklevel = 1
206+ )
195207 if e .attrib ["authority" ] == "rfc3066" :
196208 if e .text == "de" :
197209 e .attrib ["authority" ] = "iso639-2b"
198210 e .text = "deu"
199211 warnings .warn (
200- "Changed languageTerm authority from rfc3066 to iso639-2b"
212+ "Changed languageTerm authority from rfc3066 to iso639-2b" ,
213+ stacklevel = 1 ,
201214 )
202215 return self
203216
@@ -206,7 +219,7 @@ def add_missing_type_text(self) -> TagGroup:
206219 # Default to type=text
207220 if "type" not in e .attrib :
208221 e .attrib ["type" ] = "text"
209- warnings .warn ("Added placeTerm type='text'" )
222+ warnings .warn ("Added placeTerm type='text'" , stacklevel = 1 )
210223 return self
211224
212225 def remove_attributes (self , attribs ) -> TagGroup :
@@ -304,7 +317,9 @@ def fix_recordIdentifier_source_zdb(self) -> TagGroup:
304317 if e .get ("type" ) == "zdb" :
305318 e .attrib ["source" ] = "zdb"
306319 del e .attrib ["type" ]
307- warnings .warn ("Fixed recordIdentifier type 'zdb' to source" )
320+ warnings .warn (
321+ "Fixed recordIdentifier type 'zdb' to source" , stacklevel = 1
322+ )
308323 return self
309324
310325
0 commit comments