Merge pull request #28 from ltworf/compatibility

Remove backwards compatibility stuff
master
Salvo 'LtWorf' Tomaselli 2020-08-13 14:31:20 +07:00 committed by GitHub
commit b6f902c5a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 22 deletions

@ -1,6 +1,6 @@
#!/usr/bin/env python3
# Relational
# Copyright (C) 2010-2017 Salvo "LtWorf" Tomaselli
# Copyright (C) 2010-2020 Salvo "LtWorf" Tomaselli
#
# Relational is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -57,7 +57,7 @@ def load_relations():
print ("Loading relation %s with name %s..." % (i, relname))
rels[relname] = relation.relation('%s%s' % (examples_path, i))
rels[relname] = relation.Relation('%s%s' % (examples_path, i))
print('done')
@ -238,7 +238,7 @@ def run_test(testname):
o_result = None
try:
result_rel = relation.relation('%s%s.result' % (tests_path, testname))
result_rel = relation.Relation('%s%s.result' % (tests_path, testname))
query = readfile('%s%s.query' % (tests_path, testname)).strip()
o_query = optimizer.optimize_all(query, rels)

@ -29,6 +29,32 @@ from dataclasses import dataclass
from relational import rtypes
__all__ = [
'PRODUCT',
'DIFFERENCE',
'UNION',
'INTERSECTION',
'DIVISION',
'JOIN',
'JOIN_LEFT',
'JOIN_RIGHT',
'JOIN_FULL',
'PROJECTION',
'SELECTION',
'RENAME',
'ARROW',
'TokenizerException',
'ParserException',
'CallableString',
'Node',
'Unary',
'Binary',
'Variable',
'tree',
'parse',
]
PRODUCT = '*'
DIFFERENCE = '-'
UNION = ''

@ -1,5 +1,5 @@
# Relational
# Copyright (C) 2008-2018 Salvo "LtWorf" Tomaselli
# Copyright (C) 2008-2020 Salvo "LtWorf" Tomaselli
#
# Relational is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -28,6 +28,12 @@ from pathlib import Path
from relational.rtypes import *
__all__ = [
'Relation',
'Header',
]
class Relation:
'''
@ -336,7 +342,7 @@ class Relation:
added = True
# If it didn't partecipate, adds it
if not added:
item = chain(i, repeat(rstring('---'), len(noid)))
item = chain(i, repeat(Rstring('---'), len(noid)))
newt.content.add(tuple(item))
return newt
@ -468,7 +474,7 @@ class Relation:
self._make_writable()
prevlen = len(self.content)
self.content.add(tuple(map(rstring, values)))
self.content.add(tuple(map(Rstring, values)))
return len(self.content) - prevlen
def delete(self, expr: str) -> int:
@ -541,7 +547,3 @@ class Header(tuple):
return [self.index(i) for i in param]
except ValueError as e:
raise Exception('One of the fields is not in the relation: %s' % ','.join(param))
# Backwards compatibility
relation = Relation
header = Header

@ -1,5 +1,5 @@
# Relational
# Copyright (C) 2008-2017 Salvo "LtWorf" Tomaselli
# Copyright (C) 2008-2020 Salvo "LtWorf" Tomaselli
#
# Relation is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -55,7 +55,7 @@ class Rstring(str):
elif self.isFloat():
self._autocast = float(self)
elif self.isDate():
self._autocast = rdate(self)
self._autocast = Rdate(self)
return self._autocast
def isInt(self) -> bool:
@ -119,8 +119,8 @@ class Rdate (object):
def __init__(self, date):
'''date: A string representing a date'''
if not isinstance(date, rstring):
date = rstring(date)
if not isinstance(date, Rstring):
date = Rstring(date)
self.intdate = date.getDate()
self.day = self.intdate.day
@ -136,7 +136,7 @@ class Rdate (object):
def __add__(self, days):
res = self.intdate + datetime.timedelta(days)
return rdate(res.__str__())
return Rdate(res.__str__())
def __eq__(self, other):
return self.intdate == other.intdate
@ -164,8 +164,3 @@ def is_valid_relation_name(name: str) -> bool:
'''Checks if a name is valid for a relation.
Returns boolean'''
return re.match(RELATION_NAME_REGEXP, name) != None and not keyword.iskeyword(name)
# Backwards compatibility
rdate = Rdate
rstring = Rstring

@ -1,5 +1,5 @@
# Relational
# Copyright (C) 2010-2017 Salvo "LtWorf" Tomaselli
# Copyright (C) 2010-2020 Salvo "LtWorf" Tomaselli
#
# Relational is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -137,7 +137,7 @@ def load_relation(filename: str, defname:Optional[str]=None) -> Optional[str]:
"%s is not a valid relation name" % defname, ERROR_COLOR), file=sys.stderr)
return None
try:
relations[defname] = relation.relation(filename)
relations[defname] = relation.Relation(filename)
completer.add_completion(defname)
printtty(colorize("Loaded relation %s" % defname, COLOR_GREEN))