示例#1
0
 def rename(self):
     # And issuing the rename is surprisingly straightforward.
     p = self.src.rename(self.dest.asBytes())
     self.resolver.resolve(p)
     # At last, done with fs. No need to unstash; it was already unstashed
     # in the callback. (We're being called *from the callback*.)
     ruv.fsDiscard(self.fs)
示例#2
0
文件: files.py 项目: dckc/typhon
 def rename(self):
     # And issuing the rename is surprisingly straightforward.
     p = self.src.rename(self.dest.asBytes())
     self.resolver.resolve(p)
     # At last, done with fs. No need to unstash; it was already unstashed
     # in the callback. (We're being called *from the callback*.)
     ruv.fsDiscard(self.fs)
示例#3
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"
示例#4
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"
示例#5
0
文件: files.py 项目: dckc/typhon
def openSetContentsCB(fs):
    try:
        fd = intmask(fs.c_result)
        with ruv.unstashingFS(fs) as (vat, sc):
            assert isinstance(sc, SetContents)
            if fd < 0:
                msg = ruv.formatError(fd).decode("utf-8")
                sc.fail(u"Couldn't open file fount: %s" % msg)
                # Done with fs.
                ruv.fsDiscard(fs)
            else:
                sc.startWriting(fd, fs)
    except:
        print "Exception in openSetContentsCB"
示例#6
0
def openSetContentsCB(fs):
    try:
        fd = intmask(fs.c_result)
        with ruv.unstashingFS(fs) as (vat, sc):
            assert isinstance(sc, SetContents)
            if fd < 0:
                msg = ruv.formatError(fd).decode("utf-8")
                sc.fail(u"Couldn't open file fount: %s" % msg)
                # Done with fs.
                ruv.fsDiscard(fs)
            else:
                sc.startWriting(fd, fs)
    except:
        print "Exception in openSetContentsCB"
示例#7
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)
示例#8
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"
示例#9
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"
示例#10
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"
示例#11
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"
示例#12
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"
示例#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"