Example #1
0
    def __init__(self, name, description=None, **attrs):
        """Initialize the catalog object from a dictionary of attributes

        :param name: name of object
        :param description: comment text describing object
        :param attrs: the dictionary of attributes

        Non-key attributes without a value are discarded. Values that
        are multi-line strings are treated specially so that YAML will
        output them in block style.
        """
        self.name = name
        self.description = description
        self._init_own_privs(attrs.pop('owner', None),
                             attrs.pop('privileges', []))
        self.depends_on = []
        self._objtype = None

        for key, val in list(attrs.items()):
            if val or key in self.keylist:
                if key in ['definition', 'source'] and \
                        isinstance(val, strtypes) and '\n' in val:
                    newval = []
                    for line in val.split('\n'):
                        if line and line[-1] in (' ', '\t'):
                            line = line.rstrip()
                        newval.append(line)
                    strval = '\n'.join(newval)
                    if PY2:
                        val = strval.encode('utf_8').decode('utf_8')
                    else:
                        val = MultiLineStr(strval)
                setattr(self, key, val)
Example #2
0
    def __init__(self, name, schema, description, owner, privileges,
                 arguments, language, returns, source, obj_file=None,
                 configuration=None, volatility=None, leakproof=False,
                 strict=False, security_definer=False, cost=0, rows=0,
                 allargs=None, oid=None):
        """Initialize the function

        :param name-arguments: see Proc.__init__ params
        :param language: implementation language (from prolang)
        :param returns: return type (from pg_get_function_result/prorettype)
        :param source: source code, link symbol, etc. (from prosrc)
        :param obj_file: language-specific info (from probin)
        :param configuration: configuration variables (from proconfig)
        :param volatility: volatility type (from provolatile)
        :param leakproof: has side effects (from proleakproof)
        :param strict: null handling (from proisstrict)
        :param security_definer: security definer (from prosecdef)
        :param cost: execution cost estimate (from procost)
        :param rows: result row estimate (from prorows)
        :param allargs: argument list with defaults (from
               pg_get_function_arguments)
        """
        super(Function, self).__init__(
            name, schema, description, owner, privileges, arguments)
        self.language = language
        self.returns = returns
        if source and '\n' in source:
            newsrc = []
            for line in source.split('\n'):
                if line and line[-1] in (' ', '\t'):
                    line = line.rstrip()
                newsrc.append(line)
            source = '\n'.join(newsrc)
        if PY2:
            if source is not None:
                self.source = source.encode('utf_8').decode('utf_8')
            else:
                self.source = None
        else:
            self.source = MultiLineStr(source)
        self.obj_file = obj_file
        self.configuration = configuration
        self.allargs = allargs
        if volatility is not None:
            self.volatility = volatility[:1].lower()
        else:
            self.volatility = 'v'
        assert self.volatility in VOLATILITY_TYPES.keys()
        self.leakproof = leakproof
        self.strict = strict
        self.security_definer = security_definer
        self.cost = cost
        self.rows = rows
        self.oid = oid
Example #3
0
File: view.py Project: swca/Pyrseas
    def __init__(self, name, schema, description, owner, privileges,
                 definition,
                 oid=None):
        """Initialize the view

        :param name-privileges: see DbClass.__init__ params
        :param definition: prettified definition (from pg_getviewdef)
        """
        super(View, self).__init__(name, schema, description, owner,
                                   privileges)
        if PY2:
            self.definition = definition
        else:
            self.definition = MultiLineStr(definition)
        self.triggers = {}
        self.columns = []
        self.oid = oid