#NEWLINE# def overlap( a1 , a2 , b1 , b2 ) : #NEWLINE# #INDENT# 'Test whether two value ranges overlap.\n    \n    This function is typically used with date values, but it also\n    works with integers or other comparable values.  The following\n    examples use integer values to be more readable.\n\n    Unlike the test presented at\n    <http://bytes.com/topic/python/answers/457949-determing-whether-two-ranges-overlap>,\n    this works also with "open" ranges (the open end being indicated\n    by a `None` value).\n    \n    Types of constellations::\n    \n      -   o---o  o---o\n      -   o---o  o--->\n      -   <---o  o---o\n      -   <---o  o--->\n                \n      -   o------------->\n                o---o\n                \n      -   o---o\n            o---o\n                \n      -   o---o\n            o--->\n      -   <---------o\n               o---o\n    \n\n\n    >>> overlap(1,2,3,4)\n    False\n    >>> overlap(3,4,1,2)\n    False\n    >>> overlap(1,3,2,4)\n    True\n    >>> overlap(2,4,1,3)\n    True\n    >>> overlap(1,4,2,3)\n    True\n    >>> overlap(2,3,1,4)\n    True\n    \n    \n    >>> overlap(1,None,3,4)\n    True\n    >>> overlap(3,4,1,None)\n    True\n    \n    \n    >>> overlap(1,2,3,None)\n    False\n    >>> overlap(3,None,1,2)\n    False\n    \n    >>> overlap(None,2,3,None)\n    False\n    >>> overlap(3,None,None,2)\n    False\n    \n    >>> overlap(1,3,2,None)\n    True\n    \n    Ranges that "only touch" each other are not considered overlapping:\n        \n    >>> overlap(1,2,2,3)\n    False\n    >>> overlap(2,3,1,2)\n    False\n\n    ' #NEWLINE# if a2 : #NEWLINE# #INDENT# if a1 : #NEWLINE# #INDENT# if ( b1 >= a2 ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( b2 and a1 ) : #NEWLINE# #INDENT# if ( a1 > a2 ) : #NEWLINE# #INDENT# raise ValueError ( 'Range 1 ends before it started.' ) #NEWLINE# #UNINDENT# return ( b2 > a1 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return True #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( b2 and a1 ) : #NEWLINE# #INDENT# return ( b2 >= a1 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return True #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if b2 : #NEWLINE# #INDENT# if a1 : #NEWLINE# #INDENT# return ( b2 > a1 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return True #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return True