32
32
"""
33
33
34
34
import array
35
- from ast import literal_eval
36
35
import codecs
37
- from email .parser import HeaderParser
38
36
import struct
39
37
import sys
38
+ from ast import literal_eval
39
+ from email .parser import HeaderParser
40
40
41
41
PY3 = sys .version_info [0 ] == 3
42
42
if PY3 :
@@ -55,7 +55,7 @@ def header_charset(s):
55
55
from cStringIO import StringIO as BytesIO
56
56
# file is a type defined only under python 2.
57
57
# Flake8 when run in py3 flags this.
58
- FILE_TYPE = file # noqa: 821
58
+ FILE_TYPE = file # noqa: F821
59
59
60
60
61
61
class PoSyntaxError (Exception ):
@@ -102,13 +102,13 @@ def readPoData(self):
102
102
return [first ] + output .readlines ()
103
103
return output
104
104
105
- def add (self , context , id , string , fuzzy ):
105
+ def add (self , context , label , string , fuzzy ):
106
106
"Add a non-empty and non-fuzzy translation to the dictionary."
107
107
if string and not fuzzy :
108
108
# The context is put before the id and separated by a EOT char.
109
109
if context :
110
- id = context + u'\x04 ' + id
111
- if not id :
110
+ label = context + u'\x04 ' + label
111
+ if not label :
112
112
# See whether there is an encoding declaration
113
113
charset = header_charset (string )
114
114
if charset :
@@ -118,29 +118,29 @@ def add(self, context, id, string, fuzzy):
118
118
# undo damage done by literal_eval in Python 2.x
119
119
string = string .encode (self .encoding ).decode (charset )
120
120
self .encoding = charset
121
- self .messages [id ] = string
121
+ self .messages [label ] = string
122
122
123
123
def generate (self ):
124
124
"Return the generated output."
125
125
# the keys are sorted in the .mo file
126
126
keys = sorted (self .messages .keys ())
127
127
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 )
132
132
# For each string, we need size and file offset. Each string is
133
133
# 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 ),
135
135
len (msg )))
136
- ids += id + b'\0 '
136
+ labels += label + b'\0 '
137
137
strs += msg + b'\0 '
138
138
output = b''
139
139
# The header is 7 32-bit unsigned integers. We don't use hash tables,
140
140
# so the keys start right after the index tables.
141
141
keystart = 7 * 4 + 16 * len (keys )
142
142
# and the values start after the keys
143
- valuestart = keystart + len (ids )
143
+ valuestart = keystart + len (labels )
144
144
koffsets = []
145
145
voffsets = []
146
146
# The string table first has the list of keys, then the list of values.
@@ -163,7 +163,7 @@ def generate(self):
163
163
output += array .array ("i" , offsets ).tobytes ()
164
164
else :
165
165
output += array .array ("i" , offsets ).tostring ()
166
- output += ids
166
+ output += labels
167
167
output += strs
168
168
return output
169
169
@@ -184,6 +184,7 @@ def read(self, header_only=False):
184
184
msgid = msgstr = msgctxt = u''
185
185
186
186
# Parse the catalog
187
+ # ruff: noqa: E741 PLW2901 - 'l' var name ok; overwrite 'l' ok
187
188
lno = 0
188
189
for l in self .readPoData ():
189
190
l = l .decode (self .encoding )
0 commit comments