Exemplo n.º 1
0
    def decode_WML(self, data):
        p = wmlparser.Parser(None, no_macros_in_string=True)
        p.verbose = False
        p.do_preprocessor_logic = True
        p.no_macros = True
        p.parse_text(data, binary=True)
        doc = wmldata.DataSub("WML")
        p.parse_top(doc)

        return doc

        def done():
            return pos[0] >= len(data)

        def next():
            c = data[pos[0]]
            pos[0] += 1
            return c

        def literal():
            s = pos[0]
            e = data.find("\00", s)

            pack = data[s:e]

            pack = pack.replace("\01\01", "\00")
            pack = pack.replace("\01\02", "\01")

            pos[0] = e + 1

            return pack

        while not done():
            code = ord(next())
            if code == 0:  # open element (name code follows)
                open_element = True
            elif code == 1:  # close current element
                tag.pop()
            elif code == 2:  # add code
                self.words[self.wordcount] = literal()
                self.wordcount += 1
            else:
                if code == 3:
                    word = literal()  # literal word
                else:
                    word = self.words[code]  # code
                if open_element:  # we handle opening an element
                    element = wmldata.DataSub(word)
                    tag[-1].insert(element)  # add it to the current one
                    tag.append(element)  # put to our stack to keep track
                elif word == "contents":  # detect any binary attributes
                    binary = wmldata.DataBinary(word, literal())
                    tag[-1].insert(binary)
                else:  # others are text attributes
                    text = wmldata.DataText(word, literal())
                    tag[-1].insert(text)
                open_element = False

        return WML
Exemplo n.º 2
0
    def get_campaign_raw(self, name):
        """
        Downloads the named campaign and returns it as a raw binary WML packet.
        """
        request = wmldata.DataSub("request_campaign")
        request.insert(wmldata.DataText("name", name))
        self.send_packet(self.make_packet(request))
        raw_packet = self.read_packet()

        if self.canceled:
            return None

        return raw_packet
Exemplo n.º 3
0
        def put_file(name, f):
            for ig in ign:
                if ig[-1] != "/" and fnmatch.fnmatch(name, ig):
                    print("Ignored file", name)
                    return None
            fileNode = wmldata.DataSub("file")

            # Order in which we apply escape sequences matters.
            contents = f.read()
            contents = contents.replace("\x01", "\x01\x02")
            contents = contents.replace("\x00", "\x01\x01")
            contents = contents.replace("\x0d", "\x01\x0e")
            contents = contents.replace("\xfe", "\x01\xff")

            fileContents = wmldata.DataText("contents", contents)
            fileNode.insert(fileContents)
            fileNode.set_text_val("name", name)

            return fileNode