def load_resources(zdir): """ Loads all resources, setting all appropriate tz lists """ global all_timezones, all_timezones_set global common_timezones, common_timezones_set global _zdir _zdir = zdir all_timezones = LazyList(tz for tz in all_timezones if resource_exists(tz, zdir)) all_timezones_set = LazySet(all_timezones) common_timezones = LazyList(tz for tz in common_timezones if tz in all_timezones) common_timezones_set = LazySet(common_timezones)
'US/Arizona', 'US/Central', 'US/East-Indiana', 'US/Eastern', 'US/Hawaii', 'US/Indiana-Starke', 'US/Michigan', 'US/Mountain', 'US/Pacific', 'US/Samoa', 'UTC', 'Universal', 'W-SU', 'WET', 'Zulu'] all_timezones = LazyList(tz for tz in all_timezones if resource_exists(tz)) all_timezones_set = LazySet(all_timezones) common_timezones = \ ['Africa/Abidjan', 'Africa/Accra', 'Africa/Addis_Ababa', 'Africa/Algiers', 'Africa/Asmara', 'Africa/Bamako', 'Africa/Bangui', 'Africa/Banjul', 'Africa/Bissau', 'Africa/Blantyre', 'Africa/Brazzaville', 'Africa/Bujumbura',
def setUp(self): self.base = [3, 2, 1] self.lesser = [2, 1, 0] self.greater = [4, 3, 2] self.lazy = LazyList(iter(list(self.base)))
class LazyListTestCase(unittest.TestCase): initial_data = [3, 2, 1] def setUp(self): self.base = [3, 2, 1] self.lesser = [2, 1, 0] self.greater = [4, 3, 2] self.lazy = LazyList(iter(list(self.base))) def test_unary_ops(self): unary_ops = [str, repr, len, bool, not_] try: unary_ops.append(unicode) except NameError: pass # unicode no longer exists in Python 3. for op in unary_ops: self.assertEqual( op(self.lazy), op(self.base), str(op)) def test_binary_ops(self): binary_ops = [eq, ge, gt, le, lt, ne, add, concat] try: binary_ops.append(cmp) except NameError: pass # cmp no longer exists in Python 3. for op in binary_ops: self.assertEqual( op(self.lazy, self.lazy), op(self.base, self.base), str(op)) for other in [self.base, self.lesser, self.greater]: self.assertEqual( op(self.lazy, other), op(self.base, other), '%s %s' % (op, other)) self.assertEqual( op(other, self.lazy), op(other, self.base), '%s %s' % (op, other)) # Multiplication self.assertEqual(self.lazy * 3, self.base * 3) self.assertEqual(3 * self.lazy, 3 * self.base) # Contains self.assertTrue(2 in self.lazy) self.assertFalse(42 in self.lazy) def test_iadd(self): self.lazy += [1] self.base += [1] self.assertEqual(self.lazy, self.base) def test_bool(self): self.assertTrue(bool(self.lazy)) self.assertFalse(bool(LazyList())) self.assertFalse(bool(LazyList(iter([])))) def test_hash(self): self.assertRaises(TypeError, hash, self.lazy) def test_isinstance(self): self.assertTrue(isinstance(self.lazy, list)) self.assertFalse(isinstance(self.lazy, tuple)) def test_callable(self): try: callable except NameError: return # No longer exists with Python 3. self.assertFalse(callable(self.lazy)) def test_append(self): self.base.append('extra') self.lazy.append('extra') self.assertEqual(self.lazy, self.base) def test_count(self): self.assertEqual(self.lazy.count(2), 1) def test_index(self): self.assertEqual(self.lazy.index(2), 1) def test_extend(self): self.base.extend([6, 7]) self.lazy.extend([6, 7]) self.assertEqual(self.lazy, self.base) def test_insert(self): self.base.insert(0, 'ping') self.lazy.insert(0, 'ping') self.assertEqual(self.lazy, self.base) def test_pop(self): self.assertEqual(self.lazy.pop(), self.base.pop()) self.assertEqual(self.lazy, self.base) def test_remove(self): self.base.remove(2) self.lazy.remove(2) self.assertEqual(self.lazy, self.base) def test_reverse(self): self.base.reverse() self.lazy.reverse() self.assertEqual(self.lazy, self.base) def test_reversed(self): self.assertEqual(list(reversed(self.lazy)), list(reversed(self.base))) def test_sort(self): self.base.sort() self.assertNotEqual(self.lazy, self.base, 'Test data already sorted') self.lazy.sort() self.assertEqual(self.lazy, self.base) def test_sorted(self): self.assertEqual(sorted(self.lazy), sorted(self.base)) def test_getitem(self): for idx in range(-len(self.base), len(self.base)): self.assertEqual(self.lazy[idx], self.base[idx]) def test_setitem(self): for idx in range(-len(self.base), len(self.base)): self.base[idx] = idx + 1000 self.assertNotEqual(self.lazy, self.base) self.lazy[idx] = idx + 1000 self.assertEqual(self.lazy, self.base) def test_delitem(self): del self.base[0] self.assertNotEqual(self.lazy, self.base) del self.lazy[0] self.assertEqual(self.lazy, self.base) del self.base[-2] self.assertNotEqual(self.lazy, self.base) del self.lazy[-2] self.assertEqual(self.lazy, self.base) def test_iter(self): self.assertEqual(list(iter(self.lazy)), list(iter(self.base))) def test_getslice(self): for i in range(-len(self.base), len(self.base)): for j in range(-len(self.base), len(self.base)): for step in [-1, 1]: self.assertEqual(self.lazy[i:j:step], self.base[i:j:step]) def test_setslice(self): for i in range(-len(self.base), len(self.base)): for j in range(-len(self.base), len(self.base)): for step in [-1, 1]: replacement = range(0, len(self.base[i:j:step])) self.base[i:j:step] = replacement self.lazy[i:j:step] = replacement self.assertEqual(self.lazy, self.base) def test_delslice(self): del self.base[0:1] del self.lazy[0:1] self.assertEqual(self.lazy, self.base) del self.base[-1:1:-1] del self.lazy[-1:1:-1] self.assertEqual(self.lazy, self.base)
def test_bool(self): self.assertTrue(bool(self.lazy)) self.assertFalse(bool(LazyList())) self.assertFalse(bool(LazyList(iter([]))))
class LazyListTestCase(unittest.TestCase): initial_data = [3, 2, 1] def setUp(self): self.base = [3, 2, 1] self.lesser = [2, 1, 0] self.greater = [4, 3, 2] self.lazy = LazyList(iter(list(self.base))) def test_unary_ops(self): unary_ops = [str, repr, len, bool, not_] try: unary_ops.append(unicode) except NameError: pass # unicode no longer exists in Python 3. for op in unary_ops: self.assertEqual(op(self.lazy), op(self.base), str(op)) def test_binary_ops(self): binary_ops = [eq, ge, gt, le, lt, ne, add, concat] try: binary_ops.append(cmp) except NameError: pass # cmp no longer exists in Python 3. for op in binary_ops: self.assertEqual(op(self.lazy, self.lazy), op(self.base, self.base), str(op)) for other in [self.base, self.lesser, self.greater]: self.assertEqual(op(self.lazy, other), op(self.base, other), '%s %s' % (op, other)) self.assertEqual(op(other, self.lazy), op(other, self.base), '%s %s' % (op, other)) # Multiplication self.assertEqual(self.lazy * 3, self.base * 3) self.assertEqual(3 * self.lazy, 3 * self.base) # Contains self.assertTrue(2 in self.lazy) self.assertFalse(42 in self.lazy) def test_iadd(self): self.lazy += [1] self.base += [1] self.assertEqual(self.lazy, self.base) def test_bool(self): self.assertTrue(bool(self.lazy)) self.assertFalse(bool(LazyList())) self.assertFalse(bool(LazyList(iter([])))) def test_hash(self): self.assertRaises(TypeError, hash, self.lazy) def test_isinstance(self): self.assertTrue(isinstance(self.lazy, list)) self.assertFalse(isinstance(self.lazy, tuple)) def test_callable(self): try: callable except NameError: return # No longer exists with Python 3. self.assertFalse(callable(self.lazy)) def test_append(self): self.base.append('extra') self.lazy.append('extra') self.assertEqual(self.lazy, self.base) def test_count(self): self.assertEqual(self.lazy.count(2), 1) def test_index(self): self.assertEqual(self.lazy.index(2), 1) def test_extend(self): self.base.extend([6, 7]) self.lazy.extend([6, 7]) self.assertEqual(self.lazy, self.base) def test_insert(self): self.base.insert(0, 'ping') self.lazy.insert(0, 'ping') self.assertEqual(self.lazy, self.base) def test_pop(self): self.assertEqual(self.lazy.pop(), self.base.pop()) self.assertEqual(self.lazy, self.base) def test_remove(self): self.base.remove(2) self.lazy.remove(2) self.assertEqual(self.lazy, self.base) def test_reverse(self): self.base.reverse() self.lazy.reverse() self.assertEqual(self.lazy, self.base) def test_reversed(self): self.assertEqual(list(reversed(self.lazy)), list(reversed(self.base))) def test_sort(self): self.base.sort() self.assertNotEqual(self.lazy, self.base, 'Test data already sorted') self.lazy.sort() self.assertEqual(self.lazy, self.base) def test_sorted(self): self.assertEqual(sorted(self.lazy), sorted(self.base)) def test_getitem(self): for idx in range(-len(self.base), len(self.base)): self.assertEqual(self.lazy[idx], self.base[idx]) def test_setitem(self): for idx in range(-len(self.base), len(self.base)): self.base[idx] = idx + 1000 self.assertNotEqual(self.lazy, self.base) self.lazy[idx] = idx + 1000 self.assertEqual(self.lazy, self.base) def test_delitem(self): del self.base[0] self.assertNotEqual(self.lazy, self.base) del self.lazy[0] self.assertEqual(self.lazy, self.base) del self.base[-2] self.assertNotEqual(self.lazy, self.base) del self.lazy[-2] self.assertEqual(self.lazy, self.base) def test_iter(self): self.assertEqual(list(iter(self.lazy)), list(iter(self.base))) def test_getslice(self): for i in range(-len(self.base), len(self.base)): for j in range(-len(self.base), len(self.base)): for step in [-1, 1]: self.assertEqual(self.lazy[i:j:step], self.base[i:j:step]) def test_setslice(self): for i in range(-len(self.base), len(self.base)): for j in range(-len(self.base), len(self.base)): for step in [-1, 1]: replacement = range(0, len(self.base[i:j:step])) self.base[i:j:step] = replacement self.lazy[i:j:step] = replacement self.assertEqual(self.lazy, self.base) def test_delslice(self): del self.base[0:1] del self.lazy[0:1] self.assertEqual(self.lazy, self.base) del self.base[-1:1:-1] del self.lazy[-1:1:-1] self.assertEqual(self.lazy, self.base)
continue pieces = line.rstrip().split(None, 3) code, coordinates, zone = pieces[:3] comment = len(pieces) == 4 and pieces[3] or '' if zone not in all_timezones_set: continue coordinates = _parse_iso6709(coordinates) if not coordinates: continue lat, lon = coordinates yield zonetype(code, (lat, lon), zone, comment) zone_tab = LazyList(_zone_tab()) def _parse_iso6709(iso6709): match = re.match('^([-+][0-9]+)([-+][0-9]+)$', iso6709) if not match: return return map(_parse_iso6709_coord, match.groups()) def _parse_iso6709_coord(coord): if len(coord) % 2: deg = float(coord[:3]) coord = coord[3:] else: deg = float(coord[:4])