Consistent variable names
This commit is contained in:
parent
ffe3504e0a
commit
1817caf30f
@ -31,19 +31,19 @@ _MO_BIG_ENDIAN = 0xde120495
|
|||||||
_MO_LITTLE_ENDIAN = 0x950412de
|
_MO_LITTLE_ENDIAN = 0x950412de
|
||||||
|
|
||||||
|
|
||||||
def _readbin(handle, fmt, bytecount):
|
def _read_bin(handle, fmt, bytecount):
|
||||||
read_bytes = handle.read(bytecount)
|
read_bytes = handle.read(bytecount)
|
||||||
retvalue = struct.unpack(fmt, read_bytes)
|
ret_value = struct.unpack(fmt, read_bytes)
|
||||||
if len(retvalue) == 1:
|
if len(ret_value) == 1:
|
||||||
return retvalue[0]
|
return ret_value[0]
|
||||||
else:
|
else:
|
||||||
return retvalue
|
return ret_value
|
||||||
|
|
||||||
|
|
||||||
def _extract_header(filepath):
|
def _extract_header(filepath):
|
||||||
header = ''
|
header = ''
|
||||||
handle = open(filepath, 'rb')
|
handle = open(filepath, 'rb')
|
||||||
magic_number = _readbin(handle, '<I', 4)
|
magic_number = _read_bin(handle, '<I', 4)
|
||||||
|
|
||||||
if magic_number == _MO_BIG_ENDIAN:
|
if magic_number == _MO_BIG_ENDIAN:
|
||||||
fmt = '>II'
|
fmt = '>II'
|
||||||
@ -52,21 +52,21 @@ def _extract_header(filepath):
|
|||||||
else:
|
else:
|
||||||
raise IOError('File does not seem to be valid MO file')
|
raise IOError('File does not seem to be valid MO file')
|
||||||
|
|
||||||
version_, numofstrings = _readbin(handle, fmt, 8)
|
version_, num_of_strings = _read_bin(handle, fmt, 8)
|
||||||
|
|
||||||
msgids_hash_offset, msgstrs_hash_offset = _readbin(handle, fmt, 8)
|
msgids_hash_offset, msgstrs_hash_offset = _read_bin(handle, fmt, 8)
|
||||||
handle.seek(msgids_hash_offset)
|
handle.seek(msgids_hash_offset)
|
||||||
|
|
||||||
msgids_index = []
|
msgids_index = []
|
||||||
for i in range(numofstrings):
|
for i in range(num_of_strings):
|
||||||
msgids_index.append(_readbin(handle, fmt, 8))
|
msgids_index.append(_read_bin(handle, fmt, 8))
|
||||||
handle.seek(msgstrs_hash_offset)
|
handle.seek(msgstrs_hash_offset)
|
||||||
|
|
||||||
msgstrs_index = []
|
msgstrs_index = []
|
||||||
for i in range(numofstrings):
|
for i in range(num_of_strings):
|
||||||
msgstrs_index.append(_readbin(handle, fmt, 8))
|
msgstrs_index.append(_read_bin(handle, fmt, 8))
|
||||||
|
|
||||||
for i in range(numofstrings):
|
for i in range(num_of_strings):
|
||||||
handle.seek(msgids_index[i][1])
|
handle.seek(msgids_index[i][1])
|
||||||
msgid = handle.read(msgids_index[i][0])
|
msgid = handle.read(msgids_index[i][0])
|
||||||
if msgid == '':
|
if msgid == '':
|
||||||
@ -86,9 +86,9 @@ def _extract_modification_time(filepath):
|
|||||||
items = header.split('\n')
|
items = header.split('\n')
|
||||||
for item in items:
|
for item in items:
|
||||||
if item.startswith('PO-Revision-Date:'):
|
if item.startswith('PO-Revision-Date:'):
|
||||||
timestr = item.split(': ')[1]
|
time_str = item.split(': ')[1]
|
||||||
parsedtime = dateutil.parser.parse(timestr)
|
parsed_time = dateutil.parser.parse(time_str)
|
||||||
return time.mktime(parsedtime.timetuple())
|
return time.mktime(parsed_time.timetuple())
|
||||||
|
|
||||||
raise ValueError('Could not find revision date')
|
raise ValueError('Could not find revision date')
|
||||||
return -1
|
return -1
|
||||||
@ -124,13 +124,13 @@ def get_locale_path(bundle_id):
|
|||||||
|
|
||||||
for candidate_dir in candidate_dirs.keys():
|
for candidate_dir in candidate_dirs.keys():
|
||||||
if os.path.exists(candidate_dir):
|
if os.path.exists(candidate_dir):
|
||||||
fullpath = os.path.join(candidate_dir, \
|
full_path = os.path.join(candidate_dir, \
|
||||||
locale.getdefaultlocale()[0], 'LC_MESSAGES', \
|
locale.getdefaultlocale()[0], 'LC_MESSAGES', \
|
||||||
bundle_id + '.mo')
|
bundle_id + '.mo')
|
||||||
if os.path.exists(fullpath):
|
if os.path.exists(full_path):
|
||||||
try:
|
try:
|
||||||
candidate_dirs[candidate_dir] = \
|
candidate_dirs[candidate_dir] = \
|
||||||
_extract_modification_time(fullpath)
|
_extract_modification_time(full_path)
|
||||||
except (IOError, ValueError):
|
except (IOError, ValueError):
|
||||||
# The mo file is damaged or has not been initialized
|
# The mo file is damaged or has not been initialized
|
||||||
# Set lowest priority
|
# Set lowest priority
|
||||||
|
Loading…
Reference in New Issue
Block a user