forked from django-cms/django-classy-tags
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exceptions.py
63 lines (42 loc) · 1.92 KB
/
exceptions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from django.template import TemplateSyntaxError
__all__ = ['ArgumentRequiredError', 'InvalidFlag', 'BreakpointExpected',
'TooManyArguments']
class BaseError(TemplateSyntaxError):
template = ''
def __str__(self): # pragma: no cover
return self.template % self.__dict__
class ArgumentRequiredError(BaseError):
template = "The tag '%(tagname)s' requires the '%(argname)s' argument."
def __init__(self, argument, tagname):
self.argument = argument
self.tagname = tagname
self.argname = self.argument.name
class InvalidFlag(BaseError):
template = ("The flag '%(argname)s' for the tag '%(tagname)s' must be one "
"of %(allowed_values)s, but got '%(actual_value)s'")
def __init__(self, argname, actual_value, allowed_values, tagname):
self.argname = argname
self.tagname = tagname
self.actual_value = actual_value
self.allowed_values = allowed_values
class BreakpointExpected(BaseError):
template = ("Expected one of the following breakpoints: %(breakpoints)s "
"in %(tagname)s, got '%(got)s' instead.")
def __init__(self, tagname, breakpoints, got):
self.breakpoints = ', '.join(["'%s'" % bp for bp in breakpoints])
self.tagname = tagname
self.got = got
class TrailingBreakpoint(BaseError):
template = ("Tag %(tagname)s ends in trailing breakpoint '%(breakpoint)s' without an argument following.")
def __init__(self, tagname, breakpoint):
self.tagname = tagname
self.breakpoint = breakpoint
class TooManyArguments(BaseError):
template = "The tag '%(tagname)s' got too many arguments: %(extra)s"
def __init__(self, tagname, extra):
self.tagname = tagname
self.extra = ', '.join(["'%s'" % e for e in extra])
class TemplateSyntaxWarning(Warning):
"""
Used for variable cleaning TemplateSyntaxErrors when in non-debug-mode.
"""