@@ -744,7 +744,7 @@ def __init__(self, baseuri=None, baselang=None, encoding="utf-8"):
744744
745745 def unknown_starttag (self , tag , attrs ):
746746 if _debug :
747- sys .stderr .write ("start %s with %s \n " % ( tag , attrs ) )
747+ sys .stderr .write (f "start { tag } with { attrs } \n " )
748748 # normalize attrs
749749 attrs = [(k .lower (), v ) for k , v in attrs ]
750750 attrs = [(k , k in ("rel" , "type" ) and v .lower () or v ) for k , v in attrs ]
@@ -792,7 +792,7 @@ def unknown_starttag(self, tag, attrs):
792792 # This will horribly munge inline content with non-empty qnames,
793793 # but nobody actually does that, so I'm not fixing it.
794794 tag = tag .split (":" )[- 1 ]
795- return self .handle_data ("<%s%s>" % ( tag , self .strattrs (attrs )) , escape = 0 )
795+ return self .handle_data (f"< { tag } { self .strattrs (attrs )} >" , escape = 0 )
796796
797797 # match namespaces
798798 if tag .find (":" ) != - 1 :
@@ -971,7 +971,7 @@ def decodeEntities(self, element, data):
971971 return data
972972
973973 def strattrs (self , attrs ):
974- return "" .join ([' %s="%s"' % (t [0 ], _xmlescape (t [1 ], {'"' : """ })) for t in attrs ])
974+ return "" .join ([' {}="{}"' . format (t [0 ], _xmlescape (t [1 ], {'"' : """ })) for t in attrs ])
975975
976976 def push (self , element , expectingText ):
977977 self .elementstack .append ([element , expectingText , []])
@@ -1388,7 +1388,7 @@ def _sync_author_detail(self, key="author"):
13881388 name = detail .get ("name" )
13891389 email = detail .get ("email" )
13901390 if name and email :
1391- context [key ] = "%s (%s)" % ( name , email )
1391+ context [key ] = f" { name } ( { email } )"
13921392 elif name :
13931393 context [key ] = name
13941394 elif email :
@@ -1956,7 +1956,7 @@ def unknown_starttag(self, tag, attrs):
19561956 if type (value ) != str :
19571957 value = str (value , self .encoding )
19581958 uattrs .append ((str (key , self .encoding ), value ))
1959- strattrs = "" .join ([' %s="%s"' % ( key , value ) for key , value in uattrs ]).encode (self .encoding )
1959+ strattrs = "" .join ([f' { key } =" { value } "' for key , value in uattrs ]).encode (self .encoding )
19601960 if tag in self .elements_no_end_tag :
19611961 self .pieces .append ("<%(tag)s%(strattrs)s />" % locals ())
19621962 else :
@@ -2438,7 +2438,7 @@ def _open_resource(url_file_stream_or_string, etag, modified, agent, referrer, h
24382438 if realhost :
24392439 user_passwd , realhost = urllib .splituser (realhost )
24402440 if user_passwd :
2441- url_file_stream_or_string = "%s ://%s%s" % ( urltype , realhost , rest )
2441+ url_file_stream_or_string = f" { urltype } ://{ realhost } { rest } "
24422442 auth = base64 .encodestring (user_passwd ).strip ()
24432443 # try to open with urllib2 (to use optional headers)
24442444 request = urllib .request .Request (url_file_stream_or_string )
@@ -2638,10 +2638,10 @@ def _parse_date_iso8601(dateString):
26382638_korean_pm = "\uc624 \ud6c4 " # bfc0 c8c4 in euc-kr
26392639
26402640_korean_onblog_date_re = re .compile (
2641- r "(\d{4})%s \s+(\d{2})%s \s+(\d{2})%s \s+(\d{2} ):(\d{2} ):(\d{2})" % ( _korean_year , _korean_month , _korean_day ) ,
2641+ fr "(\d{{4}}) { _korean_year } \s+(\d{{2}}) { _korean_month } \s+(\d{{2}}) { _korean_day } \s+(\d{{2}} ):(\d{{2}} ):(\d{{2}})" ,
26422642)
26432643_korean_nate_date_re = re .compile (
2644- r "(\d{4} )-(\d{2} )-(\d{2} )\s+(%s|%s )\s+(\d{,2}):(\d{,2}):(\d{,2})" % ( _korean_am , _korean_pm ) ,
2644+ fr "(\d{{4}} )-(\d{{2}} )-(\d{{2}} )\s+({ _korean_am } | { _korean_pm } )\s+(\d{{ ,2}} ):(\d{{ ,2}} ):(\d{{ ,2}})" ,
26452645)
26462646
26472647
@@ -2650,15 +2650,15 @@ def _parse_date_onblog(dateString):
26502650 m = _korean_onblog_date_re .match (dateString )
26512651 if not m :
26522652 return None
2653- w3dtfdate = "%( year)s-%( month)s-%( day)sT%( hour)s:%( minute)s:%( second)s%( zonediff)s" % {
2654- " year" : m .group (1 ),
2655- " month" : m .group (2 ),
2656- " day" : m .group (3 ),
2657- " hour" : m .group (4 ),
2658- " minute" : m .group (5 ),
2659- " second" : m .group (6 ),
2660- " zonediff" : "+09:00" ,
2661- }
2653+ w3dtfdate = "{ year}-{ month}-{ day}T{ hour}:{ minute}:{ second}{ zonediff}" . format (
2654+ year = m .group (1 ),
2655+ month = m .group (2 ),
2656+ day = m .group (3 ),
2657+ hour = m .group (4 ),
2658+ minute = m .group (5 ),
2659+ second = m .group (6 ),
2660+ zonediff = "+09:00" ,
2661+ )
26622662 if _debug :
26632663 sys .stderr .write ("OnBlog date parsed as: %s\n " % w3dtfdate )
26642664 return _parse_date_w3dtf (w3dtfdate )
@@ -2679,15 +2679,15 @@ def _parse_date_nate(dateString):
26792679 hour = str (hour )
26802680 if len (hour ) == 1 :
26812681 hour = "0" + hour
2682- w3dtfdate = "%( year)s-%( month)s-%( day)sT%( hour)s:%( minute)s:%( second)s%( zonediff)s" % {
2683- " year" : m .group (1 ),
2684- " month" : m .group (2 ),
2685- " day" : m .group (3 ),
2686- " hour" : hour ,
2687- " minute" : m .group (6 ),
2688- " second" : m .group (7 ),
2689- " zonediff" : "+09:00" ,
2690- }
2682+ w3dtfdate = "{ year}-{ month}-{ day}T{ hour}:{ minute}:{ second}{ zonediff}" . format (
2683+ year = m .group (1 ),
2684+ month = m .group (2 ),
2685+ day = m .group (3 ),
2686+ hour = hour ,
2687+ minute = m .group (6 ),
2688+ second = m .group (7 ),
2689+ zonediff = "+09:00" ,
2690+ )
26912691 if _debug :
26922692 sys .stderr .write ("Nate date parsed as: %s\n " % w3dtfdate )
26932693 return _parse_date_w3dtf (w3dtfdate )
@@ -2703,15 +2703,15 @@ def _parse_date_mssql(dateString):
27032703 m = _mssql_date_re .match (dateString )
27042704 if not m :
27052705 return None
2706- w3dtfdate = "%( year)s-%( month)s-%( day)sT%( hour)s:%( minute)s:%( second)s%( zonediff)s" % {
2707- " year" : m .group (1 ),
2708- " month" : m .group (2 ),
2709- " day" : m .group (3 ),
2710- " hour" : m .group (4 ),
2711- " minute" : m .group (5 ),
2712- " second" : m .group (6 ),
2713- " zonediff" : "+09:00" ,
2714- }
2706+ w3dtfdate = "{ year}-{ month}-{ day}T{ hour}:{ minute}:{ second}{ zonediff}" . format (
2707+ year = m .group (1 ),
2708+ month = m .group (2 ),
2709+ day = m .group (3 ),
2710+ hour = m .group (4 ),
2711+ minute = m .group (5 ),
2712+ second = m .group (6 ),
2713+ zonediff = "+09:00" ,
2714+ )
27152715 if _debug :
27162716 sys .stderr .write ("MS SQL date parsed as: %s\n " % w3dtfdate )
27172717 return _parse_date_w3dtf (w3dtfdate )
@@ -2765,16 +2765,16 @@ def _parse_date_greek(dateString):
27652765 month = _greek_months [m .group (3 )]
27662766 except :
27672767 return None
2768- rfc822date = "%( wday)s, %( day)s %( month)s %( year)s %( hour)s:%( minute)s:%( second)s %( zonediff)s" % {
2769- " wday" : wday ,
2770- " day" : m .group (2 ),
2771- " month" : month ,
2772- " year" : m .group (4 ),
2773- " hour" : m .group (5 ),
2774- " minute" : m .group (6 ),
2775- " second" : m .group (7 ),
2776- " zonediff" : m .group (8 ),
2777- }
2768+ rfc822date = "{ wday}, { day} { month} { year} { hour}:{ minute}:{ second} { zonediff}" . format (
2769+ wday = wday ,
2770+ day = m .group (2 ),
2771+ month = month ,
2772+ year = m .group (4 ),
2773+ hour = m .group (5 ),
2774+ minute = m .group (6 ),
2775+ second = m .group (7 ),
2776+ zonediff = m .group (8 ),
2777+ )
27782778 if _debug :
27792779 sys .stderr .write ("Greek date parsed as: %s\n " % rfc822date )
27802780 return _parse_date_rfc822 (rfc822date )
@@ -2816,14 +2816,14 @@ def _parse_date_hungarian(dateString):
28162816 hour = "0" + hour
28172817 except :
28182818 return None
2819- w3dtfdate = "%( year)s-%( month)s-%( day)sT%( hour)s:%( minute)s%( zonediff)s" % {
2820- " year" : m .group (1 ),
2821- " month" : month ,
2822- " day" : day ,
2823- " hour" : hour ,
2824- " minute" : m .group (5 ),
2825- " zonediff" : m .group (6 ),
2826- }
2819+ w3dtfdate = "{ year}-{ month}-{ day}T{ hour}:{ minute}{ zonediff}" . format (
2820+ year = m .group (1 ),
2821+ month = month ,
2822+ day = day ,
2823+ hour = hour ,
2824+ minute = m .group (5 ),
2825+ zonediff = m .group (6 ),
2826+ )
28272827 if _debug :
28282828 sys .stderr .write ("Hungarian date parsed as: %s\n " % w3dtfdate )
28292829 return _parse_date_w3dtf (w3dtfdate )
@@ -2924,7 +2924,7 @@ def __extract_tzd(m):
29242924 __time_re = (
29252925 r"(?P<hours>\d\d)(?P<tsep>:|)(?P<minutes>\d\d)(?:(?P=tsep)(?P<seconds>\d\d(?:[.,]\d+)?))?" + __tzd_re
29262926 )
2927- __datetime_re = "%s (?:T%s )?" % ( __date_re , __time_re )
2927+ __datetime_re = f" { __date_re } (?:T{ __time_re } )?"
29282928 __datetime_rx = re .compile (__datetime_re )
29292929 m = __datetime_rx .match (dateString )
29302930 if (m is None ) or (m .group () != dateString ):
@@ -2980,7 +2980,7 @@ def _parse_date(dateString):
29802980 return date9tuple
29812981 except Exception as e :
29822982 if _debug :
2983- sys .stderr .write ("%s raised %s \n " % ( handler .__name__ , repr (e )) )
2983+ sys .stderr .write (f" { handler .__name__ } raised { repr (e )} \n " )
29842984 return None
29852985
29862986
@@ -3357,13 +3357,13 @@ def parse(url_file_stream_or_string, etag=None, modified=None, agent=None, refer
33573357 result ["bozo" ] = 1
33583358 result ["bozo_exception" ] = CharacterEncodingUnknown (
33593359 "document encoding unknown, I tried "
3360- + "%s, %s , utf-8, and windows-1252 but nothing worked" % (result ["encoding" ], xml_encoding ),
3360+ + "{}, {} , utf-8, and windows-1252 but nothing worked" . format (result ["encoding" ], xml_encoding ),
33613361 )
33623362 result ["encoding" ] = ""
33633363 elif proposed_encoding != result ["encoding" ]:
33643364 result ["bozo" ] = 1
33653365 result ["bozo_exception" ] = CharacterEncodingOverride (
3366- "documented declared as %s , but parsed as %s" % (result ["encoding" ], proposed_encoding ),
3366+ "documented declared as {} , but parsed as {}" . format (result ["encoding" ], proposed_encoding ),
33673367 )
33683368 result ["encoding" ] = proposed_encoding
33693369
0 commit comments