fix import_from_path, add bytes mode to Path.read, and add clear_table to database.session

This commit is contained in:
Izalia Mae 2021-07-15 22:49:28 -04:00
parent 2bc9fd9745
commit 65a513916b
3 changed files with 8 additions and 4 deletions

View file

@ -163,8 +163,8 @@ def import_from_path(mod_path):
mod_path = Path(mod_path) mod_path = Path(mod_path)
if mod_path.isdir: if mod_path.is_dir():
path = mod_path.join('__init__.py') path = mod_path.joinpath('__init__.py')
name = path.name name = path.name
else: else:

View file

@ -119,9 +119,9 @@ class Path(str):
return open(self, *args, **kwargs) return open(self, *args, **kwargs)
def read(self): def read(self, byte=False):
fd = open(self) fd = open(self)
data = fd.read() data = fd.read('rb' if byte else 'r')
fd.close() fd.close()
return data return data

View file

@ -323,6 +323,10 @@ class SqlSession(object):
self.execute(f'ALTER TABLE {tbl}_temp RENAME TO {tbl}') self.execute(f'ALTER TABLE {tbl}_temp RENAME TO {tbl}')
def clear_table(self, table):
self.execute(f'DELETE FROM {table}')
class CustomRows(object): class CustomRows(object):
def get(self, name): def get(self, name):
return getattr(self, name, self.Row) return getattr(self, name, self.Row)