Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 5
0
Archivo: I18N.py Proyecto: 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 10
0
def _cook_F(value):
    return float(TFL.r_eval(value))
Ejemplo n.º 11
0
 def _eval(self, tokval):
     return TFL.r_eval(tokval).strip()
Ejemplo n.º 12
0
def load_entries (file_name) :
    with open (file_name) as f :
         return TFL.r_eval (f.read (), ** eval_scope ())
Ejemplo n.º 13
0
def load_entries(file_name):
    with open(file_name) as f:
        return TFL.r_eval(f.read(), **eval_scope())
Ejemplo n.º 14
0
 def _eval (self, tokval) :
     return TFL.r_eval (tokval).strip ()
Ejemplo n.º 15
0
def _cook_F (value) :
    return float (TFL.r_eval (value))