示例#1
0
 def extends (self) :
     env    = self.env
     pat    = self._extend_pat
     source = self.source
     if source and pat.search (source) :
         try :
             path = TFL.r_eval (pat.name.strip (), ** self.env_globals)
         except Exception :
             pass
         else :
             return self.__class__ (env, path)
示例#2
0
 def extends(self):
     env = self.env
     pat = self._extend_pat
     source = self.source
     if source and pat.search(source):
         try:
             path = TFL.r_eval(pat.name.strip(), **self.env_globals)
         except Exception:
             pass
         else:
             return self.__class__(env, path)
示例#3
0
 def _gen():
     for match in pat.search_iter(source):
         try:
             name = match.group("name").strip()
             pathes = TFL.r_eval(name, **self.env_globals)
         except Exception:
             pass
         else:
             if isinstance(pathes, pyk.string_types):
                 pathes = [pathes]
             for p in pathes:
                 yield self.__class__(env, p)
示例#4
0
 def _gen () :
     for match in pat.search_iter (source) :
         try:
             name   = match.group ("name").strip ()
             pathes = TFL.r_eval  (name, ** self.env_globals)
         except Exception :
             pass
         else :
             if isinstance (pathes, pyk.string_types) :
                 pathes = [pathes]
             for p in pathes :
                 yield self.__class__ (env, p)
示例#5
0
文件: I18N.py 项目: Tapyr/tapyr
def safe_eval (value, encoding = None) :
    if encoding and not isinstance (value, pyk.text_type) :
        try :
            value = value.decode (encoding)
        except Exception as exc :
            print (repr (value), encoding)
            raise
    try :
        result = TFL.r_eval (value)
    except SyntaxError :
        print (value)
        raise
    return result
示例#6
0
def safe_eval(value, encoding=None):
    if encoding and not isinstance(value, pyk.text_type):
        try:
            value = value.decode(encoding)
        except Exception as exc:
            print(repr(value), encoding)
            raise
    try:
        result = TFL.r_eval(value)
    except SyntaxError:
        print(value)
        raise
    return result
示例#7
0
 def _cooked_value(self, value):
     if value in ("", None):
         value = self.cooked_default
     if isinstance(value, pyk.string_types):
         try:
             cook = self.cook
             if self.type in "L" and not self.paren_pat.match(value):
                 value = "(%s)" % (value, )
             try:
                 value = cook(value)
             except ValueError:
                 ### `eval' handles expressions
                 value = cook(TFL.r_eval(value))
         except Exception as exc:
             print(exc)
             raise Cmd_Error \
                 ( "Invalid value `%s' for %s `%s' of type `%s'"
                 % (value, self.kind, self.name, self.type)
                 )
     return value
示例#8
0
 def _cooked_value (self, value) :
     if value in ("", None) :
         value = self.cooked_default
     if isinstance (value, pyk.string_types) :
         try :
             cook = self.cook
             if self.type in "L" and not self.paren_pat.match (value) :
                 value = "(%s)" % (value, )
             try :
                 value = cook (value)
             except ValueError :
                 ### `eval' handles expressions
                 value = cook (TFL.r_eval (value))
         except Exception as exc :
             print (exc)
             raise Cmd_Error \
                 ( "Invalid value `%s' for %s `%s' of type `%s'"
                 % (value, self.kind, self.name, self.type)
                 )
     return value
示例#9
0
 def _sanitized_field (self, value) :
     if isinstance (value, str) :
         if value [0] == "0" :
             value = value [1:]
         value = TFL.r_eval (value)
     return int (value)
示例#10
0
def _cook_F(value):
    return float(TFL.r_eval(value))
示例#11
0
 def _eval(self, tokval):
     return TFL.r_eval(tokval).strip()
示例#12
0
def load_entries (file_name) :
    with open (file_name) as f :
         return TFL.r_eval (f.read (), ** eval_scope ())
示例#13
0
def load_entries(file_name):
    with open(file_name) as f:
        return TFL.r_eval(f.read(), **eval_scope())
示例#14
0
 def _eval (self, tokval) :
     return TFL.r_eval (tokval).strip ()
示例#15
0
def _cook_F (value) :
    return float (TFL.r_eval (value))