5
5
import logging
6
6
import re
7
7
from typing import Any , AnyStr , Dict , List , Text , Union
8
+ import six
8
9
from six import u
9
10
10
11
from . import sandboxjs
@@ -21,21 +22,21 @@ def jshead(engineConfig, rootvars):
21
22
# to str in `rootvars` dict.
22
23
# TODO: need to make sure the `rootvars dict`
23
24
# contains no bytes type in the first place.
24
- rootvars = bytes2str_in_dicts (rootvars )
25
+ if six .PY3 :
26
+ rootvars = bytes2str_in_dicts (rootvars ) # type -> ignore
25
27
26
28
return u"\n " .join (engineConfig + [u"var %s = %s;" % (k , json .dumps (v , indent = 4 )) for k , v in rootvars .items ()])
27
29
28
30
29
- # all these raw strings are decoded to unicode
30
- # object due to the __future__ import
31
+ # decode all raw strings to unicode
31
32
seg_symbol = r"""\w+"""
32
33
seg_single = r"""\['([^']|\\')+'\]"""
33
34
seg_double = r"""\["([^"]|\\")+"\]"""
34
35
seg_index = r"""\[[0-9]+\]"""
35
36
segments = r"(\.%s|%s|%s|%s)" % (seg_symbol , seg_single , seg_double , seg_index )
36
- segment_re = re .compile (segments , flags = re .UNICODE )
37
+ segment_re = re .compile (u ( segments ) , flags = re .UNICODE )
37
38
param_str = r"\((%s)%s*\)$" % (seg_symbol , segments )
38
- param_re = re .compile (param_str , flags = re .UNICODE )
39
+ param_re = re .compile (u ( param_str ) , flags = re .UNICODE )
39
40
40
41
JSON = Union [Dict [Any , Any ], List [Any ], Text , int , float , bool , None ]
41
42
@@ -119,7 +120,7 @@ def scanner(scan): # type: (Text) -> List[int]
119
120
return None
120
121
121
122
122
- def next_seg (remain , obj ): # type: (str , Any) -> Any
123
+ def next_seg (remain , obj ): # type: (Text , Any) -> Any
123
124
if remain :
124
125
m = segment_re .match (remain )
125
126
key = None # type: Union[Text, int]
@@ -153,7 +154,7 @@ def next_seg(remain, obj): # type: (str, Any) -> Any
153
154
154
155
155
156
def evaluator (ex , jslib , obj , fullJS = False , timeout = None , debug = False ):
156
- # type: (str , Text, Dict[Text, Any], bool, int, bool) -> JSON
157
+ # type: (Text , Text, Dict[Text, Any], bool, int, bool) -> JSON
157
158
m = param_re .match (ex )
158
159
if m :
159
160
if m .end (1 )+ 1 == len (ex ) and m .group (1 ) == "null" :
0 commit comments