• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python util.safe_execute函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中services.util.safe_execute函数的典型用法代码示例。如果您正苦于以下问题:Python safe_execute函数的具体用法?Python safe_execute怎么用?Python safe_execute使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了safe_execute函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: delete_storage

 def delete_storage(self, user_id):
     """Removes all user data"""
     for query in ('DELETE_USER_COLLECTIONS', 'DELETE_USER_WBOS'):
         query = self._get_query(query, user_id)
         safe_execute(self._engine, query, user_id=user_id)
     # XXX see if we want to check the rowcount
     return True
开发者ID:rfk,项目名称:moz-server-storage,代码行数:7,代码来源:sql.py


示例2: set_collection

    def set_collection(self, user_id, collection_name, **values):
        """Creates a collection"""
        # XXX values is not used for now because there are no values besides
        # the name
        if self.collection_exists(user_id, collection_name):
            return

        values['userid'] = user_id
        values['name'] = collection_name

        if self.standard_collections:
            ids = _STANDARD_COLLECTIONS.keys()
            min_id = max(ids) + 1
        else:
            min_id = 0

        # getting the max collection_id
        # XXX why don't we have an autoinc here ?
        # see https://bugzilla.mozilla.org/show_bug.cgi?id=579096
        next_id = -1
        while next_id < min_id:
            query = self._get_query('COLLECTION_NEXTID', user_id)
            max_ = safe_execute(self._engine, query, user_id=user_id).first()
            if max_[0] is None:
                next_id = min_id
            else:
                next_id = max_[0] + 1

        # insertion
        values['collectionid'] = next_id
        query = insert(collections).values(**values)
        safe_execute(self._engine, query, **values)
        return next_id
开发者ID:rfk,项目名称:moz-server-storage,代码行数:33,代码来源:sql.py


示例3: set_user

    def set_user(self, user_id, **values):
        """set information for a user. values contains the fields to set.

        If the user doesn't exists, it will be created.
        """
        values['id'] = user_id
        if not self.user_exists(user_id):
            query = insert(users).values(**values)
        else:
            query = update(users).where(users.c.id == user_id)
            query = query.values(**values)

        safe_execute(self._engine, query)
开发者ID:rfk,项目名称:moz-server-storage,代码行数:13,代码来源:sql.py


示例4: update_password

    def update_password(self, user_id, password, old_password=None, key=None):
        """Change the user password

        Args:
            user_id: user id
            password: new password

        Returns:
            True if the change was successful, False otherwise
        """
        if old_password is None:
            if key:
                #using a key, therefore we should check it
                if self._get_reset_code(user_id) == key:
                    self.clear_reset_code(user_id)
                else:
                    logger.error("bad key used for update password")
                    return False
            else:
                return False

        password_hash = ssha256(password)
        query = update(users).where(users.c.id == user_id)
        res = safe_execute(self._engine,
                           query.values(password_hash=password_hash))
        return res.rowcount == 1
开发者ID:mozilla,项目名称:server-core,代码行数:26,代码来源:sql.py


示例5: clear_reset_code

    def clear_reset_code(self, user_id):
        if self._engine is None:
            raise NotImplementedError()

        query = delete(reset_codes).where(reset_codes.c.username == user_id)
        res = safe_execute(self._engine, query)
        return res.rowcount > 0
开发者ID:irslambouf,项目名称:SyncServer,代码行数:7,代码来源:resetcode.py


示例6: create_user

    def create_user(self, username, password, email, **extra_fields):
        """Creates a user. Returns True on success."""
        if not self.allow_new_users:
            raise BackendError("Creation of new users is disabled")

        password_hash = sscrypt(password)
        values = {
            'username': username,
            'password': password_hash,
            'mail': email,
        }
        for field in ('userid', 'accountStatus', 'mailVerified', 'syncNode'):
            if field in extra_fields:
                values[field] = extra_fields[field]
        query = insert(users).values(**values)
        try:
            res = safe_execute(self._engine, query)
        except IntegrityError:
            #Name already exists
            return False

        if res.rowcount != 1:
            return False

        #need a copy with some of the info for the return value
        userobj = User()
        userobj['username'] = username
        userobj['userid'] = res.lastrowid
        userobj['mail'] = email

        return userobj
开发者ID:irslambouf,项目名称:SyncServer,代码行数:31,代码来源:sql.py


示例7: get_user_info

    def get_user_info(self, user, attrs):
        """Returns user info

        Args:
            user: the user object
            attrs: the pieces of data requested

        Returns:
            user object populated with attrs
        """
        user_id = self.get_user_id(user)
        if user_id is None:
            return user

        attrs = [attr for attr in attrs if not user.get(attr)]
        if attrs == []:
            return user

        fields = []
        for attr in attrs:
            fields.append(getattr(users.c, attr))

        _USER_INFO = select(fields, users.c.userid == bindparam('user_id'))
        res = safe_execute(self._engine, _USER_INFO,
                           user_id=user_id).fetchone()
        if res is None:
            return user
        for attr in attrs:
            try:
                user[attr] = getattr(res, attr)
            except AttributeError:
                user[attr] = None

        return user
开发者ID:rfk,项目名称:moz-server-core,代码行数:34,代码来源:sql.py


示例8: get_collection

    def get_collection(self, user_id, collection_name, fields=None,
                       create=True):
        """Return information about a collection."""
        if fields is None:
            fields = [collections]
            field_names = collections.columns.keys()
        else:
            field_names = fields
            fields = [getattr(collections.c, field) for field in fields]

        query = select(fields, and_(collections.c.userid == user_id,
                                    collections.c.name == collection_name))
        res = safe_execute(self._engine, query).first()

        # the collection is created
        if res is None and create:
            collid = self.set_collection(user_id, collection_name)
            res = {'userid': user_id, 'collectionid': collid,
                   'name': collection_name}
            if fields is not None:
                for key in res.keys():
                    if key not in field_names:
                        del res[key]
        else:
            # make this a single step
            res = dict([(key, value) for key, value in res.items()
                         if value is not None])
        return res
开发者ID:rfk,项目名称:moz-server-storage,代码行数:28,代码来源:sql.py


示例9: collection_exists

 def collection_exists(self, user_id, collection_name):
     """Returns True if the collection exists"""
     query = self._get_query('COLLECTION_EXISTS', user_id)
     res = safe_execute(self._engine, query, user_id=user_id,
                        collection_name=collection_name)
     res = res.fetchone()
     return res is not None
开发者ID:rfk,项目名称:moz-server-storage,代码行数:7,代码来源:sql.py


示例10: get_user_id

 def get_user_id(self, user_name):
     """Returns the id for a user name"""
     user = safe_execute(self._engine, _USER_ID,
                         user_name=user_name).fetchone()
     if user is None:
         return None
     return user.id
开发者ID:irslambouf,项目名称:SyncServer,代码行数:7,代码来源:sql.py


示例11: _set_reset_code

 def _set_reset_code(self, user_id):
     code, expiration = generate_reset_code()
     query = update(users).values(reset=code, reset_expiration=expiration)
     res = safe_execute(self._engine, query.where(users.c.id == user_id))
     if res.rowcount != 1:
         logger.debug('Unable to add a new reset code')
         return None  # XXX see if appropriate
     return code
开发者ID:mozilla,项目名称:server-core,代码行数:8,代码来源:sql.py


示例12: delete_item

 def delete_item(self, user_id, collection_name, item_id,
                 storage_time=None):
     """Deletes an item"""
     collection_id = self._get_collection_id(user_id, collection_name)
     query = self._get_query('DELETE_SOME_USER_WBO', user_id)
     res = safe_execute(self._engine, query, user_id=user_id,
                        collection_id=collection_id,
                        item_id=item_id)
     return res.rowcount == 1
开发者ID:rfk,项目名称:moz-server-storage,代码行数:9,代码来源:sql.py


示例13: get_collections

    def get_collections(self, user_id, fields=None):
        """returns the collections information """
        if fields is None:
            fields = [collections]
        else:
            fields = [getattr(collections.c, field) for field in fields]

        query = select(fields, collections.c.userid == user_id)
        return safe_execute(self._engine, query).fetchall()
开发者ID:rfk,项目名称:moz-server-storage,代码行数:9,代码来源:sql.py


示例14: get_collection_counts

 def get_collection_counts(self, user_id):
     """Return the collection counts for a given user"""
     query = self._get_query('COLLECTION_COUNTS', user_id)
     res = safe_execute(self._engine, query, user_id=user_id,
                        ttl=_int_now())
     try:
         return dict([(self._collid2name(user_id, collid), count)
                       for collid, count in res])
     finally:
         self._purge_cache(user_id)
开发者ID:rfk,项目名称:moz-server-storage,代码行数:10,代码来源:sql.py


示例15: get_collection_timestamps

 def get_collection_timestamps(self, user_id):
     """return the collection names for a given user"""
     query = 'COLLECTION_STAMPS'
     query = self._get_query(query, user_id)
     res = safe_execute(self._engine, query, user_id=user_id)
     try:
         return dict([(self._collid2name(user_id, coll_id),
                     bigint2time(stamp)) for coll_id, stamp in res])
     finally:
         self._purge_cache(user_id)
开发者ID:rfk,项目名称:moz-server-storage,代码行数:10,代码来源:sql.py


示例16: _set_reset_code

 def _set_reset_code(self, user_id):
     rc = ResetCode()
     code = rc._generate_reset_code()
     expiration = datetime.datetime.now() + datetime.timedelta(hours=6)
     query = update(users).values(reset=code, reset_expiration=expiration)
     res = safe_execute(self._engine, query.where(users.c.id == user_id))
     if res.rowcount != 1:
         self.logger.debug('Unable to add a new reset code')
         return None  # XXX see if appropriate
     return code
开发者ID:irslambouf,项目名称:SyncServer,代码行数:10,代码来源:sql.py


示例17: item_exists

 def item_exists(self, user_id, collection_name, item_id):
     """Returns a timestamp if an item exists."""
     collection_id = self._get_collection_id(user_id, collection_name)
     query = self._get_query('ITEM_EXISTS', user_id)
     res = safe_execute(self._engine, query, user_id=user_id,
                        item_id=item_id,
                        collection_id=collection_id, ttl=_int_now())
     res = res.fetchone()
     if res is None:
         return None
     return bigint2time(res[0])
开发者ID:rfk,项目名称:moz-server-storage,代码行数:11,代码来源:sql.py


示例18: get_collection_max_timestamp

 def get_collection_max_timestamp(self, user_id, collection_name):
     """Returns the max timestamp of a collection."""
     query = self._get_query('COLLECTION_MAX_STAMPS', user_id)
     collection_id = self._get_collection_id(user_id, collection_name)
     res = safe_execute(self._engine, query, user_id=user_id,
                        collection_id=collection_id)
     res = res.fetchone()
     stamp = res[0]
     if stamp is None:
         return None
     return bigint2time(stamp)
开发者ID:rfk,项目名称:moz-server-storage,代码行数:11,代码来源:sql.py


示例19: get_total_size

    def get_total_size(self, user_id, recalculate=False):
        """Returns the total size in KB of a user storage.

        The size is the sum of stored payloads.
        """
        query = self._get_query('USER_STORAGE_SIZE', user_id)
        res = safe_execute(self._engine, query, user_id=user_id,
                           ttl=_int_now())
        res = res.fetchone()
        if res is None or res[0] is None:
            return 0.0
        return int(res[0]) / _KB
开发者ID:rfk,项目名称:moz-server-storage,代码行数:12,代码来源:sql.py


示例20: delete_items

    def delete_items(self, user_id, collection_name, item_ids=None,
                     filters=None, limit=None, offset=None, sort=None,
                     storage_time=None):
        """Deletes items. All items are removed unless item_ids is provided"""
        collection_id = self._get_collection_id(user_id, collection_name)
        wbo = self._get_wbo_table(user_id)
        query = _delete(wbo)
        where = [wbo.c.username == bindparam('user_id'),
                 wbo.c.collection == bindparam('collection_id')]

        if item_ids is not None:
            where.append(wbo.c.id.in_(item_ids))

        if filters is not None:
            for field, value in filters.items():
                field = getattr(wbo.c, field)

                operator, value = value
                if field.name == 'modified':
                    value = _roundedbigint(value)
                if isinstance(value, (list, tuple)):
                    where.append(field.in_(value))
                else:
                    if operator == '=':
                        where.append(field == value)
                    elif operator == '<':
                        where.append(field < value)
                    elif operator == '>':
                        where.append(field > value)

        where = and_(*where)
        query = query.where(where)

        if self.engine_name != 'sqlite':
            if sort is not None:
                if sort == 'oldest':
                    query = query.order_by(wbo.c.modified.asc())
                elif sort == 'newest':
                    query = query.order_by(wbo.c.modified.desc())
                else:
                    query = query.order_by(wbo.c.sortindex.desc())

            if limit is not None and int(limit) > 0:
                query = query.limit(int(limit))

            if offset is not None and int(offset) > 0:
                query = query.offset(int(offset))

        # XXX see if we want to send back more details
        # e.g. by checking the rowcount
        res = safe_execute(self._engine, query, user_id=user_id,
                           collection_id=collection_id)
        return res.rowcount > 0
开发者ID:rfk,项目名称:moz-server-storage,代码行数:53,代码来源:sql.py



注:本文中的services.util.safe_execute函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python verify.decode_receipt函数代码示例发布时间:2022-05-27
下一篇:
Python spawn.MobileTemplate类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap