Style
This commit is contained in:
@@ -95,7 +95,7 @@ class UserInterface (object):
|
||||
as bytes.
|
||||
'''
|
||||
if filename:
|
||||
with open(filename,'w') as f:
|
||||
with open(filename, 'w') as f:
|
||||
pickle.dump(self.relations, f)
|
||||
return None
|
||||
return pickle.dumps(self.relations)
|
||||
|
@@ -508,6 +508,7 @@ def select_union_intersect_subtract(n):
|
||||
|
||||
return changes + recoursive_scan(select_union_intersect_subtract, n)
|
||||
|
||||
|
||||
def union_and_product(n):
|
||||
'''
|
||||
A * B ∪ A * C = A * (B ∪ C)
|
||||
|
@@ -341,11 +341,12 @@ def tokenize(expression):
|
||||
expression = expression[
|
||||
par:].strip() # Removing parameter from the expression
|
||||
else: # Relation (hopefully)
|
||||
expression+=' ' #To avoid the special case of the ending
|
||||
expression += ' ' # To avoid the special case of the ending
|
||||
|
||||
#Initial part is a relation, stop when the name of the relation is over
|
||||
for r in range(1,len(expression)):
|
||||
if rtypes.RELATION_NAME_REGEXP.match(expression[:r+1]) is None:
|
||||
# Initial part is a relation, stop when the name of the relation is
|
||||
# over
|
||||
for r in range(1, len(expression)):
|
||||
if rtypes.RELATION_NAME_REGEXP.match(expression[:r + 1]) is None:
|
||||
break
|
||||
items.append(expression[:r])
|
||||
expression = expression[r:].strip()
|
||||
@@ -371,5 +372,5 @@ if __name__ == "__main__":
|
||||
e = input("Expression: ")
|
||||
print (parse(e))
|
||||
|
||||
#Backwards compatibility
|
||||
# Backwards compatibility
|
||||
node = Node
|
||||
|
@@ -64,6 +64,7 @@ class Relation (object):
|
||||
self.header = Header(next(reader)) # read 1st line
|
||||
iterator = ((self.insert(i) for i in reader))
|
||||
deque(iterator, maxlen=0)
|
||||
|
||||
def _make_duplicate(self, copy):
|
||||
'''Flag that the relation "copy" is pointing
|
||||
to the same set as this relation.'''
|
||||
@@ -393,7 +394,7 @@ class Relation (object):
|
||||
m_len = [len(i) for i in self.header] # Maximum lenght string
|
||||
|
||||
for f in self.content:
|
||||
for col,i in enumerate(f):
|
||||
for col, i in enumerate(f):
|
||||
if len(i) > m_len[col]:
|
||||
m_len[col] = len(i)
|
||||
|
||||
@@ -403,7 +404,7 @@ class Relation (object):
|
||||
|
||||
for r in self.content:
|
||||
res += "\n"
|
||||
for col,i in enumerate(r):
|
||||
for col, i in enumerate(r):
|
||||
res += "%s" % (i.ljust(2 + m_len[col]))
|
||||
|
||||
return res
|
||||
@@ -426,12 +427,14 @@ class Relation (object):
|
||||
affected = self.selection(expr)
|
||||
not_affected = self.difference(affected)
|
||||
|
||||
new_values = tuple(zip(self.header.getAttributesId(dic.keys()), dic.values()))
|
||||
new_values = tuple(
|
||||
zip(self.header.getAttributesId(dic.keys()), dic.values())
|
||||
)
|
||||
|
||||
for i in set(affected.content):
|
||||
i = list(i)
|
||||
|
||||
for column,value in new_values:
|
||||
for column, value in new_values:
|
||||
i[column] = value
|
||||
not_affected.insert(i)
|
||||
|
||||
@@ -530,6 +533,6 @@ class Header(tuple):
|
||||
'''Returns a list with numeric index corresponding to field's name'''
|
||||
return [self.index(i) for i in param]
|
||||
|
||||
#Backwards compatibility
|
||||
# Backwards compatibility
|
||||
relation = Relation
|
||||
header = Header
|
||||
|
@@ -32,7 +32,9 @@ class Rstring (str):
|
||||
|
||||
int_regexp = re.compile(r'^[\+\-]{0,1}[0-9]+$')
|
||||
float_regexp = re.compile(r'^[\+\-]{0,1}[0-9]+(\.([0-9])+)?$')
|
||||
date_regexp = re.compile(r'^([0-9]{1,4})(\\|-|/)([0-9]{1,2})(\\|-|/)([0-9]{1,2})$')
|
||||
date_regexp = re.compile(
|
||||
r'^([0-9]{1,4})(\\|-|/)([0-9]{1,2})(\\|-|/)([0-9]{1,2})$'
|
||||
)
|
||||
|
||||
def autocast(self):
|
||||
'''
|
||||
@@ -155,11 +157,12 @@ class Rdate (object):
|
||||
def __sub__(self, other):
|
||||
return (self.intdate - other.intdate).days
|
||||
|
||||
|
||||
def is_valid_relation_name(name):
|
||||
'''Checks if a name is valid for a relation.
|
||||
Returns boolean'''
|
||||
return re.match(RELATION_NAME_REGEXP, name) != None
|
||||
|
||||
#Backwards compatibility
|
||||
# Backwards compatibility
|
||||
rdate = Rdate
|
||||
rstring = Rstring
|
||||
|
Reference in New Issue
Block a user