예제 #1
0
def renameCB(fs):
    try:
        success = intmask(fs.c_result)
        vat, r = ruv.unstashFS(fs)
        if success < 0:
            msg = ruv.formatError(success).decode("utf-8")
            r.smash(StrObject(u"Couldn't rename file: %s" % msg))
        else:
            r.resolve(NullObject)
        # Done with fs.
        ruv.fsDiscard(fs)
    except:
        print "Exception in renameCB"
예제 #2
0
파일: files.py 프로젝트: dckc/typhon
def renameCB(fs):
    try:
        success = intmask(fs.c_result)
        vat, r = ruv.unstashFS(fs)
        if success < 0:
            msg = ruv.formatError(success).decode("utf-8")
            r.smash(StrObject(u"Couldn't rename file: %s" % msg))
        else:
            r.resolve(NullObject)
        # Done with fs.
        ruv.fsDiscard(fs)
    except:
        print "Exception in renameCB"
예제 #3
0
파일: files.py 프로젝트: dckc/typhon
def closeSetContentsCB(fs):
    try:
        vat, sc = ruv.unstashFS(fs)
        # Need to scope vat here.
        with scopedVat(vat):
            assert isinstance(sc, SetContents)
            size = intmask(fs.c_result)
            if size < 0:
                msg = ruv.formatError(size).decode("utf-8")
                sc.fail(u"libuv error: %s" % msg)
            else:
                # Success.
                sc.rename()
    except:
        print "Exception in closeSetContentsCB"
예제 #4
0
def readFileCB(fs):
    size = intmask(fs.c_result)
    vat, source = ruv.unstashFS(fs)
    assert isinstance(source, FileSource)
    with scopedVat(vat):
        if size > 0:
            data = charpsize2str(source._buf.c_base, size)
            source.deliver(data)
        elif size < 0:
            msg = ruv.formatError(size).decode("utf-8")
            source.abort(u"libuv error: %s" % msg)
        else:
            # EOF.
            source.complete()
    ruv.fsDiscard(fs)
예제 #5
0
def closeSetContentsCB(fs):
    try:
        vat, sc = ruv.unstashFS(fs)
        # Need to scope vat here.
        with scopedVat(vat):
            assert isinstance(sc, SetContents)
            size = intmask(fs.c_result)
            if size < 0:
                msg = ruv.formatError(size).decode("utf-8")
                sc.fail(u"libuv error: %s" % msg)
            else:
                # Success.
                sc.rename()
    except:
        print "Exception in closeSetContentsCB"
예제 #6
0
파일: files.py 프로젝트: dckc/typhon
def openDrainCB(fs):
    # As above.
    try:
        fd = intmask(fs.c_result)
        vat, r = ruv.unstashFS(fs)
        assert isinstance(r, LocalResolver)
        with scopedVat(vat):
            if fd < 0:
                msg = ruv.formatError(fd).decode("utf-8")
                r.smash(StrObject(u"Couldn't open file drain: %s" % msg))
                # Done with fs.
                ruv.fsDiscard(fs)
            else:
                r.resolve(FileDrain(fs, fd, vat))
    except:
        print "Exception in openDrainCB"
예제 #7
0
def writeFileCB(fs):
    try:
        vat, sb = ruv.unstashFS(fs)
        sink = sb.obj
        assert isinstance(sink, FileSink)
        size = intmask(fs.c_result)
        if size > 0:
            # XXX backpressure drain.written(size)
            pass
        elif size < 0:
            msg = ruv.formatError(size).decode("utf-8")
            sink.abort(StrObject(u"libuv error: %s" % msg))
        sb.deallocate()
        ruv.fsDiscard(fs)
    except:
        print "Exception in writeFileCB"
예제 #8
0
def openDrainCB(fs):
    # As above.
    try:
        fd = intmask(fs.c_result)
        vat, r = ruv.unstashFS(fs)
        assert isinstance(r, LocalResolver)
        with scopedVat(vat):
            if fd < 0:
                msg = ruv.formatError(fd).decode("utf-8")
                r.smash(StrObject(u"Couldn't open file drain: %s" % msg))
                # Done with fs.
                ruv.fsDiscard(fs)
            else:
                r.resolve(FileDrain(fs, fd, vat))
    except:
        print "Exception in openDrainCB"
예제 #9
0
파일: files.py 프로젝트: dckc/typhon
def openFountCB(fs):
    # Does *not* run user-level code. The scoped vat is only for promise
    # resolution.
    try:
        fd = intmask(fs.c_result)
        vat, r = ruv.unstashFS(fs)
        assert isinstance(r, LocalResolver)
        with scopedVat(vat):
            if fd < 0:
                msg = ruv.formatError(fd).decode("utf-8")
                r.smash(StrObject(u"Couldn't open file fount: %s" % msg))
                # Done with fs.
                ruv.fsDiscard(fs)
            else:
                r.resolve(FileFount(fs, fd, vat))
    except:
        print "Exception in openFountCB"
예제 #10
0
def openFountCB(fs):
    # Does *not* run user-level code. The scoped vat is only for promise
    # resolution.
    try:
        fd = intmask(fs.c_result)
        vat, r = ruv.unstashFS(fs)
        assert isinstance(r, LocalResolver)
        with scopedVat(vat):
            if fd < 0:
                msg = ruv.formatError(fd).decode("utf-8")
                r.smash(StrObject(u"Couldn't open file fount: %s" % msg))
                # Done with fs.
                ruv.fsDiscard(fs)
            else:
                r.resolve(FileFount(fs, fd, vat))
    except:
        print "Exception in openFountCB"
예제 #11
0
파일: files.py 프로젝트: dckc/typhon
def getContentsCB(fs):
    try:
        size = intmask(fs.c_result)
        # Don't use with-statements here; instead, each next action in
        # GetContents will re-stash if necessary. ~ C.
        vat, self = ruv.unstashFS(fs)
        assert isinstance(self, GetContents)
        if size > 0:
            data = charpsize2str(self.buf.c_base, size)
            self.append(data)
        elif size < 0:
            msg = ruv.formatError(size).decode("utf-8")
            self.fail(msg)
        else:
            # End of file! Complete the callback.
            self.succeed()
    except Exception:
        print "Exception in getContentsCB"
예제 #12
0
def getContentsCB(fs):
    try:
        size = intmask(fs.c_result)
        # Don't use with-statements here; instead, each next action in
        # GetContents will re-stash if necessary. ~ C.
        vat, self = ruv.unstashFS(fs)
        assert isinstance(self, GetContents)
        if size > 0:
            data = charpsize2str(self.buf.c_base, size)
            self.append(data)
        elif size < 0:
            msg = ruv.formatError(size).decode("utf-8")
            self.fail(msg)
        else:
            # End of file! Complete the callback.
            self.succeed()
    except Exception:
        print "Exception in getContentsCB"
예제 #13
0
파일: files.py 프로젝트: dckc/typhon
def openGetContentsCB(fs):
    try:
        fd = intmask(fs.c_result)
        vat, r = ruv.unstashFS(fs)
        assert isinstance(r, LocalResolver)
        with scopedVat(vat):
            if fd < 0:
                msg = ruv.formatError(fd).decode("utf-8")
                r.smash(StrObject(u"Couldn't open file fount: %s" % msg))
                # Done with fs.
                ruv.fsDiscard(fs)
            else:
                # Strategy: Read and use the callback to queue additional reads
                # until done. This call is known to its caller to be expensive, so
                # there's not much point in trying to be clever about things yet.
                gc = GetContents(vat, fs, fd, r)
                gc.queueRead()
    except:
        print "Exception in openGetContentsCB"
예제 #14
0
def openGetContentsCB(fs):
    try:
        fd = intmask(fs.c_result)
        vat, r = ruv.unstashFS(fs)
        assert isinstance(r, LocalResolver)
        with scopedVat(vat):
            if fd < 0:
                msg = ruv.formatError(fd).decode("utf-8")
                r.smash(StrObject(u"Couldn't open file fount: %s" % msg))
                # Done with fs.
                ruv.fsDiscard(fs)
            else:
                # Strategy: Read and use the callback to queue additional reads
                # until done. This call is known to its caller to be expensive, so
                # there's not much point in trying to be clever about things yet.
                gc = GetContents(vat, fs, fd, r)
                gc.queueRead()
    except:
        print "Exception in openGetContentsCB"