From 1817caf30f16712c59475db2af98030f9456cebf Mon Sep 17 00:00:00 2001
From: Sayamindu Dasgupta <sayamindu@gmail.com>
Date: Tue, 9 Feb 2010 17:13:04 +0530
Subject: Consistent variable names
---
src/sugar/activity/i18n.py | 38 +++++++++++++++++++-------------------
1 files changed, 19 insertions(+), 19 deletions(-)
diff --git a/src/sugar/activity/i18n.py b/src/sugar/activity/i18n.py
index a91b912..d235a55 100644
a
|
b
|
_MO_BIG_ENDIAN = 0xde120495 |
31 | 31 | _MO_LITTLE_ENDIAN = 0x950412de |
32 | 32 | |
33 | 33 | |
34 | | def _readbin(handle, fmt, bytecount): |
| 34 | def _read_bin(handle, fmt, bytecount): |
35 | 35 | read_bytes = handle.read(bytecount) |
36 | | retvalue = struct.unpack(fmt, read_bytes) |
37 | | if len(retvalue) == 1: |
38 | | return retvalue[0] |
| 36 | ret_value = struct.unpack(fmt, read_bytes) |
| 37 | if len(ret_value) == 1: |
| 38 | return ret_value[0] |
39 | 39 | else: |
40 | | return retvalue |
| 40 | return ret_value |
41 | 41 | |
42 | 42 | |
43 | 43 | def _extract_header(filepath): |
44 | 44 | header = '' |
45 | 45 | handle = open(filepath, 'rb') |
46 | | magic_number = _readbin(handle, '<I', 4) |
| 46 | magic_number = _read_bin(handle, '<I', 4) |
47 | 47 | |
48 | 48 | if magic_number == _MO_BIG_ENDIAN: |
49 | 49 | fmt = '>II' |
… |
… |
def _extract_header(filepath): |
52 | 52 | else: |
53 | 53 | raise IOError('File does not seem to be valid MO file') |
54 | 54 | |
55 | | version_, numofstrings = _readbin(handle, fmt, 8) |
| 55 | version_, num_of_strings = _read_bin(handle, fmt, 8) |
56 | 56 | |
57 | | msgids_hash_offset, msgstrs_hash_offset = _readbin(handle, fmt, 8) |
| 57 | msgids_hash_offset, msgstrs_hash_offset = _read_bin(handle, fmt, 8) |
58 | 58 | handle.seek(msgids_hash_offset) |
59 | 59 | |
60 | 60 | msgids_index = [] |
61 | | for i in range(numofstrings): |
62 | | msgids_index.append(_readbin(handle, fmt, 8)) |
| 61 | for i in range(num_of_strings): |
| 62 | msgids_index.append(_read_bin(handle, fmt, 8)) |
63 | 63 | handle.seek(msgstrs_hash_offset) |
64 | 64 | |
65 | 65 | msgstrs_index = [] |
66 | | for i in range(numofstrings): |
67 | | msgstrs_index.append(_readbin(handle, fmt, 8)) |
| 66 | for i in range(num_of_strings): |
| 67 | msgstrs_index.append(_read_bin(handle, fmt, 8)) |
68 | 68 | |
69 | | for i in range(numofstrings): |
| 69 | for i in range(num_of_strings): |
70 | 70 | handle.seek(msgids_index[i][1]) |
71 | 71 | msgid = handle.read(msgids_index[i][0]) |
72 | 72 | if msgid == '': |
… |
… |
def _extract_modification_time(filepath): |
86 | 86 | items = header.split('\n') |
87 | 87 | for item in items: |
88 | 88 | if item.startswith('PO-Revision-Date:'): |
89 | | timestr = item.split(': ')[1] |
90 | | parsedtime = dateutil.parser.parse(timestr) |
91 | | return time.mktime(parsedtime.timetuple()) |
| 89 | time_str = item.split(': ')[1] |
| 90 | parsed_time = dateutil.parser.parse(time_str) |
| 91 | return time.mktime(parsed_time.timetuple()) |
92 | 92 | |
93 | 93 | raise ValueError('Could not find revision date') |
94 | 94 | return -1 |
… |
… |
def get_locale_path(bundle_id): |
124 | 124 | |
125 | 125 | for candidate_dir in candidate_dirs.keys(): |
126 | 126 | if os.path.exists(candidate_dir): |
127 | | fullpath = os.path.join(candidate_dir, \ |
| 127 | full_path = os.path.join(candidate_dir, \ |
128 | 128 | locale.getdefaultlocale()[0], 'LC_MESSAGES', \ |
129 | 129 | bundle_id + '.mo') |
130 | | if os.path.exists(fullpath): |
| 130 | if os.path.exists(full_path): |
131 | 131 | try: |
132 | 132 | candidate_dirs[candidate_dir] = \ |
133 | | _extract_modification_time(fullpath) |
| 133 | _extract_modification_time(full_path) |
134 | 134 | except (IOError, ValueError): |
135 | 135 | # The mo file is damaged or has not been initialized |
136 | 136 | # Set lowest priority |