How to use the twisted.internet.defer.returnValue function in Twisted

To help you get started, we’ve selected a few Twisted 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 apple / ccs-calendarserver / calendarserver / tools / shell / vfs.py View on Github external
    @inlineCallbacks
    def child(self, name):
        # FIXME: Move this logic to locate()
        # if not name:
        #     return succeed(self)
        # if name == ".":
        #     return succeed(self)
        # if name == "..":
        #     path = self.path[:-1]
        #     if not path:
        #         path = "/"
        #     return RootFolder(self.service).locate(path)

        if name in self._children:
            returnValue(self._children[name])

        if name in self._childClasses:
            child = (yield self._childClasses[name](self.service, self.path + (name,)))
            self._children[name] = child
            returnValue(child)

        raise NotFoundError("Folder %r has no child %r" % (str(self), name))
github apple / ccs-calendarserver / twistedcaldav / sharing.py View on Github external
    @inlineCallbacks
    def declineShare(self, request, inviteUID):

        # Remove it if it is in the DB
        try:
            result = yield self._newStoreHome.declineShare(inviteUID)
        except DirectoryRecordNotFoundError:
            # Missing sharer record => just treat decline as success
            result = True
        if not result:
            raise HTTPError(ErrorResponse(
                responsecode.FORBIDDEN,
                (calendarserver_namespace, "invalid-share"),
                "Invite UID not valid",
            ))
        returnValue(Response(code=responsecode.NO_CONTENT))
github NORDUnet / opennsa / opennsa / backends / oess.py View on Github external
def oess_get_circuits(conn, workgroup_id):
    query = 'services/data.cgi?'
    query += 'action=get_existing_circuits&workgroup_id=%s' % workgroup_id
    retval = yield http_query(conn, query)
    defer.returnValue(retval)
github opencord / voltha / voltha / core / dispatcher.py View on Github external
    @inlineCallbacks
    def _connect_to_peer(self, host, port):
        try:
            channel = yield grpc.insecure_channel('{}:{}'.format(host, port))
            log.info('grpc-channel-created-with-peer', peer=host)
            returnValue(channel)
        except Exception, e:
            log.exception('exception', e=e)
github Uninett / nav / python / nav / ipdevpoll / plugins / statsystem.py View on Github external
else:
                if mem:
                    self._logger.debug("Found memory values from %s: %r",
                                       mib.mib['moduleName'], mem)
                    memory.update(mem)

        timestamp = time.time()
        result = []
        for name, (used, free) in memory.items():
            for netbox in netboxes:
                prefix = metric_prefix_for_memory(netbox, name)
                result.extend([
                    (prefix + '.used', (timestamp, used)),
                    (prefix + '.free', (timestamp, free)),
                ])
        defer.returnValue(result)
github labrad / pylabrad / labrad / protocol.py View on Github external
indices, names = [], []
            # send the actual lookup request
            recs = [(C.LOOKUP, (server, names), ['w*s', 's*s'])]
            resp = yield self._sendRequestNoLookup(C.MANAGER_ID, recs)
            serverID, IDs = resp[0][1]
            # cache the results
            if isinstance(server, str):
                self._serverCache[server] = serverID
            server = serverID
            settings = self._settingCache.setdefault(server, {})
            settings.update(zip(names, IDs))
            # update the records for the packet
            for index, ID in zip(indices, IDs):
                records[index] = (ID,) + tuple(records[index][1:])

        returnValue((server, records))
github apple / ccs-calendarserver / txdav / common / datastore / sql_util.py View on Github external
found = bool((
                yield self._insertFindPreviouslyNamedQuery.on(
                    self._txn, resourceID=self._resourceID, name=name)))
            if found:
                self._syncTokenRevision = (
                    yield self._updatePreviouslyNamedQuery.on(
                        self._txn, resourceID=self._resourceID, name=name)
                )[0][0]
            else:
                self._syncTokenRevision = (
                    yield self._completelyNewRevisionQuery.on(
                        self._txn, homeID=self.ownerHome()._resourceID,
                        resourceID=self._resourceID, name=name)
                )[0][0]
        yield self._maybeNotify()
        returnValue(self._syncTokenRevision)
github Uninett / nav / python / nav / ipdevpoll / plugins / modules.py View on Github external
def _need_to_collect(self):
        yield self.stampcheck.load()
        yield self.stampcheck.collect([self.entitymib.get_last_change_time()])

        result = yield self.stampcheck.is_changed()
        defer.returnValue(result)
github codenode / codenode / codenode / frontend / async / backend.py View on Github external
def _send(self, access_id, msg):
        """
        Send to backend engine.
        """
        url = os.path.join(self.base_url, 'engine', str(access_id))
        result = yield getPage(url,
                        contextFactory=None,
                        method='POST',
                        postdata=str(msg))
        defer.returnValue(result)
github matrix-org / synapse / synapse / storage / roommember.py View on Github external
def get_invite_for_user_in_room(self, user_id, room_id):
        """Gets the invite for the given user and room

        Args:
            user_id (str)
            room_id (str)

        Returns:
            Deferred: Resolves to either a RoomsForUser or None if no invite was
                found.
        """
        invites = yield self.get_invited_rooms_for_user(user_id)
        for invite in invites:
            if invite.room_id == room_id:
                defer.returnValue(invite)
        defer.returnValue(None)