Skip to content

Commit

Permalink
l2/converter xml->py C/S side
Browse files Browse the repository at this point in the history
  • Loading branch information
yv84 committed Sep 17, 2014
1 parent 4d7c293 commit e0597a4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
32 changes: 24 additions & 8 deletions src/l2/converter/test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def dtype(act, data):
dtype = [('pck_type', 'i1')]
return dtype
pck["00"] = c_Logout"""
pck_client["00"] = c_Logout"""
self.ini_to_xml.side = b"client"
self.assertEqual(
self.xml_string_trim(
Expand Down Expand Up @@ -90,7 +90,7 @@ def dtype(act, data):
dtype = [('pck_type', 'i1'), ('ObjectID', 'i4'), ('OrigX', 'i4'), ('OrigY', 'i4'), ('OrigZ', 'i4'), ('AttackClick', 'i1')]
return dtype
pck["01"] = c_AttackRequest"""
pck_client["01"] = c_AttackRequest"""
self.ini_to_xml.side = b"client"
self.assertEqual(
self.xml_string_trim(
Expand Down Expand Up @@ -120,16 +120,13 @@ def dtype(act, data):
dtype = [('pck_type', 'i1'), ('PledgeName', '|S'+self.unicode_string(data))]
return dtype
pck["03"] = c_ReqStartPledgeWar"""
pck_client["03"] = c_ReqStartPledgeWar"""
self.ini_to_xml.side = b"client"
self.assertEqual(
self.xml_string_trim(
self.ini_to_xml.convert(self.ini_string_trim(ini_string))),
self.xml_string_trim(xml_string),
)
print()
print(self.xml_to_py.convert(xml_string))
print(py_string)
self.assertEqual(
self.xml_to_py.convert(xml_string),
py_string,
Expand All @@ -141,8 +138,7 @@ def testMiddle4(self):
h(subID)d(objID)d(1)d(terrID)
d(isDisguised)d(isDisgTerrID)
"""
xml_string = b"""
<?xml version=\'1.0\' encoding=\'ASCII\'?>
xml_string = b"""<?xml version=\'1.0\' encoding=\'ASCII\'?>
<root xmlns:la2="la2">
<la2:pck_struct name="s_ExDominionWarStart" side="server" type="FEA3">
<la2:primitive name="subID" type="i2"/>
Expand All @@ -160,6 +156,26 @@ def testMiddle4(self):
self.ini_to_xml.convert(self.ini_string_trim(ini_string))),
self.xml_string_trim(xml_string),
)
py_string = """
class s_ExDominionWarStart(UTF):
@staticmethod
def dtype(act, data):
dtype = [('pck_type', 'i1'), ('subID', 'i2'), ('objID', 'i4'), ('1', 'i4'), ('terrID', 'i4'), ('isDisguised', 'i4'), ('isDisgTerrID', 'i4')]
return dtype
pck_server["FEA3"] = s_ExDominionWarStart"""
self.assertEqual(
self.xml_string_trim(
self.ini_to_xml.convert(self.ini_string_trim(ini_string))),
self.xml_string_trim(xml_string),
)
print()
print(self.xml_to_py.convert(xml_string))
print(py_string)
self.assertEqual(
self.xml_to_py.convert(xml_string),
py_string,
)

def testMiddle5(self):
ini_string = b"""
Expand Down
2 changes: 1 addition & 1 deletion src/l2/converter/xml_to_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def dtype(act, data):
dtype = {dtype}
return dtype
pck["{type}"] = {name}""" \
pck_{side}["{type}"] = {name}""" \
.format(dtype=dtype, **pck_struct.attrib) \
.replace("'S')", "'|S'+self.unicode_string(data))")

Expand Down

0 comments on commit e0597a4

Please sign in to comment.