pyparsing: how to negate a grammar
Hi,
I want to define a rule for a line that does NOT start with a given
Literal. How do I do that? I try the following and my program just hang
there:
BodyLine = ~Literal("HTTP/1.1") + restOfLine
Thanks,
Khoa
--
http://mail.python.org/mailman/listinfo/python-list
Re: pyparsing: how to negate a grammar
Hi Paul,
I am trying to extract HTTP response codes from a HTTP page send from
a web server. Below is my test program. The program just hangs.
Thanks,
Khoa
##
#!/usr/bin/python
from pyparsing import ParseException, Dict, CharsNotIn,
Group,Literal,Word,ZeroOrMore,OneOrMore,
Suppress,nums,alphas,alphanums,printables,restOfLine
data = """HTTP/1.1 200 OK
body line some text here
body line some text here
HTTP/1.1 400 Bad request
body line some text here
body line some text here
HTTP/1.1 500 Bad request
body line some text here
body line some text here
"""
print "="
print data
print "="
HTTPVersion = (Literal("HTTP/1.1")).setResultsName("HTTPVersion")
StatusCode = (Word(nums)).setResultsName("StatusCode")
ReasonPhrase = restOfLine.setResultsName("ReasonPhrase")
StatusLine = Group(HTTPVersion + StatusCode + ReasonPhrase)
nonHTTP = ~Literal("HTTP/1.1")
BodyLine = Group(nonHTTP + restOfLine)
Response = OneOrMore(StatusLine + ZeroOrMore(BodyLine))
respFields = Response.parseString(data)
print respFields
--
http://mail.python.org/mailman/listinfo/python-list
Sending hex number as is
This question may be ased before, but I couldn't find the answer searching the archive. Basically, I just want to send a hex number from one machine to the next: for example msg = "Length is " n = '\x81' msg += n sock.send(msg) The problem is n's value is not fixed. For example, msg = "Length is " n = len(somestring) msg += n # This won't work of course, since n is int How do I send this msg + n? Thanks, Khoa -- http://mail.python.org/mailman/listinfo/python-list
Httplib request method
Hi, For some reason, httplib request() method splits the request packet into two packets, the first packet contains only HTTP headers, the body in the second packet. The first packet size is way below the MTU size. Is there a way I can send everything in one packet? Below is a piece of my code: self.conn.request(method, url, msg, headers) response = self.conn.getresponse() data = response.read() -- http://mail.python.org/mailman/listinfo/python-list
