String Template

t.giuseppe at gmail.com t.giuseppe at gmail.com
Fri Dec 27 13:55:00 CET 2013


Hello

I'm rewriting a program previously written in C #, and trying to keep the same configuration file, I have a problem with untapped strings.

The previous configuration files provide an input template string of this type:

<input> <![CDATA [{ip} - [{date}] "HTTP/1.1 GET {url}" {?} {?} "{referer}" "{useragent}"]]></ input>


This string is parsed and the values are replaced with the actual values written to a log file (apache), then he is given the variable name.

Taking for example a classic line of apache log:

0.0.0.0 - [27/Dec/2013: 00:56:51 +0100] "GET / webdav / HTTP/1.1" 404 524 "-" "Mozilla/5.0 (Windows, U, Windows NT 5.1, en-US , rv: 1.9.2.12) Gecko/20101026 Firefox/3.6.12 "

Is there any way to pull out the values so arranged as follows:

ip = 0.0.0.0
date = 27/Dec/2013: 00:56:51 +0100
url = / webdav /

Tnx



More information about the Python-list mailing list