Skip to content

Commit

Permalink
l2/converter xml->py exeption line number
Browse files Browse the repository at this point in the history
  • Loading branch information
yv84 committed Sep 28, 2014
1 parent 724f4a9 commit 2bf429e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
19 changes: 17 additions & 2 deletions src/l2/converter/ini_to_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def xml_body(self, primitives, root):
cursor, loop, skip = self.element_append(
cursor, [t, primitive_name], loop, skip)
if skip or loop:
raise Exception("wrong ini body")
raise PacketCompileException("wrong ini body")


def convert_one_line(self, line_in, root):
Expand Down Expand Up @@ -172,8 +172,10 @@ def convert(self, list_in):
xml_out = b''
root = etree.Element('root', nsmap={'la2': 'la2'})
tree = etree.ElementTree(root)
line_n = 0

for line in list_in:
line_n += 1
if isinstance(line, str):
line = line.encode('utf8')

Expand All @@ -184,7 +186,14 @@ def convert(self, list_in):
elif line.lower().startswith(b'[client]'):
self.side = b'client'
elif line:
self.convert_one_line(line, root)
try:
self.convert_one_line(line, root)
except Exception as e:
err = b"".join([b"compile error, line: ",
line[:80], b", line number: ",
str(line_n).encode('latin-1')]).decode('latin-1')
err = "\n".join([e.value, err])
raise PacketCompileException(err)
else:
pass

Expand All @@ -202,6 +211,12 @@ def convert_file(self, file_in, file_out):
f_out.write(xml_out)


class PacketCompileException(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return repr(self.value)


def agrparser():
parser = argparse.ArgumentParser(
Expand Down
5 changes: 3 additions & 2 deletions src/l2/converter/test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
SCRIPT_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__))))
sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT)))

from converter.ini_to_xml import IniToXml
from converter.ini_to_xml import IniToXml, PacketCompileException
from converter.xml_to_py import XmlToPy


Expand Down Expand Up @@ -1634,7 +1634,8 @@ def dtype(cls, data):
return dtype
pck_server[b'\\t'] = s_CharSelectionInfo"""
with self.assertRaisesRegex(Exception, "^wrong ini body$"):

with self.assertRaisesRegex(PacketCompileException, "wrong ini body.*"):
self.ini_to_xml.convert([self.ini_string_trim(ini_string),])


Expand Down

0 comments on commit 2bf429e

Please sign in to comment.