3232"""
3333
3434import array
35- from ast import literal_eval
3635import codecs
37- from email .parser import HeaderParser
3836import struct
3937import sys
38+ from ast import literal_eval
39+ from email .parser import HeaderParser
4040
4141PY3 = sys .version_info [0 ] == 3
4242if PY3 :
@@ -55,7 +55,7 @@ def header_charset(s):
5555 from cStringIO import StringIO as BytesIO
5656 # file is a type defined only under python 2.
5757 # Flake8 when run in py3 flags this.
58- FILE_TYPE = file # noqa: 821
58+ FILE_TYPE = file # noqa: F821
5959
6060
6161class PoSyntaxError (Exception ):
@@ -102,13 +102,13 @@ def readPoData(self):
102102 return [first ] + output .readlines ()
103103 return output
104104
105- def add (self , context , id , string , fuzzy ):
105+ def add (self , context , label , string , fuzzy ):
106106 "Add a non-empty and non-fuzzy translation to the dictionary."
107107 if string and not fuzzy :
108108 # The context is put before the id and separated by a EOT char.
109109 if context :
110- id = context + u'\x04 ' + id
111- if not id :
110+ label = context + u'\x04 ' + label
111+ if not label :
112112 # See whether there is an encoding declaration
113113 charset = header_charset (string )
114114 if charset :
@@ -118,29 +118,29 @@ def add(self, context, id, string, fuzzy):
118118 # undo damage done by literal_eval in Python 2.x
119119 string = string .encode (self .encoding ).decode (charset )
120120 self .encoding = charset
121- self .messages [id ] = string
121+ self .messages [label ] = string
122122
123123 def generate (self ):
124124 "Return the generated output."
125125 # the keys are sorted in the .mo file
126126 keys = sorted (self .messages .keys ())
127127 offsets = []
128- ids = strs = b''
129- for id in keys :
130- msg = self .messages [id ].encode (self .encoding )
131- id = id .encode (self .encoding )
128+ labels = strs = b''
129+ for label in keys :
130+ msg = self .messages [label ].encode (self .encoding )
131+ label = label .encode (self .encoding )
132132 # For each string, we need size and file offset. Each string is
133133 # NUL terminated; the NUL does not count into the size.
134- offsets .append ((len (ids ), len (id ), len (strs ),
134+ offsets .append ((len (labels ), len (label ), len (strs ),
135135 len (msg )))
136- ids += id + b'\0 '
136+ labels += label + b'\0 '
137137 strs += msg + b'\0 '
138138 output = b''
139139 # The header is 7 32-bit unsigned integers. We don't use hash tables,
140140 # so the keys start right after the index tables.
141141 keystart = 7 * 4 + 16 * len (keys )
142142 # and the values start after the keys
143- valuestart = keystart + len (ids )
143+ valuestart = keystart + len (labels )
144144 koffsets = []
145145 voffsets = []
146146 # The string table first has the list of keys, then the list of values.
@@ -163,7 +163,7 @@ def generate(self):
163163 output += array .array ("i" , offsets ).tobytes ()
164164 else :
165165 output += array .array ("i" , offsets ).tostring ()
166- output += ids
166+ output += labels
167167 output += strs
168168 return output
169169
@@ -184,6 +184,7 @@ def read(self, header_only=False):
184184 msgid = msgstr = msgctxt = u''
185185
186186 # Parse the catalog
187+ # ruff: noqa: E741 PLW2901 - 'l' var name ok; overwrite 'l' ok
187188 lno = 0
188189 for l in self .readPoData ():
189190 l = l .decode (self .encoding )
0 commit comments