Updating from skeleton
[gc-dialer] / src / util / misc.py
index 9797c70..9b8d88c 100644 (file)
@@ -16,6 +16,11 @@ import warnings
 import string
 
 
+class AnyData(object):
+
+       pass
+
+
 _indentationLevel = [0]
 
 
@@ -644,6 +649,35 @@ def call_trace(f):
 
 
 @contextlib.contextmanager
+def nested_break():
+       """
+       >>> with nested_break() as mylabel:
+       ...     for i in xrange(3):
+       ...             print "Outer", i
+       ...             for j in xrange(3):
+       ...                     if i == 2: raise mylabel
+       ...                     if j == 2: break
+       ...                     print "Inner", j
+       ...             print "more processing"
+       Outer 0
+       Inner 0
+       Inner 1
+       Outer 1
+       Inner 0
+       Inner 1
+       Outer 2
+       """
+
+       class NestedBreakException(Exception):
+               pass
+
+       try:
+               yield NestedBreakException
+       except NestedBreakException:
+               pass
+
+
+@contextlib.contextmanager
 def lexical_scope(*args):
        """
        @note Source: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/520586
@@ -700,7 +734,7 @@ def normalize_number(prettynumber):
        elif uglynumber.startswith("1"):
                uglynumber = "+"+uglynumber
        elif 10 <= len(uglynumber):
-               assert uglynumber[0] not in ("+", "1")
+               assert uglynumber[0] not in ("+", "1"), "Number format confusing"
                uglynumber = "+1"+uglynumber
        else:
                pass
@@ -806,6 +840,16 @@ def make_pretty(phonenumber):
        return prettynumber.strip()
 
 
+def similar_ugly_numbers(lhs, rhs):
+       return (
+               lhs == rhs or
+               lhs[1:] == rhs and lhs.startswith("1") or
+               lhs[2:] == rhs and lhs.startswith("+1") or
+               lhs == rhs[1:] and rhs.startswith("1") or
+               lhs == rhs[2:] and rhs.startswith("+1")
+       )
+
+
 def abbrev_relative_date(date):
        """
        >>> abbrev_relative_date("42 hours ago")