コード例 #1
0
    def connect(self, host, port=15000):
        self.sock.connect((host, port))
        # and ensure correct port
        self._handshake()
        if "[version]" not in self.receive_string():
            raise WesException("Server did not ask for version").quit()

        self.send_wml_string('[version]\nversion="' + self.wesnothVersion +
                             '"\n[/version]\n')

        response = self.receive_string()
        parser = wmlparser.Parser(None)
        wml = parser.parse_text(response)
        result = {}
        if type(wml) is wmlparser.RootNode:
            wml = wml.get_all()
            for i in wml:
                for j in i.get_all():
                    result[j.get_name()] = j.get_text()
        if "port" in result:
            self.main.log.debug("need to use different port %s", result)
            self.shutdown()
            self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            self.sock.settimeout(WesSock.socketTimeout)
            self.connect(result["host"], int(result["port"]))
コード例 #2
0
def read_file(filename, root_name="WML"):
    """
    Read in a file from disk and return a WML data object, with the WML in the
    file placed under an entry with the name root_name.
    """
    parser = wmlparser.Parser(None)
    parser.parse_file(filename)
    data = DataSub(root_name)
    parser.parse_top(data)
    return data
コード例 #3
0
 def __init__(self, main: 'WesBot'):
     self.log_cutoff_len = 500
     self.main = main
     self.cmd = main.commandHandler
     self.parser = wmlparser.Parser(None)