Consistent variable names

This commit is contained in:
Sayamindu Dasgupta 2010-02-09 17:13:04 +05:30
parent ffe3504e0a
commit 1817caf30f

View File

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