Exemplo n.º 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)
Exemplo n.º 2
0
Arquivo: files.py Projeto: 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)
Exemplo n.º 3
0
Arquivo: files.py Projeto: 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"
Exemplo n.º 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"
Exemplo n.º 5
0
Arquivo: files.py Projeto: 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"
Exemplo n.º 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"
Exemplo n.º 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)
Exemplo n.º 8
0
Arquivo: files.py Projeto: 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"
Exemplo n.º 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"
Exemplo n.º 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"
Exemplo n.º 11
0
Arquivo: files.py Projeto: 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"
Exemplo n.º 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"
Exemplo n.º 13
0
Arquivo: files.py Projeto: 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"
Exemplo n.º 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"