예제 #1
0
파일: Manager.py 프로젝트: Tapyr/tapyr
 def check_kind (self, kind, obj, attr_dict = {}) :
     errors   = self.errors   [kind] = []
     warnings = self.warnings [kind] = []
     attrs    = set (attr_dict)
     if attr_dict :
         check_pred_p = lambda pred : attrs.intersection (pred.attrs)
         get_attr_val = lambda attr : attr_dict.get (attr.name)
     else :
         check_pred_p = lambda pred : True
         get_attr_val = lambda attr : obj.raw_attr (attr.name)
     for rank in dusplit (self.pred_kind [kind], lambda p : p.rank) :
         for p in rank  :
             if check_pred_p (p) :
                 result = p.check_predicate (obj, attr_dict)
                 if not result :
                     if result.severe :
                         errors.append   (result.error)
                     else :
                         warnings.append (result.error)
         if errors :
             break
     if kind == "object" :
         for attr in self.syntax_checks :
             try :
                 value = get_attr_val (attr)
                 if value :
                     attr.check_syntax (obj, value)
             except MOM.Error.Attribute_Syntax as exc :
                 errors.append (exc)
     return MOM.Pred.Err_and_Warn_List (errors, warnings)
예제 #2
0
 def check_kind(self, kind, obj, attr_dict={}):
     errors = self.errors[kind] = []
     warnings = self.warnings[kind] = []
     attrs = set(attr_dict)
     if attr_dict:
         check_pred_p = lambda pred: attrs.intersection(pred.attrs)
         get_attr_val = lambda attr: attr_dict.get(attr.name)
     else:
         check_pred_p = lambda pred: True
         get_attr_val = lambda attr: obj.raw_attr(attr.name)
     for rank in dusplit(self.pred_kind[kind], lambda p: p.rank):
         for p in rank:
             if check_pred_p(p):
                 result = p.check_predicate(obj, attr_dict)
                 if not result:
                     if result.severe:
                         errors.append(result.error)
                     else:
                         warnings.append(result.error)
         if errors:
             break
     if kind == "object":
         for attr in self.syntax_checks:
             try:
                 value = get_attr_val(attr)
                 if value:
                     attr.check_syntax(obj, value)
             except MOM.Error.Attribute_Syntax as exc:
                 errors.append(exc)
     return MOM.Pred.Err_and_Warn_List(errors, warnings)
예제 #3
0
파일: options.py 프로젝트: Tapyr/tapyr
def split (argv) :
    try :
        eoo = argv.index ("--")
    except ValueError :
        args, opts = dusplit (argv, lambda x : x.startswith ("-"), 2)
    else :
        opts = argv [:eoo]
        args = argv [eoo + 1:]
    return opts, args
예제 #4
0
def split(argv):
    try:
        eoo = argv.index("--")
    except ValueError:
        args, opts = dusplit(argv, lambda x: x.startswith("-"), 2)
    else:
        opts = argv[:eoo]
        args = argv[eoo + 1:]
    return opts, args
예제 #5
0
파일: Error.py 프로젝트: JPilarr/tapyr
 def finish(self):
     if self._wrapped_errors is None:
         ### keep only those error instances that are lowest-rank for
         ### each and every of their `attributes`
         raw_errors = self._raw_errors
         arm = defaultdict_rank()
         for e in raw_errors:
             try:
                 attrs = e.attributes
             except AttributeError:
                 pass
             else:
                 for a in attrs:
                     arm[a] = min(e.rank, arm[a])
                 e.__keep = all((arm[a] == e.rank) for a in attrs)
         errors = dusplit(raw_errors, Q.__keep)[-1]
         ### wrap the filtered error instances
         entity = self.entity
         wrapped_errors = self._wrapped_errors = sorted \
             ( (Wrapper (entity, error) for error in uniq (errors))
             , key = Q.po_index
             )
         for i, w in enumerate(wrapped_errors):
             w.index = i
예제 #6
0
파일: Error.py 프로젝트: Tapyr/tapyr
 def finish (self) :
     if self._wrapped_errors is None :
         ### keep only those error instances that are lowest-rank for
         ### each and every of their `attributes`
         raw_errors = self._raw_errors
         arm = defaultdict_rank ()
         for e in raw_errors :
             try :
                 attrs = e.attributes
             except AttributeError :
                 pass
             else :
                 for a in attrs :
                     arm [a] = min (e.rank, arm [a])
                 e.__keep = all ((arm [a] == e.rank) for a in attrs)
         errors = dusplit (raw_errors, Q.__keep) [-1]
         ### wrap the filtered error instances
         entity = self.entity
         wrapped_errors = self._wrapped_errors = sorted \
             ( (Wrapper (entity, error) for error in uniq (errors))
             , key = Q.po_index
             )
         for i, w in enumerate (wrapped_errors) :
             w.index = i