Exemplo n.º 1
0
def parse_acl(acl):
    """Parse ACL entry.

    >>> parse_acl('user=rwx/owner')
    ('user', 'rwx', 'owner')
    >>> parse_acl('" ""user"=rwx/" ""owner"')
    (' "user', 'rwx', ' "owner')
    >>> parse_acl('user=rwx')
    ('user', 'rwx', None)
    >>> parse_acl('=/f')
    (None, '', 'f')
    """
    global _acl_rc
    if not _acl_rc:
        _acl_rc = re.compile(_acl_re, re.I | re.X)

    m = _acl_rc.match(acl)
    if not m:
        return None

    target = m.group('tgt')
    perm = m.group('perm')
    owner = m.group('owner')

    if target:
        target = skytools.unquote_ident(target)
    if perm:
        perm = perm[1:]
    if owner:
        owner = skytools.unquote_ident(owner[1:])

    return (target, perm, owner)
Exemplo n.º 2
0
def parse_acl(acl):
    """Parse ACL entry.

    >>> parse_acl('user=rwx/owner')
    ('user', 'rwx', 'owner')
    >>> parse_acl('" ""user"=rwx/" ""owner"')
    (' "user', 'rwx', ' "owner')
    >>> parse_acl('user=rwx')
    ('user', 'rwx', None)
    >>> parse_acl('=/f')
    (None, '', 'f')
    """
    global _acl_rc
    if not _acl_rc:
        _acl_rc = re.compile(_acl_re, re.I | re.X)

    m = _acl_rc.match(acl)
    if not m:
        return None

    target = m.group('tgt')
    perm = m.group('perm')
    owner = m.group('owner')

    if target:
        target = skytools.unquote_ident(target)
    if perm:
        perm = perm[1:]
    if owner:
        owner = skytools.unquote_ident(owner[1:])

    return (target, perm, owner)
Exemplo n.º 3
0
def unquote_any(typ, s):
    if typ == 'ident':
        ps = [skytools.unquote_ident(p) for p in s.split('.')]
        s = '.'.join(ps)
    elif typ == 'str' or typ == 'dolq':
        s = skytools.unquote_literal(s, True)
    return s
Exemplo n.º 4
0
def unquote_any(typ, s):
    if typ == 'ident':
        ps = [skytools.unquote_ident(p) for p in s.split('.')]
        s = '.'.join(ps)
    elif typ == 'str' or typ == 'dolq':
        s = skytools.unquote_literal(s, True)
    return s
Exemplo n.º 5
0
def unquote_any(s):
    if s:
        c = s[0]
        if c == "'":
            s = skytools.unquote_literal(s, stdstr = True)
        elif c == '"':
            s = skytools.unquote_ident(s)
        # extquote?
        else:
            s = s.lower()
    return s
Exemplo n.º 6
0
def unquote_any(s):
    if s:
        c = s[0]
        if c == "'":
            s = skytools.unquote_literal(s, stdstr=True)
        elif c == '"':
            s = skytools.unquote_ident(s)
        # extquote?
        else:
            s = s.lower()
    return s
Exemplo n.º 7
0
 def parse_sql(self, op, sql, pklist=None):
     """Main entry point."""
     if pklist is None:
         self.pklist = []
     else:
         self.pklist = pklist
     tk = self.tokenizer(sql)
     fields = []
     values = []
     try:
         if op == "I":
             self.parse_insert(tk, fields, values)
         elif op == "U":
             self.parse_update(tk, fields, values)
         elif op == "D":
             self.parse_delete(tk, fields, values)
         raise Exception("syntax error")
     except StopIteration:
         # last sanity check
         if len(fields) == 0 or len(fields) != len(values):
             raise Exception("syntax error, fields do not match values")
     fields = [skytools.unquote_ident(f) for f in fields]
     values = [skytools.unquote_literal(f) for f in values]
     return skytools.dbdict(zip(fields, values))
Exemplo n.º 8
0
 def _create_dbdict(self, fields, values):
     fields = [skytools.unquote_ident(f) for f in fields]
     values = [skytools.unquote_literal(f) for f in values]
     return skytools.dbdict(zip(fields, values))
Exemplo n.º 9
0
 def _create_dbdict(self, fields, values):
     fields = [skytools.unquote_ident(f) for f in fields]
     values = [skytools.unquote_literal(f) for f in values]
     return skytools.dbdict(zip(fields, values))