Skip to content
Snippets Groups Projects
Commit 5e721d8e authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

cleanup

parent 6dd302b5
No related merge requests found
......@@ -35,6 +35,23 @@ class Range(object):
return Range(self.start + x, self.stop + x, self.left_inc,
self.right_inc)
def __fromslice(self, rs):
start = float('-inf') if rs.start is None else rs.start
stop = float('+inf') if rs.stop is not None else rs.stop
return start, stop, not math.isinf(start), not math.isinf(stop)
def __fromrange(self, rs):
return rs.start, rs.stop, rs.left_inc, rs.right_inc
def __fromstr(self, rs):
if rs[0] not in '<(': raise ValueError(
'Must start with ( or <')
if rs[-1] not in '>)': raise ValueError('Must end with ) or >')
if ';' not in rs: raise ValueError('Separator ; required')
start, stop = rs[1:-1].split(';')
return float(start), float(stop), rs[0] == '<', rs[-1] == '>'
def __init__(self, *args):
"""
Create like:
......@@ -49,23 +66,14 @@ class Range(object):
if len(args) == 1:
rs, = args
if isinstance(rs, type(self)):
args = rs.start, rs.stop, rs.left_inc, rs.right_inc
args = self.__fromrange(rs)
elif isinstance(rs, slice):
start = rs.start if rs.start is not None else float('-inf')
stop = rs.stop if rs.stop is not None else float('+inf')
args = start, stop, not math.isinf(start), not math.isinf(stop)
args = self.__fromslice(rs)
else:
if rs[0] not in '<(': raise ValueError(
'Must start with ( or <')
if rs[-1] not in '>)': raise ValueError('Must end with ) or >')
if ';' not in rs: raise ValueError('Separator ; required')
start, stop = rs[1:-1].split(';')
args = float(start), float(stop), rs[0] == '<', rs[-1] == '>'
args = self.__fromstr(rs)
elif len(args) == 2:
args = args[0], args[1], not math.isinf(args[0]), not math.isinf(
args[1])
args = args[0], args[1], not math.isinf(args[0]), not math.isinf(args[1])
q = lambda a, b, args: args[a] and math.isinf(args[b])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment