def parse_privs(privs, db):
 if (privs is None):
  return privs
 o_privs = {'database': {}, 'table': {}}
 for token in privs.split('/'):
  if (':' not in token):
   type_ = 'database'
   name = db
   priv_set = frozenset((x.strip().upper() for x in token.split(',') if x.strip()))
  else:
   type_ = 'table'
   (name, privileges) = token.split(':', 1)
   priv_set = frozenset((x.strip().upper() for x in privileges.split(',') if x.strip()))
  if (not priv_set.issubset(VALID_PRIVS[type_])):
   raise InvalidPrivsError(('Invalid privs specified for %s: %s' % (type_, ' '.join(priv_set.difference(VALID_PRIVS[type_])))))
  priv_set = normalize_privileges(priv_set, type_)
  o_privs[type_][name] = priv_set
 return o_privs

def parse_privs ( privs , db ) : if ( privs is None ) : return privs o_privs = { 'database' : { } , 'table' : { } } for token in privs . split ( '/' ) : if ( ':' not in token ) : type_ = 'database' name = db priv_set = frozenset ( ( x . strip ( ) . upper ( ) for x in token . split ( ',' ) if x . strip ( ) ) ) else : type_ = 'table' ( name , privileges ) = token . split ( ':' , 1 ) priv_set = frozenset ( ( x . strip ( ) . upper ( ) for x in privileges . split ( ',' ) if x . strip ( ) ) ) if ( not priv_set . issubset ( VALID_PRIVS [ type_ ] ) ) : raise InvalidPrivsError ( ( 'Invalid privs specified for %s: %s' % ( type_ , ' ' . join ( priv_set . difference ( VALID_PRIVS [ type_ ] ) ) ) ) ) priv_set = normalize_privileges ( priv_set , type_ ) o_privs [ type_ ] [ name ] = priv_set return o_privs
parse privilege string to determine permissions for database db .