def descendents (self) : def _gen (self) : for c in self.children : yield c for d in c.descendents : yield d return tuple (uniq (_gen (self)))
def base_dirs (self) : result = self.__super.base_dirs opt_map = self.cmd._opt_map cdo = opt_map.get (self._config_dirs_name) if cdo and cdo.base_dirs : result = cdo.base_dirs + result return tuple (uniq (result))
def base_dirs(self): result = self.__super.base_dirs opt_map = self.cmd._opt_map cdo = opt_map.get(self._config_dirs_name) if cdo and cdo.base_dirs: result = cdo.base_dirs + result return tuple(uniq(result))
def elems(self): if self.embedder: elems = ichain((self.elem, ), self.embedder.entity_p_buddy_elems) result = tuple(uniq(elems)) else: result = self.entity_p_buddy_elems return result
def elems (self) : if self.embedder : elems = ichain ((self.elem, ), self.embedder.entity_p_buddy_elems) result = tuple (uniq (elems)) else : result = self.entity_p_buddy_elems return result
def descendents(self): def _gen(self): for c in self.children: yield c yield from c.descendents return tuple(uniq(_gen(self)))
def embedded_elems (self) : def _gen (self) : for e in self.elem.elements : c = e.completer if c is not None : yield c.embedded_elems yield (self.elem, ) return tuple (uniq (ichain (* _gen (self))))
def q_able_names (self) : result = self.attr.q_able_names if self is not self.eff : result = uniq (itertools.chain (result, self.eff.q_able_names)) prefix = self.prefix if prefix : result = (".".join ((prefix, name)) for name in result) return tuple (sorted (result))
def q_able_names(self): result = self.attr.q_able_names if self is not self.eff: result = uniq(itertools.chain(result, self.eff.q_able_names)) prefix = self.prefix if prefix: result = (".".join((prefix, name)) for name in result) return tuple(sorted(result))
def _m_create_role_children (cls) : for role in uniq (cls._role_children_to_add) : role = getattr (cls._Attributes, role) children = sorted \ ( pyk.itervalues (role.E_Type.children_np) , key = TFL.Getter.i_rank ) for c in children : cls._m_create_role_child ((role.name, c))
def _m_create_role_children(cls): for role in uniq(cls._role_children_to_add): role = getattr(cls._Attributes, role) children = sorted \ ( pyk.itervalues (role.E_Type.children_np) , key = TFL.Getter.i_rank ) for c in children: cls._m_create_role_child((role.name, c))
def embedded_elems(self): def _gen(self): for e in self.elem.elements: c = e.completer if c is not None: yield c.embedded_elems yield (self.elem, ) return tuple(uniq(ichain(*_gen(self))))
def ancestors (self) : def _gen (self) : p = self.parent if p : if p.sa_table is not None : yield p for a in p.ancestors : yield a return tuple (uniq (_gen (self)))
def entity_p_buddy_elems (self) : result = self.own_elems if self.entity_p : def _gen (self) : yield self.own_elems for e in self.anchor.elements : c = e.completer if c is not None and c.entity_p : yield c.embedded_elems result = tuple (uniq (ichain (* _gen (self)))) return result
def own_elems (self) : def _gen (self) : ep = self.elem.parent yield (self.elem, ) for n in self.attr.completer.names : elem = ep.get (n) if elem is not None : if elem.completer is not None : yield elem.completer.embedded_elems else : yield (elem, ) return tuple (uniq (ichain (* _gen (self))))
def entity_p_buddy_elems(self): result = self.own_elems if self.entity_p: def _gen(self): yield self.own_elems for e in self.anchor.elements: c = e.completer if c is not None and c.entity_p: yield c.embedded_elems result = tuple(uniq(ichain(*_gen(self)))) return result
def own_elems(self): def _gen(self): ep = self.elem.parent yield (self.elem, ) for n in self.attr.completer.names: elem = ep.get(n) if elem is not None: if elem.completer is not None: yield elem.completer.embedded_elems else: yield (elem, ) return tuple(uniq(ichain(*_gen(self))))
def dynamic_defaults (self, defaults) : def _gen_template_dirs (self, defaults) : yield self.app_dir tpds = defaults.get ("template_package_dirs", ["_JNJ"]) for tpd in tpds : mod = import_module (tpd) yield sos.path.dirname (mod.__file__) result = self.__super.dynamic_defaults (defaults) combined = dict (defaults, ** result) tdirs = list (combined.get ("template_dirs", ())) tdirs.extend (_gen_template_dirs (self, combined)) result ["template_dirs"] = tuple (uniq (tdirs)) return result
def _m_combine_lists(cls, bases, dict): for name in cls._lists_to_combine: setattr \ ( cls, name , list ( uniq ( itertools.chain ( * ( getattr (c, name, []) for c in reversed ((cls, ) + bases) ) ) ) ) )
def _m_combine_lists (cls, bases, dict) : for name in cls._lists_to_combine : setattr \ ( cls, name , list ( uniq ( itertools.chain ( * ( getattr (c, name, []) for c in reversed ((cls, ) + bases) ) ) ) ) )
def HTML \ ( version = "html/5.jnj" , load_path = () , loader = None , globals = {} , encoding = "utf-8" , i18n = False , Media_Parameters = None , GTW = None , prefixes = {} , ** kw ) : jnj_loader = FileSystemLoader (sos.path.dirname (__file__), "utf-8") loaders = [] if loader : loaders.append (loader) if load_path : loaders.append (FileSystemLoader (load_path, encoding)) loaders.append (jnj_loader) if prefixes : sk = lambda x : (- len (x [1]), x [1]) for prefix, lp in sorted (pyk.iteritems (prefixes), key = sk) : loaders.append \ ( PrefixLoader ({prefix : FileSystemLoader (lp, encoding)}, delimiter='::') ) loaders.append (PrefixLoader (dict (STD = jnj_loader), delimiter='::')) loader = ChoiceLoader (loaders) extensions = (kw.pop ("extensions", []) + Default_Extensions) if i18n : extensions.append ("jinja2.ext.i18n") result = Environment \ ( extensions = uniq (extensions), loader = loader, ** kw) if GTW is None : GTW = JNJ.GTW (result) result.globals.update \ ( globals , GTW = GTW , html_version = version ) result.Media_Parameters = Media_Parameters result.encoding = encoding result.static_handler = None if i18n : result.install_gettext_translations (TFL.I18N) return result
def _effective_prop_kind_mixins(self, name, kind, prop_type, e_type): result = self.__super._effective_prop_kind_mixins \ (name, kind, prop_type, e_type) if prop_type.needs_raw_value and not kind.electric: result += (MOM.Attr._Raw_Value_Mixin_, ) if prop_type.auto_up_depends: MI = \ ( MOM.Attr._Auto_Update_Lazy_Mixin_ if (MOM.Attr.Computed_Set_Mixin in result) else MOM.Attr._Auto_Update_Mixin_ ) result += (MI, ) if isinstance(e_type, MOM.Meta.M_E_Type_An): result = (MOM.Attr._Nested_Mixin_, ) + result if MOM.Attr.Computed_Mixin in result: result = tuple(r for r in result if r != MOM.Attr.Sticky_Mixin) result = prop_type.Kind_Mixins_X + result return tuple(uniq(result))
def _m_update_combine (cls, bases, dct) : def _gen (cls, bases, name) : undef = update_combined_many.Undef for c in reversed ((cls, ) + bases) : yield getattr (c, name, undef) for name in cls._attrs_to_update_combine : try : v = update_combined_many (* _gen (cls, bases, name)) except Exception as exc : print \ ( "*** Exception when trying to update/combined", name , "for class", cls ) raise setattr (cls, name, v) for name in cls._attrs_uniq_to_update_combine : v = update_combined_many (* _gen (cls, bases, name)) setattr (cls, name, v.__class__ (uniq (v)))
def _effective_prop_kind_mixins (self, name, kind, prop_type, e_type) : result = self.__super._effective_prop_kind_mixins \ (name, kind, prop_type, e_type) if prop_type.needs_raw_value and not kind.electric : result += (MOM.Attr._Raw_Value_Mixin_, ) if prop_type.auto_up_depends : MI = \ ( MOM.Attr._Auto_Update_Lazy_Mixin_ if (MOM.Attr.Computed_Set_Mixin in result) else MOM.Attr._Auto_Update_Mixin_ ) result += (MI, ) if isinstance (e_type, MOM.Meta.M_E_Type_An) : result = (MOM.Attr._Nested_Mixin_, ) + result if MOM.Attr.Computed_Mixin in result : result = tuple (r for r in result if r != MOM.Attr.Sticky_Mixin) result = prop_type.Kind_Mixins_X + result return tuple (uniq (result))
def names (self) : def _gen (self) : selector = self.selector skip_pat = self.name_skip_pat trigger = self.trigger try : f = selector [trigger] except KeyError : logging.warning \ ( "Unknown trigger attribute %s for %r" % (trigger, selector) ) else : yield f.name for f in selector.atoms : n = f.name if not skip_pat.match (n) : yield n return tuple (uniq (_gen (self)))
def __init__ \ ( self, base , deltas = None , log_round_amount = None , scale = 0 , ** kwds ) : self.base = base self.deltas = \ ( None if deltas is None else sorted (uniq (itertools.chain (deltas, ([] if scale else [1, base])))) ) self.lra = log_round_amount self.scale = scale self._kwds = kwds self.pop_to_self (kwds, "base_deltas") self.__dict__.update (kwds) if base == 10 : self.log = log10
def _m_update_combine(cls, bases, dct): def _gen(cls, bases, name): undef = update_combined_many.Undef for c in reversed((cls, ) + bases): yield getattr(c, name, undef) for name in cls._attrs_to_update_combine: try: v = update_combined_many(*_gen(cls, bases, name)) except Exception as exc: print \ ( "*** Exception when trying to update/combined", name , "for class", cls ) raise setattr(cls, name, v) for name in cls._attrs_uniq_to_update_combine: v = update_combined_many(*_gen(cls, bases, name)) setattr(cls, name, v.__class__(uniq(v)))
def names(self): def _gen(self): selector = self.selector skip_pat = self.name_skip_pat trigger = self.trigger try: f = selector[trigger] except KeyError: logging.warning \ ( "Unknown trigger attribute %s for %r" % (trigger, selector) ) else: yield f.name for f in selector.atoms: n = f.name if not skip_pat.match(n): yield n return tuple(uniq(_gen(self)))
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
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
def names (self) : return tuple (uniq ((self.name, ) + self.polisher.buddies))
def _of_bases (self, cls) : result = TFL.defaultdict (list) for b in reversed (cls.__bases__) : for k, cs in pyk.iteritems (self.of_class (b)) : result [k] = list (uniq (ichain (result [k], cs))) return result
def add_replacers (self, * replacers) : self.replacers = list \ (uniq (itertools.chain (self.replacers, replacers)))
def attrs (self) : return tuple (uniq (itertools.chain (* (s.attrs for s in self.sels))))
def attrs(self): return tuple(uniq(itertools.chain(*(s.attrs for s in self.sels))))
def _of_bases(self, cls): result = TFL.defaultdict(list) for b in reversed(cls.__bases__): for k, cs in pyk.iteritems(self.of_class(b)): result[k] = list(uniq(ichain(result[k], cs))) return result
def add_replacers(self, *replacers): self.replacers = list \ (uniq (itertools.chain (self.replacers, replacers)))