Atlas 0.7.0
Networking protocol for the Worldforge system.
xml2.py
1#experimental XML2 codec
2
3#Copyright 2001 by Aloril
4
5#This library is free software; you can redistribute it and/or
6#modify it under the terms of the GNU Lesser General Public
7#License as published by the Free Software Foundation; either
8#version 2.1 of the License, or (at your option) any later version.
9
10#This library is distributed in the hope that it will be useful,
11#but WITHOUT ANY WARRANTY; without even the implied warranty of
12#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13#Lesser General Public License for more details.
14
15#You should have received a copy of the GNU Lesser General Public
16#License along with this library; if not, write to the Free Software
17#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19
20import string
21from atlas.typemap import *
22
23from . import gen_xml, parse_xml
24
25def gen_xml2(obj):
26 gen = GenerateXML2()
27 return gen.encode(obj)
28
29attribute_type_dict = {
30 'abstract_type': 'string',
31 'action': 'string',
32 'age': 'float',
33 'alcahol': 'int',
34 'ammo': 'string',
35 'args': 'list',
36 'atlas_name': 'string',
37 'auto': 'int',
38 'bbox': 'list',
39 'burn_speed': 'float',
40 'characters': 'list',
41 'contains': 'list',
42 'cooked': 'int',
43 'coords': 'list',
44 'copy': 'string',
45 'description': 'string',
46 'drunkness': 'float',
47 'face': 'list',
48 'from': 'string',
49 'fruitchance': 'int',
50 'fruitname': 'string',
51 'fruits': 'int',
52 'future_seconds': 'float',
53 'height': 'int',
54 'id': 'string',
55 'init_fruits': 'int',
56 'key': 'string',
57 'loc': 'string',
58 'material': 'string',
59 'maxweight': 'float',
60 'message': 'string',
61 'mode': 'string',
62 'name': 'string',
63 'objtype': 'string',
64 'op': 'map',
65 'parent': 'string',
66 'password': 'string',
67 'place': 'string',
68 'pos': 'list',
69 'rain': 'float',
70 'ref': 'string',
71 'refno': 'int',
72 'say': 'string',
73 'seconds': 'float',
74 'serialno': 'int',
75 'sex': 'string',
76 'sizename': 'string',
77 'snow': 'float',
78 'stamp': 'float',
79 'stamp_contains': 'float',
80 'status': 'float',
81 'time': 'map',
82 'time_string': 'string',
83 'to': 'string',
84 'type': 'string',
85 'value': 'string',
86 'velocity': 'list',
87 'weight': 'float',
88 'what': 'string'
89}
90
92 def encode_attribute(self, indent, name, str_type, str_value):
93 attribute_type_dict[name] = str_type
94 return '%s<%s>%s</%s>' % \
95 (indent, name, str_value, name)
96
98
100 def unknown_starttag(self, tag, attributes):
101 method_name = "start_" + attribute_type_dict.get(tag, "")
102 if hasattr(self, method_name):
103 method = getattr(self, method_name)
104 attributes["name"] = tag
105 return method(attributes)
106 raise XmlException("Unknown tag: "+tag)
107
108 def unknown_endtag(self, tag):
109 method_name = "end_" + attribute_type_dict.get(tag, "")
110 if hasattr(self, method_name):
111 method = getattr(self, method_name)
112 return method()
113 raise XmlException("Unknown tag: "+tag)
114
115
116def get_parser():
117 xml2_msg_parser=XML2Parser()
118 xml2_msg_parser.setup()
119 return xml2_msg_parser