[lxml-dev] [Bug 255800] parser.feed(t) + parser.feed('\n') != parser.feed(t+'\n')
Stefan Behnel
stefan_ml at behnel.de
Fri Aug 8 07:57:05 CEST 2008
(forwarding this to the list)
Vladimir Vcelak wrote:
> Dne Thu, 07 Aug 2008 19:13:04 +0200 (CEST) Stefan Behnel napsal:
>> Vladimir Vcelak wrote:
>>> >>> t = '<a>x</a>'
>>> >>> parser = etree.XMLParser(target = EchoTarget())
>>> >>> parser.feed(t) ; parser.feed('\n')
>>> start a {}
>>> data u'x'
>>> end a
>>>
>>> >>> parser = etree.XMLParser(target = EchoTarget())
>>> >>> parser.feed(t + '\n')
>>> (print none!!)
>>
>> The parser is free to start/stop/continue parsing at any time. As long
>> as the callback sequence in both cases is the same after
>> close(), I don't see the bug here.
>
> Thank you for your answer, but I can't depend on calling close(). My idea is use XML for dialogue between Server and Client:
>
> SERVER:
> from lxml import etree
>
> class MyParser:
> def start():
> level += 1
> def end():
> level -= 1
> if level == 0:
> end_command = True
>
> socket = create_TCP_server(port)
> while True:
> s = socket.accept()
> end_command = False
> parser = etree.XMLParser(target = MyTarget())
> while not end_command:
> parser.feed(s.readline())
Have you actually tried calling close() at this point? It might even work, and
it will raise an exception if the command wasn't well-formed.
BTW, I didn't check, but creating the parser once outside the loop and making
sure you call close() after each iteration might actually be enough.
> answer = execute(command)
> s.write(answer)
>
>
>
> CLIENT:
> socket = connect_to(server, port)
> socket.write("<cmd1> ..........</cmd1>\n")
> answer = socket.read()
> socket.write("<cmd2> ..........</cmd2>\n")
> answer = socket.read()
> ....
>
> or CLIENT for debug:
> telnet server port
> <cmd1> ....
> ...
> </cmd1>
> answer
> <cmd2> ....
> ...
> </cmd2>
> answer
More information about the lxml-dev
mailing list