13
13
from .utils import reference_to_id , unknown_reference_error_obj
14
14
15
15
16
- text_type = six .text_type
16
+ """
17
+ The classes in this module are used to transform the source
18
+ AST to a partially evaluated resolver tree. They're subclasses
19
+ to the syntax AST node, and `BaseResolver`. Syntax nodes that
20
+ don't require special handling, but have children that need to be
21
+ transformed, need to just inherit from their syntax base class and
22
+ `BaseResolver`. When adding to the module namespace here, watch
23
+ out for naming conflicts with `fluent.syntax.ast`.
17
24
18
- # Prevent expansion of too long placeables, for memory DOS protection
19
- MAX_PART_LENGTH = 2500
20
-
21
- # Prevent messages with too many sub parts, for CPI DOS protection
22
- MAX_PARTS = 1000
25
+ `ResolverEnvironment` is the `env` passed to the `__call__` method
26
+ in the resolver tree. The `CurrentEnvironment` keeps track of the
27
+ modifyable state in the resolver environment.
28
+ """
23
29
24
30
25
- # Unicode bidi isolation characters.
26
- FSI = "\u2068 "
27
- PDI = "\u2069 "
31
+ # Prevent expansion of too long placeables, for memory DOS protection
32
+ MAX_PART_LENGTH = 2500
28
33
29
34
30
35
@attr .s
@@ -95,6 +100,9 @@ class Term(FTL.Term, BaseResolver):
95
100
96
101
97
102
class Pattern (FTL .Pattern , BaseResolver ):
103
+ # Prevent messages with too many sub parts, for CPI DOS protection
104
+ MAX_PARTS = 1000
105
+
98
106
def __init__ (self , * args , ** kwargs ):
99
107
super (Pattern , self ).__init__ (* args , ** kwargs )
100
108
self .dirty = False
@@ -103,15 +111,15 @@ def __call__(self, env):
103
111
if self .dirty :
104
112
env .errors .append (FluentCyclicReferenceError ("Cyclic reference" ))
105
113
return FluentNone ()
106
- if env .part_count > MAX_PARTS :
114
+ if env .part_count > self . MAX_PARTS :
107
115
return ""
108
116
self .dirty = True
109
117
elements = self .elements
110
- remaining_parts = MAX_PARTS - env .part_count
118
+ remaining_parts = self . MAX_PARTS - env .part_count
111
119
if len (self .elements ) > remaining_parts :
112
120
elements = elements [:remaining_parts + 1 ]
113
121
env .errors .append (ValueError ("Too many parts in message (> {0}), "
114
- "aborting." .format (MAX_PARTS )))
122
+ "aborting." .format (self . MAX_PARTS )))
115
123
retval = '' .join (
116
124
resolve (element (env ), env ) for element in elements
117
125
)
@@ -213,7 +221,7 @@ def __call__(self, env):
213
221
FluentReferenceError ("Unknown external: {0}" .format (name )))
214
222
return FluentNoneResolver (name )
215
223
216
- if isinstance (arg_val , (FluentType , text_type )):
224
+ if isinstance (arg_val , (FluentType , six . text_type )):
217
225
return arg_val
218
226
env .errors .append (TypeError ("Unsupported external type: {0}, {1}"
219
227
.format (name , type (arg_val ))))
0 commit comments