Drop lots of legacy code. Support Python 3.7-3.11.
[librarian.git] / src / librarian / meta / types / wluri.py
index c31d391..367157f 100644 (file)
@@ -1,11 +1,13 @@
+# This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
+#
+import re
 from .base import MetaValue
 
 
 class WLURI(MetaValue):
     """Represents a WL URI. Extracts slug from it."""
-    slug = None
-
-    example = 'http://wolnelektury.pl/katalog/lektura/template/'
+    template = 'http://wolnelektury.pl/katalog/lektura/%s/'
     _re_wl_uri = re.compile(
         r'http://(www\.)?wolnelektury.pl/katalog/lektur[ay]/'
         '(?P<slug>[-a-z0-9]+)/?$'
@@ -14,16 +16,15 @@ class WLURI(MetaValue):
     def __init__(self, slug, uri=None):
         """Contructs an URI from slug.
 
-        >>> print(WLURI.from_slug('a-slug').uri)
+        >>> print(WLURI('a-slug').uri)
         http://wolnelektury.pl/katalog/lektura/a-slug/
 
         """
         if uri is None:
-            uri = 'http://wolnelektury.pl/katalog/lektura/%s/' % slug
+            uri = self.template % slug
         self.uri = uri
         return super().__init__(slug)
-        
-    
+
     @classmethod
     def from_text(cls, uri):
         slug = uri.rstrip('/').rsplit('/', 1)[-1]
@@ -34,10 +35,13 @@ class WLURI(MetaValue):
         if not match:
             raise ValidationError('Invalid URI (%s). Should match: %s' % (
                         self.uri, self._re_wl_uri.pattern))
-        return cls(uri)
 
     def __str__(self):
         return self.uri
 
     def __eq__(self, other):
-        return self.slug == other.slug
+        return self.value == other.value
+
+    @property
+    def slug(self):
+        return self.value