- language = None
-
- example = 'http://wolnelektury.pl/katalog/lektura/template/'
- _re_wl_uri = re.compile('http://wolnelektury.pl/katalog/lektura/'
- '(?P<slug>[-a-z0-9]+)(/(?P<lang>[a-z]{3}))?/?$')
-
- def __init__(self, uri=None):
- if uri is not None:
- uri = unicode(uri)
- self.uri = uri
- match = self._re_wl_uri.match(uri)
- if not match:
- raise ValueError('Supplied URI (%s) does not match '
- 'the WL document URI template.' % uri)
- self.slug = match.group('slug')
- self.language = match.group('lang') or self.DEFAULT_LANGUAGE
+
+ example = 'http://edukacjamedialna.edu.pl/'
+ _re_wl_uri = re.compile(r'http://(www\.)?edukacjamedialna.edu.pl/'
+ '(?P<slug>[-a-z0-9]+)/?$')
+
+ def __init__(self, uri):
+ uri = unicode(uri)
+ self.uri = uri
+ self.slug = uri.rstrip('/').rsplit('/', 1)[-1]
+
+ @classmethod
+ def strict(cls, uri):
+ match = cls._re_wl_uri.match(uri)
+ if not match:
+ raise ValidationError(u'Invalid URI (%s). Should match: %s' % (
+ uri, cls._re_wl_uri.pattern))
+ return cls(uri)