I don't know how I forgot about dict(zip())
This commit is contained in:
parent
091dc82f1e
commit
a5924b4642
2 changed files with 5 additions and 18 deletions
|
@ -247,19 +247,6 @@ def now(timestamp=True):
|
||||||
return n.timestamp()
|
return n.timestamp()
|
||||||
return n
|
return n
|
||||||
|
|
||||||
def parallel_to_dict(keys, values):
|
|
||||||
'''
|
|
||||||
Given two parallel sequences, return a dictionary where the keys are
|
|
||||||
elements of `keys` and their values are the element of `values` with the
|
|
||||||
same index.
|
|
||||||
|
|
||||||
['test', 'toast'],
|
|
||||||
['hello', 'world']
|
|
||||||
->
|
|
||||||
{'test': 'hello', 'toast': 'world'}
|
|
||||||
'''
|
|
||||||
return {keys[index]: value for (index, value) in enumerate(values)}
|
|
||||||
|
|
||||||
def read_filebytes(filepath, range_min, range_max, chunk_size=2 ** 20):
|
def read_filebytes(filepath, range_min, range_max, chunk_size=2 ** 20):
|
||||||
'''
|
'''
|
||||||
Yield chunks of bytes from the file between the endpoints.
|
Yield chunks of bytes from the file between the endpoints.
|
||||||
|
|
|
@ -221,7 +221,7 @@ class Album(ObjectBase, GroupableMixin):
|
||||||
def __init__(self, photodb, db_row):
|
def __init__(self, photodb, db_row):
|
||||||
super().__init__(photodb)
|
super().__init__(photodb)
|
||||||
if isinstance(db_row, (list, tuple)):
|
if isinstance(db_row, (list, tuple)):
|
||||||
db_row = helpers.parallel_to_dict(constants.SQL_ALBUM_COLUMNS, db_row)
|
db_row = dict(zip(constants.SQL_ALBUM_COLUMNS, db_row))
|
||||||
self.id = db_row['id']
|
self.id = db_row['id']
|
||||||
self.title = db_row['title']
|
self.title = db_row['title']
|
||||||
self.description = db_row['description']
|
self.description = db_row['description']
|
||||||
|
@ -426,7 +426,7 @@ class Bookmark(ObjectBase):
|
||||||
def __init__(self, photodb, db_row):
|
def __init__(self, photodb, db_row):
|
||||||
super().__init__(photodb)
|
super().__init__(photodb)
|
||||||
if isinstance(db_row, (list, tuple)):
|
if isinstance(db_row, (list, tuple)):
|
||||||
db_row = helpers.parallel_to_dict(constants.SQL_BOOKMARK_COLUMNS, db_row)
|
db_row = dict(zip(constants.SQL_BOOKMARK_COLUMNS, db_row))
|
||||||
|
|
||||||
self.id = db_row['id']
|
self.id = db_row['id']
|
||||||
self.title = db_row['title']
|
self.title = db_row['title']
|
||||||
|
@ -473,7 +473,7 @@ class Photo(ObjectBase):
|
||||||
def __init__(self, photodb, db_row):
|
def __init__(self, photodb, db_row):
|
||||||
super().__init__(photodb)
|
super().__init__(photodb)
|
||||||
if isinstance(db_row, (list, tuple)):
|
if isinstance(db_row, (list, tuple)):
|
||||||
db_row = helpers.parallel_to_dict(constants.SQL_PHOTO_COLUMNS, db_row)
|
db_row = dict(zip(constants.SQL_PHOTO_COLUMNS, db_row))
|
||||||
|
|
||||||
self.real_filepath = helpers.normalize_filepath(db_row['filepath'], allowed=':\\/')
|
self.real_filepath = helpers.normalize_filepath(db_row['filepath'], allowed=':\\/')
|
||||||
self.real_path = pathclass.Path(self.real_filepath)
|
self.real_path = pathclass.Path(self.real_filepath)
|
||||||
|
@ -949,7 +949,7 @@ class Tag(ObjectBase, GroupableMixin):
|
||||||
def __init__(self, photodb, db_row):
|
def __init__(self, photodb, db_row):
|
||||||
super().__init__(photodb)
|
super().__init__(photodb)
|
||||||
if isinstance(db_row, (list, tuple)):
|
if isinstance(db_row, (list, tuple)):
|
||||||
db_row = helpers.parallel_to_dict(constants.SQL_TAG_COLUMNS, db_row)
|
db_row = dict(zip(constants.SQL_TAG_COLUMNS, db_row))
|
||||||
self.id = db_row['id']
|
self.id = db_row['id']
|
||||||
self.name = db_row['name']
|
self.name = db_row['name']
|
||||||
self.group_getter = self.photodb.get_tag
|
self.group_getter = self.photodb.get_tag
|
||||||
|
@ -1147,7 +1147,7 @@ class User(ObjectBase):
|
||||||
def __init__(self, photodb, db_row):
|
def __init__(self, photodb, db_row):
|
||||||
super().__init__(photodb)
|
super().__init__(photodb)
|
||||||
if isinstance(db_row, (list, tuple)):
|
if isinstance(db_row, (list, tuple)):
|
||||||
db_row = helpers.parallel_to_dict(constants.SQL_USER_COLUMNS, db_row)
|
db_row = dict(zip(constants.SQL_USER_COLUMNS, db_row))
|
||||||
self.id = db_row['id']
|
self.id = db_row['id']
|
||||||
self.username = db_row['username']
|
self.username = db_row['username']
|
||||||
self.created = db_row['created']
|
self.created = db_row['created']
|
||||||
|
|
Loading…
Reference in a new issue