Пример #1
0
 def _outer_pgk_ns (self, outer, pns, _pkg_ns) :
     while True :
         outer, _, name = rsplit_hst (outer, ".")
         if (not outer) or outer in _pkg_ns :
             break
         pns = pns._Outer
         yield outer, pns
Пример #2
0
 def _outer_pgk_ns(self, outer, pns, _pkg_ns):
     while True:
         outer, _, name = rsplit_hst(outer, ".")
         if (not outer) or outer in _pkg_ns:
             break
         pns = pns._Outer
         yield outer, pns
Пример #3
0
def formatted_select(ETW, name="select", select=None, formatter=str):
    sep = nl + indent
    if select is None:
        select = getattr(ETW, name, None)
    if select is None:
        return "No '%s'" % (name, )
    text = formatter(select)

    def _gen(lines, indent=7):
        s = "," + sep + (" " * indent)
        inner_indent = " " * (indent - 7)
        inner_sep = "\n" + inner_indent
        for l in lines:
            if "," in l:
                comps = sorted(c.strip() for c in l.split(","))
                yield s.join(comps)
            elif "JOIN" in l:
                rerep = TFL.Re_Replacer \
                    ( "((?:[A-Z]+ )*JOIN)"
                    , "\n       \\1"
                    )
                p = rerep(l)
                ps = list(x.rstrip() for x in p.split("\n"))
                p = inner_indent + inner_sep.join(ps)
                yield p
            elif "WHERE" in l:
                rerep = TFL.Re_Replacer \
                    ( "((?:\s+)*(?:AND|OR)\s+)"
                    , "\n       \\1"
                    )
                p = rerep(l)
                ps = list(x.rstrip() for x in p.split("\n"))
                p = inner_indent + inner_sep.join(ps)
                yield p
            else:
                yield l

    gindent = 7
    head, _, tail = split_hst(text, " ")
    t_head, t_sep, t_tail = split_hst(tail, "\nFROM (SELECT")
    if t_sep:
        head = sep.join((" ".join((head, t_head)), t_sep.strip()))
        tail, t_sep, t_tail_tip = rsplit_hst(t_tail, ")")
        ttt_lines = t_tail_tip.split(nl)
        gindent += 6
    lines = tail.split(nl)
    result = " ".join \
        ((head, sep.join (x.rstrip () for x in _gen (lines, gindent))))
    if t_sep:
        r_tail = sep.join(x.rstrip() for x in _gen(ttt_lines))
        result = sep.join((result, " " * 5 + t_sep + r_tail))
    return result.rstrip()
Пример #4
0
def formatted_select (ETW, name = "select", select = None, formatter = str) :
    sep = nl + indent
    if select is None :
        select = getattr (ETW, name, None)
    if select is None :
        return "No '%s'" % (name, )
    text = formatter (select)
    def _gen (lines, indent = 7) :
        s = "," + sep + (" " * indent)
        inner_indent = " " * (indent - 7)
        inner_sep    = "\n" + inner_indent
        for l in lines :
            if "," in l :
                comps = sorted (c.strip () for c in l.split (","))
                yield s.join (comps)
            elif "JOIN" in l :
                rerep = TFL.Re_Replacer \
                    ( "((?:[A-Z]+ )*JOIN)"
                    , "\n       \\1"
                    )
                p  = rerep (l)
                ps = list (x.rstrip () for x in p.split ("\n"))
                p  = inner_indent + inner_sep.join (ps)
                yield p
            elif "WHERE" in l :
                rerep = TFL.Re_Replacer \
                    ( "((?:\s+)*(?:AND|OR)\s+)"
                    , "\n       \\1"
                    )
                p  = rerep (l)
                ps = list (x.rstrip () for x in p.split ("\n"))
                p  = inner_indent + inner_sep.join (ps)
                yield p
            else :
                yield l
    gindent = 7
    head, _, tail  = split_hst  (text, " ")
    t_head, t_sep, t_tail = split_hst (tail, "\nFROM (SELECT")
    if t_sep :
        head = sep.join ((" ".join ((head, t_head)), t_sep.strip ()))
        tail, t_sep, t_tail_tip = rsplit_hst (t_tail, ")")
        ttt_lines = t_tail_tip.split (nl)
        gindent += 6
    lines  = tail.split (nl)
    result = " ".join \
        ((head, sep.join (x.rstrip () for x in _gen (lines, gindent))))
    if t_sep :
        r_tail = sep.join (x.rstrip () for x in _gen (ttt_lines))
        result = sep.join (( result, " " * 5 + t_sep + r_tail))
    return result.rstrip ()
Пример #5
0
 def dir_map (cmd) :
     from _TFL.predicate import rsplit_hst
     for d in cmd.argv :
         p, _, v = rsplit_hst (d, "=")
         yield p, v
Пример #6
0
 def RAW(self):
     """Get raw value for attribute specified by getter `self`."""
     prefix, _, postfix = rsplit_hst(self._name, ".")
     Q = self.Q
     return Q.RAW._Get_Raw_(Q, prefix=prefix, postfix=postfix)
Пример #7
0
 def RAW (self) :
     """Get raw value for attribute specified by getter `self`."""
     prefix, _, postfix = rsplit_hst (self._name, ".")
     Q = self.Q
     return Q.RAW._Get_Raw_ (Q, prefix = prefix, postfix = postfix)