import string
+class AnyData(object):
+
+ pass
+
+
_indentationLevel = [0]
@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
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
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")