示例#1
0
        return set.__new__(cls)

    def __setstate__(self, state):
        if isinstance(state, tuple):
            self.update(state[0].keys())
        else:
            self.update(state)

class Sentinel(magic.FakeStrict, object):
    __module__ = "renpy.object"
    def __new__(cls, name):
        obj = object.__new__(cls)
        obj.name = name
        return obj

factory = magic.FakeClassFactory((PyExpr, PyCode, RevertableList, RevertableDict, RevertableSet, Sentinel), magic.FakeStrict)

def read_ast_from_file(raw_contents):
    # .rpyc files are just zlib compressed pickles of a tuple of some data and the actual AST of the file
    if raw_contents.startswith("RENPY RPC2"):
        # parse the archive structure
        position = 10
        chunks = {}
        while True:
            slot, start, length = struct.unpack("III", raw_contents[position: position + 12])
            if slot == 0:
                break
            position += 12

            chunks[slot] = raw_contents[start: start + length]
示例#2
0
    def __new__(cls, s, filename, linenumber):
        self = unicode.__new__(cls, s)
        self.filename = filename
        self.linenumber = linenumber
        return self


class PyCode(magic.FakeStrict):
    __module__ = "renpy.ast"

    def __setstate__(self, state):
        (_, self.source, self.location, self.mode) = state
        self.bytecode = None


factory = magic.FakeClassFactory((PyExpr, PyCode), magic.FakeStrict)


def read_ast_from_file(raw_contents):
    # .rpyc files are just zlib compressed pickles of a tuple of some data and the actual AST of the file
    if raw_contents.startswith("RENPY RPC2"):
        # parse the archive structure
        position = 10
        chunks = {}
        while True:
            slot, start, length = struct.unpack(
                "III", raw_contents[position:position + 12])
            if slot == 0:
                break
            position += 12