mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Micro-optimize mi.set_identifiers()
This commit is contained in:
parent
2da2657345
commit
9b57e80e28
@ -42,6 +42,8 @@ NULL_VALUES = {
|
|||||||
|
|
||||||
field_metadata = FieldMetadata()
|
field_metadata = FieldMetadata()
|
||||||
|
|
||||||
|
ck = lambda typ: icu_lower(typ).strip().replace(':', '').replace(',', '')
|
||||||
|
cv = lambda val: val.strip().replace(',', '|').replace(':', '|')
|
||||||
|
|
||||||
class Metadata(object):
|
class Metadata(object):
|
||||||
|
|
||||||
@ -224,9 +226,9 @@ class Metadata(object):
|
|||||||
|
|
||||||
def _clean_identifier(self, typ, val):
|
def _clean_identifier(self, typ, val):
|
||||||
if typ:
|
if typ:
|
||||||
typ = icu_lower(typ).strip().replace(':', '').replace(',', '')
|
typ = ck(typ)
|
||||||
if val:
|
if val:
|
||||||
val = val.strip().replace(',', '|').replace(':', '|')
|
val = cv(val)
|
||||||
return typ, val
|
return typ, val
|
||||||
|
|
||||||
def set_identifiers(self, identifiers):
|
def set_identifiers(self, identifiers):
|
||||||
@ -234,11 +236,7 @@ class Metadata(object):
|
|||||||
Set all identifiers. Note that if you previously set ISBN, calling
|
Set all identifiers. Note that if you previously set ISBN, calling
|
||||||
this method will delete it.
|
this method will delete it.
|
||||||
'''
|
'''
|
||||||
cleaned = {}
|
cleaned = {ck(k):cv(v) for k, v in identifiers.iteritems() if k and v}
|
||||||
for key, val in identifiers.iteritems():
|
|
||||||
key, val = self._clean_identifier(key, val)
|
|
||||||
if key and val:
|
|
||||||
cleaned[key] = val
|
|
||||||
object.__getattribute__(self, '_data')['identifiers'] = cleaned
|
object.__getattribute__(self, '_data')['identifiers'] = cleaned
|
||||||
|
|
||||||
def set_identifier(self, typ, val):
|
def set_identifier(self, typ, val):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user