コード例 #1
0
ファイル: catalog.py プロジェクト: CGTIC/Plone_SP
 def removeDefaultQueryFactory(self, factory):
     res = list(self._queryFactories)
     try:
         res.remove(factory)
     except ValueError:
         raise LookupError('factory not found', factory)
     self._queryFactories = tuple(res)
コード例 #2
0
ファイル: zodb_backend.py プロジェクト: lexBuright/qscli
 def default(self, o):
     if isinstance(o, persistent.list.PersistentList):
         return list(o)
     elif isinstance(o, persistent.mapping.PersistentMapping):
         return dict(o)
     else:
         return json.JSONEncoder.default(self, o)
コード例 #3
0
ファイル: catalog.py プロジェクト: ale-rt/zc.relation
 def removeDefaultQueryFactory(self, factory):
     res = list(self._queryFactories)
     try:
         res.remove(factory)
     except ValueError:
         raise LookupError('factory not found', factory)
     self._queryFactories = tuple(res)
コード例 #4
0
ファイル: zodb_backend.py プロジェクト: lexBuright/qscli
def _zodb_json_object_hook(input_dict):
    d = input_dict.copy()

    for k in list(d.keys()):
        if isinstance(d[k], list):
            d[k] = persistent.list.PersistentList(d[k])
    result = persistent.mapping.PersistentMapping(d)
    return result
コード例 #5
0
 def prepare():
     self._check_reassigned(statuses)
     self._status_id = 1  # ACTIVE
     self._active_start = datetime.datetime.now(pytz.UTC)
     effective_args = list(args)
     effective_args[0:0] = self.args
     effective_kwargs = dict(self.kwargs)
     effective_kwargs.update(kwargs)
     return effective_args, effective_kwargs
コード例 #6
0
    def __exit__(self, _, __, ___):
        """Ensure all sessions are closed"""

        # Retrieve the existing session IDs list
        session_ids = list(self.sessions.keys())

        # Close each session based on its ``session_id``
        for session_id in session_ids:
            self.sessions[session_id].close()
コード例 #7
0
ファイル: job.py プロジェクト: upiq/zc.async
 def prepare():
     self._check_reassigned(statuses)
     self._status_id = 1 # ACTIVE
     self._active_start = datetime.datetime.now(pytz.UTC)
     effective_args = list(args)
     effective_args[0:0] = self.args
     effective_kwargs = dict(self.kwargs)
     effective_kwargs.update(kwargs)
     return effective_args, effective_kwargs
コード例 #8
0
ファイル: contractstorage.py プロジェクト: zzzxxxbbb/mythril
    def search(self, expression, callback_func):

        all_keys = list(self.contracts)

        for k in all_keys:

            if self.contracts[k].matches_expression(expression):
                m = self.instance_lists[k]

                callback_func(k.hex(), self.contracts[k], m.addresses,
                              m.balances)
コード例 #9
0
ファイル: serialize.py プロジェクト: tonich-sh/pjpersist
    def resolve(self, dbref, no_cache=False, use_broken=True):

        # 0. Use DBREF_RESOLVE_CACHE
        if not no_cache:
            klass = DBREF_RESOLVE_CACHE.get(dbref.as_key())
            if klass is not None:
                return prepare_class(klass)

        # 1. Try to optimize on whether there's just one class stored in one
        #    table, that can save us one DB query
        if dbref.table in TABLE_KLASS_MAP:
            results = TABLE_KLASS_MAP[dbref.table]
            if len(results) == 1:
                # there must be just ONE, otherwise we need to check the JSONB
                klass = list(results)[0]
                DBREF_RESOLVE_CACHE.put(dbref.as_key(), klass)
                return prepare_class(klass)

        # from this point on we need the dbref.id
        if dbref.id is None:
            if use_broken:
                return broken.Broken
            else:
                raise ImportError(dbref)
        # 2. Get the class from the object state
        #    Multiple object types are stored in the table. We have to
        #    look at the object (JSONB) to find out the type.
        if ALWAYS_READ_FULL_DOC:
            # Optimization: Read the entire doc and stick it in the right
            # place so that unghostifying the object later will not cause
            # another database access.
            obj_doc = self._jar._get_doc_by_dbref(dbref)
        else:
            # Just read the type from the database, still requires one query
            pytype = self._jar._get_doc_py_type(
                dbref.database, dbref.table, dbref.id)
            obj_doc = {interfaces.ATTR_NAME_PY_TYPE: pytype}
        if obj_doc is None:
            # There is no document for this reference in the database.
            if use_broken:
                return broken.Broken
            else:
                raise ImportError(dbref)
        if interfaces.ATTR_NAME_PY_TYPE in obj_doc:
            # We have always the path to the class in JSONB
            klass = self.simple_resolve(obj_doc[interfaces.ATTR_NAME_PY_TYPE], use_broken=use_broken)
        else:
            if use_broken:
                return broken.Broken
            else:
                raise ImportError(dbref)
        DBREF_RESOLVE_CACHE.put(dbref.as_key(), klass)
        return prepare_class(klass)
コード例 #10
0
ファイル: tournaments.py プロジェクト: syniosis76/tourney
 def toJson(self, email = None, admin = False):
     tournaments = self.list
     #if (admin):
     #    tournaments = [x for x in self.list if x.canEdit(email)]
         
     sortedList = sorted(tournaments, key=lambda tournament: tournament.startDate, reverse=True)
     resultList = list(map(lambda tournament: tournament.basicDict(), sortedList))
     result = {}        
     result['tournaments'] = resultList
     canEdit = self.canEdit(email)
     result['canEdit'] = canEdit
     if canEdit: result['administrators'] = self.get_administrators()
     return json.dumps(result)
コード例 #11
0
    def search(self, expression, callback_func):

        all_keys = list(self.contracts)

        for k in all_keys:

            if self.contracts[k].matches_expression(expression):

                m = hashlib.md5()
                m.update(self.contracts[k].code.encode('UTF-8'))
                contract_hash = m.digest()

                m = self.instance_lists[contract_hash]

                callback_func(contract_hash.hex(), self.contracts[k], m.addresses, m.balances)
コード例 #12
0
 def resolve(self, dbref):
     __traceback_info__ = dbref
     # 1. Try to optimize on whether there's just one class stored in one
     #    table, that can save us one DB query
     if dbref.table in TABLE_KLASS_MAP:
         results = TABLE_KLASS_MAP[dbref.table]
         if len(results) == 1:
             # there must be just ONE, otherwise we need to check the JSONB
             klass = list(results)[0]
             return klass
     # from this point on we need the dbref.id
     if dbref.id is None:
         raise ImportError(dbref)
     # 2. Get the class from the object state
     #    Multiple object types are stored in the table. We have to
     #    look at the object (JSONB) to find out the type.
     if dbref in self._jar._latest_states:
         # Optimization: If we have the latest state, then we just get
         # this object document. This is used for fast loading or when
         # resolving the same object path a second time. (The latter
         # should never happen due to the object cache.)
         obj_doc = self._jar._latest_states[dbref]
     elif ALWAYS_READ_FULL_DOC:
         # Optimization: Read the entire doc and stick it in the right
         # place so that unghostifying the object later will not cause
         # another database access.
         obj_doc = self._jar._get_doc_by_dbref(dbref)
         # Do not pollute the latest states because the ref could not be
         # found.
         if obj_doc is not None:
             self._jar._latest_states[dbref] = obj_doc
     else:
         # Just read the type from the database, still requires one query
         pytype = self._jar._get_doc_py_type(dbref.database, dbref.table,
                                             dbref.id)
         obj_doc = {interfaces.PY_TYPE_ATTR_NAME: pytype}
     if obj_doc is None:
         # There is no document for this reference in the database.
         raise ImportError(dbref)
     if interfaces.PY_TYPE_ATTR_NAME in obj_doc:
         # We have always the path to the class in JSONB
         klass = self.simple_resolve(obj_doc[interfaces.PY_TYPE_ATTR_NAME])
     else:
         raise ImportError(dbref)
     return klass
コード例 #13
0
ファイル: serialize.py プロジェクト: agroszer/pjpersist
 def resolve(self, dbref):
     __traceback_info__ = dbref
     # 1. Try to optimize on whether there's just one class stored in one
     #    table, that can save us one DB query
     if dbref.table in TABLE_KLASS_MAP:
         results = TABLE_KLASS_MAP[dbref.table]
         if len(results) == 1:
             # there must be just ONE, otherwise we need to check the JSONB
             klass = list(results)[0]
             return klass
     # from this point on we need the dbref.id
     if dbref.id is None:
         raise ImportError(dbref)
     # 2. Get the class from the object state
     #    Multiple object types are stored in the table. We have to
     #    look at the object (JSONB) to find out the type.
     if dbref in self._jar._latest_states:
         # Optimization: If we have the latest state, then we just get
         # this object document. This is used for fast loading or when
         # resolving the same object path a second time. (The latter
         # should never happen due to the object cache.)
         obj_doc = self._jar._latest_states[dbref]
     elif ALWAYS_READ_FULL_DOC:
         # Optimization: Read the entire doc and stick it in the right
         # place so that unghostifying the object later will not cause
         # another database access.
         obj_doc = self._jar._get_doc_by_dbref(dbref)
         # Do not pollute the latest states because the ref could not be
         # found.
         if obj_doc is not None:
             self._jar._latest_states[dbref] = obj_doc
     else:
         # Just read the type from the database, still requires one query
         pytype = self._jar._get_doc_py_type(
             dbref.database, dbref.table, dbref.id)
         obj_doc = {interfaces.PY_TYPE_ATTR_NAME: pytype}
     if obj_doc is None:
         # There is no document for this reference in the database.
         raise ImportError(dbref)
     if interfaces.PY_TYPE_ATTR_NAME in obj_doc:
         # We have always the path to the class in JSONB
         klass = self.simple_resolve(obj_doc[interfaces.PY_TYPE_ATTR_NAME])
     else:
         raise ImportError(dbref)
     return klass
コード例 #14
0
    def get_jid_by_base64(self, type_, base64):

        db_con = self.rtenv.db.open()
        con_root = db_con.root

        b64_1 = ''.join(base64.splitlines())

        ret = set()

        for k, v in con_root.wayround_i2p_gitpub_public_keys.items():
            if v['msg_type_part'] == type_:
                if b64_1 == ''.join(v['msg_base64_part'].splitlines()):
                    ret.add(wayround_i2p.xmpp.core.jid_to_bare(k))

        transaction.commit()
        db_con.close()

        return list(ret)
コード例 #15
0
ファイル: workitem.py プロジェクト: gocept/gocept.alphaflow
 def listRelevantUsers(self):
     if ILifeCycleController(self).state != "active":
         return []
     activity = self.getActivity()
     assert IAssignableActivity.providedBy(activity)
     if activity.assigneesKind == 'possible':
         relevant = self.getActivityConfiguration("assignees")
         if not isinstance(relevant, (list, tuple)):
             relevant = []
     else:
         if activity.assigneesExpression is not None:
             relevant = utils.evaluateTales(activity.assigneesExpression,
                                            workitem=self)
             groupstool = getToolByName(self, "portal_groups")
             relevant = utils.expandGroups(groupstool, relevant)
         elif activity.roles:
             # we have roles
             roles = activity.roles
             relevant = self.listMembersWithRolesOnContentObject(roles)
         else:
             # we have groups
             gt = getToolByName(self, 'portal_groups')
             relevant = utils.expandGroups(gt, activity.groups)
     return list(relevant)
コード例 #16
0
            self._status_id = 0  # NEW
            self._active_start = None
            self(result)
        else:
            zc. async .utils.tracelog.debug(
                'aborting interrupted callback '
                '%r to %r', self, caller)
            self.fail(zc. async .interfaces.AbortedError())

    def resumeCallbacks(self):
        # should be called within a job that has a RetryCommonForever policy
        if self.status != zc. async .interfaces.CALLBACKS:
            raise zc. async .interfaces.BadStatusError(
                'can only resumeCallbacks on a job with CALLBACKS status')
        self._check_reassigned((zc. async .interfaces.CALLBACKS, ))
        callbacks = list(self.callbacks)
        tm = transaction.interfaces.ITransactionManager(self)
        length = 0
        while 1:
            for j in callbacks:
                self._check_reassigned((zc. async .interfaces.CALLBACKS, ))
                if zc. async .interfaces.ICallbackProxy.providedBy(j):
                    j = j.getJob(self.result)
                status = j.status
                if status in (zc. async .interfaces.NEW,
                              zc. async .interfaces.ASSIGNED,
                              zc. async .interfaces.PENDING):
                    if (j.begin_by is not None and (j.begin_after + j.begin_by)
                            < datetime.datetime.now(pytz.UTC)):
                        zc. async .utils.log.error(
                            'failing expired callback %r to %r', j, self)
コード例 #17
0
ファイル: job.py プロジェクト: upiq/zc.async
            self._status_id = 0 # NEW
            self._active_start = None
            self(result)
        else:
            zc.async.utils.tracelog.debug(
                'aborting interrupted callback '
                '%r to %r', self, caller)
            self.fail(zc.async.interfaces.AbortedError())

    def resumeCallbacks(self):
        # should be called within a job that has a RetryCommonForever policy
        if self.status != zc.async.interfaces.CALLBACKS:
            raise zc.async.interfaces.BadStatusError(
                'can only resumeCallbacks on a job with CALLBACKS status')
        self._check_reassigned((zc.async.interfaces.CALLBACKS,))
        callbacks = list(self.callbacks)
        tm = transaction.interfaces.ITransactionManager(self)
        length = 0
        while 1:
            for j in callbacks:
                self._check_reassigned((zc.async.interfaces.CALLBACKS,))
                if zc.async.interfaces.ICallbackProxy.providedBy(j):
                    j = j.getJob(self.result)
                status = j.status
                if status in (zc.async.interfaces.NEW,
                              zc.async.interfaces.ASSIGNED,
                              zc.async.interfaces.PENDING):
                    if (j.begin_by is not None and
                        (j.begin_after + j.begin_by) <
                        datetime.datetime.now(pytz.UTC)):
                        zc.async.utils.log.error(
コード例 #18
0
ファイル: nodeops.py プロジェクト: dpedu/docker-nodepupper
 def class_names(self):
     return list(self.classes.keys())