fnp
/
librarian.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Drop lots of legacy code. Support Python 3.7-3.11.
[librarian.git]
/
src
/
librarian
/
dcparser.py
diff --git
a/src/librarian/dcparser.py
b/src/librarian/dcparser.py
index
f402c04
..
1d3c2f3
100644
(file)
--- a/
src/librarian/dcparser.py
+++ b/
src/librarian/dcparser.py
@@
-1,11
+1,11
@@
# This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
# This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
-# Copyright © Fundacja
Nowoczesna Polska
. See NOTICE for more information.
+# Copyright © Fundacja
Wolne Lektury
. See NOTICE for more information.
#
from xml.parsers.expat import ExpatError
from datetime import date
#
from xml.parsers.expat import ExpatError
from datetime import date
+import io
import time
import re
import time
import re
-import six
from librarian.util import roman_to_int
from librarian import (ValidationError, NoDublinCore, ParseError, DCNS, RDFNS,
from librarian.util import roman_to_int
from librarian import (ValidationError, NoDublinCore, ParseError, DCNS, RDFNS,
@@
-15,14
+15,13
@@
import lxml.etree as etree
from lxml.etree import XMLSyntaxError
from librarian.meta.types.bool import BoolValue
from lxml.etree import XMLSyntaxError
from librarian.meta.types.bool import BoolValue
-from librarian.meta.types.date import DateValue
from librarian.meta.types.person import Person
from librarian.meta.types.wluri import WLURI
from librarian.meta.types.person import Person
from librarian.meta.types.wluri import WLURI
-from librarian.meta.types
.text import TextValue
+from librarian.meta.types
import text
-class Field
(object)
:
- def __init__(self, uri, attr_name, value_type=TextValue,
+class Field:
+ def __init__(self, uri, attr_name, value_type=
text.
TextValue,
multiple=False, salias=None, **kwargs):
self.uri = uri
self.name = attr_name
multiple=False, salias=None, **kwargs):
self.uri = uri
self.name = attr_name
@@
-104,7
+103,7
@@
class DCInfo(type):
return super(DCInfo, mcs).__new__(mcs, classname, bases, class_dict)
return super(DCInfo, mcs).__new__(mcs, classname, bases, class_dict)
-class WorkInfo(
six.with_metaclass(DCInfo, object)
):
+class WorkInfo(
metaclass=DCInfo
):
FIELDS = (
Field(DCNS('creator'), 'authors', Person, salias='author',
multiple=True),
FIELDS = (
Field(DCNS('creator'), 'authors', Person, salias='author',
multiple=True),
@@
-121,7
+120,7
@@
class WorkInfo(six.with_metaclass(DCInfo, object)):
Field(DCNS('contributor.thanks'), 'thanks', required=False),
Field(DCNS('date'), 'created_at'),
Field(DCNS('contributor.thanks'), 'thanks', required=False),
Field(DCNS('date'), 'created_at'),
- Field(DCNS('date.pd'), 'released_to_public_domain_at',
DateValue,
+ Field(DCNS('date.pd'), 'released_to_public_domain_at',
required=False),
Field(DCNS('publisher'), 'publisher', multiple=True),
required=False),
Field(DCNS('publisher'), 'publisher', multiple=True),
@@
-151,7
+150,7
@@
class WorkInfo(six.with_metaclass(DCInfo, object)):
@classmethod
def from_bytes(cls, xml, *args, **kwargs):
@classmethod
def from_bytes(cls, xml, *args, **kwargs):
- return cls.from_file(
six
.BytesIO(xml), *args, **kwargs)
+ return cls.from_file(
io
.BytesIO(xml), *args, **kwargs)
@classmethod
def from_file(cls, xmlfile, *args, **kwargs):
@classmethod
def from_file(cls, xmlfile, *args, **kwargs):
@@
-237,7
+236,6
@@
class WorkInfo(six.with_metaclass(DCInfo, object)):
for field in self.FIELDS:
value = field.validate(dc_fields, fallbacks=fallbacks,
strict=strict, validate_required=validate_required)
for field in self.FIELDS:
value = field.validate(dc_fields, fallbacks=fallbacks,
strict=strict, validate_required=validate_required)
- print(field.name, value)
setattr(self, 'prop_' + field.name, value)
self.fmap[field.name] = field
if field.salias:
setattr(self, 'prop_' + field.name, value)
self.fmap[field.name] = field
if field.salias:
@@
-303,11
+301,11
@@
class WorkInfo(six.with_metaclass(DCInfo, object)):
for x in v:
e = etree.Element(field.uri)
if x is not None:
for x in v:
e = etree.Element(field.uri)
if x is not None:
- e.text = s
ix.text_type
(x)
+ e.text = s
tr
(x)
description.append(e)
else:
e = etree.Element(field.uri)
description.append(e)
else:
e = etree.Element(field.uri)
- e.text = s
ix.text_type
(v)
+ e.text = s
tr
(v)
description.append(e)
return root
description.append(e)
return root
@@
-322,9
+320,9
@@
class WorkInfo(six.with_metaclass(DCInfo, object)):
if field.multiple:
if len(v) == 0:
continue
if field.multiple:
if len(v) == 0:
continue
- v = [s
ix.text_type
(x) for x in v if x is not None]
+ v = [s
tr
(x) for x in v if x is not None]
else:
else:
- v = s
ix.text_type
(v)
+ v = s
tr
(v)
dc[field.name] = {'uri': field.uri, 'value': v}
rdf['fields'] = dc
dc[field.name] = {'uri': field.uri, 'value': v}
rdf['fields'] = dc
@@
-339,32
+337,32
@@
class WorkInfo(six.with_metaclass(DCInfo, object)):
if field.multiple:
if len(v) == 0:
continue
if field.multiple:
if len(v) == 0:
continue
- v = [s
ix.text_type
(x) for x in v if x is not None]
+ v = [s
tr
(x) for x in v if x is not None]
else:
else:
- v = s
ix.text_type
(v)
+ v = s
tr
(v)
result[field.name] = v
if field.salias:
v = getattr(self, field.salias)
if v is not None:
result[field.name] = v
if field.salias:
v = getattr(self, field.salias)
if v is not None:
- result[field.salias] = s
ix.text_type
(v)
+ result[field.salias] = s
tr
(v)
return result
class BookInfo(WorkInfo):
FIELDS = (
return result
class BookInfo(WorkInfo):
FIELDS = (
- Field(DCNS('audience'), 'audiences', salias='audience', multiple=True,
+ Field(DCNS('audience'), 'audiences',
text.Audience,
salias='audience', multiple=True,
required=False),
required=False),
- Field(DCNS('subject.period'), 'epochs', salias='epoch', multiple=True,
+ Field(DCNS('subject.period'), 'epochs',
text.Epoch,
salias='epoch', multiple=True,
required=False),
required=False),
- Field(DCNS('subject.type'), 'kinds', salias='kind', multiple=True,
+ Field(DCNS('subject.type'), 'kinds',
text.Kind,
salias='kind', multiple=True,
required=False),
required=False),
- Field(DCNS('subject.genre'), 'genres', salias='genre', multiple=True,
+ Field(DCNS('subject.genre'), 'genres',
text.Genre,
salias='genre', multiple=True,
required=False),
required=False),
- Field(WLNS('category.legimi'), 'legimi', required=False),
-
+ Field(WLNS('category.legimi'), 'legimi',
text.LegimiCategory,
required=False),
+ Field(WLNS('category.thema'), 'thema', text.ThemaCategory, required=False, multiple=True),
Field(DCNS('subject.location'), 'location', required=False),
Field(DCNS('contributor.translator'), 'translators',
Field(DCNS('subject.location'), 'location', required=False),
Field(DCNS('contributor.translator'), 'translators',