Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/allpy/file/8b25fa9734c0/allpy/util.py
Дата изменения: Unknown
Дата индексирования: Sun Feb 3 20:41:55 2013
Кодировка:
allpy: 8b25fa9734c0 allpy/util.py

allpy

view allpy/util.py @ 837:8b25fa9734c0

Added allpy.utils.lazy_import: a helper to break import loops less pervasively
author Daniil Alexeyevsky <dendik@kodomo.fbb.msu.ru>
date Tue, 19 Jul 2011 19:39:59 +0400
parents 7de42d758354
children 88b04c08f539
line source
1 """Miscellanous utilities.
2 """
3 import warnings
5 def unzip(seq):
6 """The oppozite of zip() builtin."""
7 a, b = [], []
8 for x, y in seq:
9 a.append(x)
10 b.append(y)
11 return a, b
13 def remove_each(string, substrings):
14 """Remove each of substrings from string."""
15 for sub in substrings:
16 string = string.replace(sub, "")
17 return string
19 class UserDict(dict):
20 """Clone of dict that user may add attributes to."""
21 pass
23 class UserList(list):
24 """Clone of list that user may add attributes to."""
25 pass
27 class UserString(str):
28 """Clone of str that user may add attributes to."""
29 pass
31 def deprecated(message):
32 """Warn about function being deprecated."""
33 warnings.warn(message, DeprecationWarning, stacklevel=2)
35 class lazy_import(object):
36 """Lazy module import to help breaking bad import loops."""
37 def __init__(self, name):
38 self.name = name
39 def __getattr__(self, attr):
40 self.module = __import__(self.name)
41 self.__dict__ = self.module.__dict__
43 # vim: set et ts=4 sts=4 sw=4: