diff --git a/backends/file.py b/backends/file.py index b19bbfc..ff45c42 100644 --- a/backends/file.py +++ b/backends/file.py @@ -15,7 +15,7 @@ def _load(name,pos,file,obj): for line in linegen(file): split=line.split(',') if split[pos]==name: return obj(*split) - raise Exception('No such',obj.__name__,'with identifier',name) + raise Exception(f'No such {obj.__name__} with identifier {name}') def _load_multi(name,pos,file,obj): out=[] for line in linegen(file): @@ -62,7 +62,7 @@ def delete_invite(token): def linegen(path): i=0 file=open(path) - line=file.readline() + line=file.readline().rstrip('\n') # Maybe sometimes there won't be one. while line: i+=1 response=yield line @@ -91,7 +91,7 @@ def writefile(path,action,post=None): while line: i+=1 action(write,i,line) - line=file.readline() + line=file.readline().rstrip('\n') if post is not None: post(write) file.close() write.close() diff --git a/models.py b/models.py index f64ca8b..92f2c36 100644 --- a/models.py +++ b/models.py @@ -24,12 +24,15 @@ class Token(): self.owner=owner def revoke(self): backend.delete_token(self) + @property + def serialise(self): + return ','.join([self.value,self.owner]) @dataclass class InviteToken(Token): _uses: int=0 _max_uses: int=-1 - _expires: datetime=None + expires: datetime=None def __init__(self,*args,**kwargs): return super().__init__(*args,**kwargs) @property @@ -44,6 +47,9 @@ class InviteToken(Token): def max_uses(self,val): if -1