How to use the pydal._compat.iteritems function in pydal

To help you get started, we’ve selected a few pydal examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github web2py / pydal / pydal / representers / __init__.py View on Github external
def get_representer_for_instance(self, value):
        for inst, representer in iteritems(self.registered_i):
            if isinstance(value, inst):
                return representer
        return self._default_instance
github web2py / pydal / pydal / scheduler.py View on Github external
def _decode_dict(dct):
    if not PY2:
        return dct
    newdict = {}
    for k, v in iteritems(dct):
        if isinstance(k, unicode):
            k = k.encode('utf-8')
        if isinstance(v, unicode):
            v = v.encode('utf-8')
        elif isinstance(v, list):
            v = _decode_list(v)
        newdict[k] = v
    return newdict
github web2py / pydal / pydal / adapters / mssql.py View on Github external
password = ''
            host = m.group('host')
            if not host:
                raise SyntaxError('Host name required')
            db = m.group('db')
            if not db:
                raise SyntaxError('Database name required')
            port = m.group('port') or '1433'
            # Parse the optional url name-value arg pairs after the '?'
            # (in the form of arg1=value1&arg2=value2&...)
            # Default values (drivers like FreeTDS insist on uppercase parameter keys)
            argsdict = { 'DRIVER':'{SQL Server}' }
            urlargs = m.group('urlargs') or ''
            for argmatch in self.REGEX_ARGPATTERN.finditer(urlargs):
                argsdict[str(argmatch.group('argkey')).upper()] = argmatch.group('argvalue')
            urlargs = ';'.join(['%s=%s' % (ak, av) for (ak, av) in iteritems(argsdict)])
            cnxn = 'SERVER=%s;PORT=%s;DATABASE=%s;UID=%s;PWD=%s;%s' \
                % (host, port, db, user, password, urlargs)
        def connector(cnxn=cnxn,driver_args=driver_args):
            return self.driver.connect(cnxn, **driver_args)
        self.connector = connector
        if do_connect: self.reconnect()
github web2py / pydal / pydal / dialects / __init__.py View on Github external
def __init__(self, adapter):
        self.adapter = adapter
        self.types = {}
        for name, obj in iteritems(self._all_sqltypes_):
            self.types[obj.key] = obj.f(self)
        for name, obj in iteritems(self._all_expressions_):
            Expression._dialect_expressions_[obj.name] = ExpressionMethodWrapper(
                self, obj
            )
github web2py / pydal / pydal / objects.py View on Github external
def _compute_fields_for_operation(self, fields, to_compute):
        row = OpRow(self)
        for name, tup in iteritems(fields):
            field, value = tup
            if isinstance(
                value,
                (
                    types.LambdaType,
                    types.FunctionType,
                    types.MethodType,
                    types.BuiltinFunctionType,
                    types.BuiltinMethodType,
                ),
            ):
                value = value()
            row.set_value(name, value, field)
        for name, field in to_compute:
            try:
                row.set_value(name, field.compute(row), field)
github web2py / pydal / pydal / representers / __init__.py View on Github external
def __init__(self, adapter):
        self.adapter = adapter
        self.dialect = adapter.dialect
        self._tbefore_registry_ = {}
        for name, obj in iteritems(self._declared_tbefore_):
            self._tbefore_registry_[obj.field_type] = obj.f
        self.registered_t = defaultdict(lambda self=self: self._default)
        for name, obj in iteritems(self._declared_trepresenters_):
            if obj.field_type in self._tbefore_registry_:
                self.registered_t[obj.field_type] = TReprMethodWrapper(
                    self, obj, self._tbefore_registry_[obj.field_type]
                )
            else:
                self.registered_t[obj.field_type] = TReprMethodWrapper(self, obj)
        self.registered_i = {}
        for name, obj in iteritems(self._declared_irepresenters_):
            self.registered_i[obj.inst_type] = IReprMethodWrapper(self, obj)
        self._pre_registry_ = []
        pres = []
        for name, obj in iteritems(self._declared_pres_):
            pres.append(obj)
        pres.sort(key=lambda x: x._inst_count_)
        for pre in pres:
            self._pre_registry_.append(PreMethodWrapper(self, pre))
github web2py / pydal / pydal / migrator.py View on Github external
# logfile is deprecated (moved to adapter.log method)
        db = table._db
        db._migrated.append(table._tablename)
        tablename = table._tablename
        if self.dbengine in ("firebird",):
            drop_expr = "ALTER TABLE %s DROP %s;"
        else:
            drop_expr = "ALTER TABLE %s DROP COLUMN %s;"
        field_types = dict(
            (x.lower(), table[x].type) for x in sql_fields.keys() if x in table
        )
        # make sure all field names are lower case to avoid
        # migrations because of case change
        sql_fields = dict(map(self._fix, iteritems(sql_fields)))
        sql_fields_old = dict(map(self._fix, iteritems(sql_fields_old)))
        sql_fields_aux = dict(map(self._fix, iteritems(sql_fields_aux)))
        if db._debug:
            db.logger.debug("migrating %s to %s" % (sql_fields_old, sql_fields))

        keys = list(sql_fields.keys())
        for key in sql_fields_old:
            if key not in keys:
                keys.append(key)
        new_add = self.dialect.concat_add(table._rname)

        metadata_change = False
        sql_fields_current = copy.copy(sql_fields_old)
        for key in keys:
            query = None
            if key not in sql_fields_old:
                sql_fields_current[key] = sql_fields[key]
                if self.dbengine in ("postgres",) and sql_fields[key][
github web2py / pydal / pydal / migrator.py View on Github external
fake_migrate=False,
    ):
        # logfile is deprecated (moved to adapter.log method)
        db = table._db
        db._migrated.append(table._tablename)
        tablename = table._tablename
        if self.dbengine in ("firebird",):
            drop_expr = "ALTER TABLE %s DROP %s;"
        else:
            drop_expr = "ALTER TABLE %s DROP COLUMN %s;"
        field_types = dict(
            (x.lower(), table[x].type) for x in sql_fields.keys() if x in table
        )
        # make sure all field names are lower case to avoid
        # migrations because of case change
        sql_fields = dict(map(self._fix, iteritems(sql_fields)))
        sql_fields_old = dict(map(self._fix, iteritems(sql_fields_old)))
        sql_fields_aux = dict(map(self._fix, iteritems(sql_fields_aux)))
        if db._debug:
            db.logger.debug("migrating %s to %s" % (sql_fields_old, sql_fields))

        keys = list(sql_fields.keys())
        for key in sql_fields_old:
            if key not in keys:
                keys.append(key)
        new_add = self.dialect.concat_add(table._rname)

        metadata_change = False
        sql_fields_current = copy.copy(sql_fields_old)
        for key in keys:
            query = None
            if key not in sql_fields_old:
github web2py / pydal / pydal / objects.py View on Github external
def validate_and_update(self, _key, **fields):
        record = self(**_key) if isinstance(_key, dict) else self(_key)
        response, new_fields = self._validate_fields(fields, "update", record.id)
        #: do the update
        if not response.errors and record:
            if "_id" in self:
                myset = self._db(self._id == record[self._id.name])
            else:
                query = None
                for key, value in iteritems(_key):
                    if query is None:
                        query = getattr(self, key) == value
                    else:
                        query = query & (getattr(self, key) == value)
                myset = self._db(query)
            response.updated = myset.update(**new_fields)
        if record:
            response.id = record.id
        return response
github web2py / pydal / pydal / representers / __init__.py View on Github external
def __init__(self, adapter):
        self.adapter = adapter
        self.dialect = adapter.dialect
        self._tbefore_registry_ = {}
        for name, obj in iteritems(self._declared_tbefore_):
            self._tbefore_registry_[obj.field_type] = obj.f
        self.registered_t = defaultdict(lambda self=self: self._default)
        for name, obj in iteritems(self._declared_trepresenters_):
            if obj.field_type in self._tbefore_registry_:
                self.registered_t[obj.field_type] = TReprMethodWrapper(
                    self, obj, self._tbefore_registry_[obj.field_type]
                )
            else:
                self.registered_t[obj.field_type] = TReprMethodWrapper(self, obj)
        self.registered_i = {}
        for name, obj in iteritems(self._declared_irepresenters_):
            self.registered_i[obj.inst_type] = IReprMethodWrapper(self, obj)
        self._pre_registry_ = []
        pres = []
        for name, obj in iteritems(self._declared_pres_):
            pres.append(obj)

pydal

pyDAL is a Database Abstraction Layer. It generates queries for SQlite, PotsgreSQL, MySQL, and other backends. It was originally part of the web2py frameworks but it is now an independent project. Example: db.define_table("thing",Field("name")) and db.thing.insert(name="Pizza")

BSD-3-Clause
Latest version published 18 days ago

Package Health Score

81 / 100
Full package analysis