Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #42770
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <kushal.kumaran@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.010 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; '(at': 0.04; 'skip:[ 20': 0.04; 'sufficient': 0.05; 'expressions': 0.07; 'string': 0.09; 'literal': 0.09; 'parsing': 0.09; 'solution,': 0.09; 'effect.': 0.16; 'localhost': 0.16; 'mangled': 0.16; 'readable': 0.16; 'roy': 0.16; 'too).': 0.16; 'files.': 0.16; ':-)': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; "python's": 0.19; 'rules': 0.22; 'this?': 0.23; 'header:User-Agent:1': 0.23; 'parse': 0.24; 'skip:{ 20': 0.24; 'together.': 0.24; '(or': 0.24; 'suggested': 0.26; 'header:In-Reply-To:1': 0.27; 'point': 0.28; '----': 0.29; 'cool': 0.30; 'direction': 0.30; 'code': 0.31; 'easier': 0.31; 'writes:': 0.31; 'regular': 0.32; 'run': 0.32; 'running': 0.33; 'received:209.85': 0.35; 'tool': 0.35; 'received:209.85.160.46': 0.35; 'received:google.com': 0.35; 'received:209': 0.37; 'jason': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'enough': 0.39; 'read': 0.60; 'expression': 0.60; 'skip:2 20': 0.60; 'skip:n 30': 0.60; 'up,': 0.60; 'break': 0.61; 'challenge': 0.61; 'making': 0.63; 'skip:r 40': 0.68; 'smith': 0.68; 'skip:r 30': 0.69; 'article': 0.77; 'received:117': 0.78; 'message-id:@mx.google.com': 0.80; '(probably': 0.84; 'embrace': 0.84; 'noise': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:subject:in-reply-to:references:user-agent :date:message-id:mime-version:content-type; bh=ijYRuEkAvnw9t+3mWpkZR4VS/TVdyMZJbwpMFqwRKVw=; b=mdkov0zaaganMK3Ael4H5OfqAAySUAUoy5LzTM4mIDlXHs/fX4dbugfzlXNUrbf8IA 673tIWihVc4yLKKjx5SNQjnvGmd9cVtomZfO193q0WNw6EItbaBju+EvwxD44wbK64v/ uE9+OxXWegnN+GlkbQ5tdNSRI+iU56svurR2+RP2dcD9t5elLLCBaMrIV5WAgDGnj7A1 PiCctXU4YycnepkTkLU3fuhkYOyVywwjHRhZ5RFFYsClbQib7AQew58KRzNR1PQvw2ki XnvVK4FuB89lSKBGSSVPMNo3jav8s37nZBNc3rgTmOd8CkxZw7Ha+lfqZLhuRAtb7eVx IdhA== |
| X-Received | by 10.66.6.42 with SMTP id x10mr10707234pax.218.1365096858955; Thu, 04 Apr 2013 10:34:18 -0700 (PDT) |
| Sender | Kushal Kumaran <kushal.kumaran@gmail.com> |
| From | Kushal Kumaran <kushal.kumaran+python@gmail.com> |
| To | python-list@python.org |
| Subject | Re: In defence of 80-char lines |
| In-Reply-To | <roy-D6F29A.08394604042013@news.panix.com> |
| References | <515cd919$0$29966$c3e8da3$5496439d@news.astraweb.com> <mailman.96.1365077619.3114.python-list@python.org> <roy-D6F29A.08394604042013@news.panix.com> |
| User-Agent | Notmuch/0.13.2 (http://notmuchmail.org) Emacs/24.1.1 (x86_64-pc-linux-gnu) |
| Date | Thu, 04 Apr 2013 23:04:07 +0530 |
| MIME-Version | 1.0 |
| Content-Type | text/plain |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.111.1365096868.3114.python-list@python.org> (permalink) |
| Lines | 63 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1365096868 news.xs4all.nl 6945 [2001:888:2000:d::a6]:51292 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:42770 |
Show key headers only | View raw
Roy Smith <roy@panix.com> writes:
> In article <mailman.96.1365077619.3114.python-list@python.org>,
> Jason Swails <jason.swails@gmail.com> wrote:
>
>> The only time I regularly break my rule is for regular expressions (at some
>> point I may embrace re.X to allow me to break those up, too).
>
> re.X is a pretty cool tool for making huge regexes readable. But, it
> turns out that python's auto-continuation and string literal
> concatenation rules are enough to let you get much the same effect.
> Here's a regex we use to parse haproxy log files. This would be utter
> line noise all run together. This way, it's almost readable :-)
>
> pattern = re.compile(r'haproxy\[(?P<pid>\d+)]: '
> r'(?P<client_ip>(\d{1,3}\.){3}\d{1,3}):'
> r'(?P<client_port>\d{1,5}) '
>
> r'\[(?P<accept_date>\d{2}/\w{3}/\d{4}(:\d{2}){3}\.\d{3})] '
> r'(?P<frontend_name>\S+) '
> r'(?P<backend_name>\S+)/'
> r'(?P<server_name>\S+) '
> r'(?P<Tq>(-1|\d+))/'
> r'(?P<Tw>(-1|\d+))/'
> r'(?P<Tc>(-1|\d+))/'
> r'(?P<Tr>(-1|\d+))/'
> r'(?P<Tt>\+?\d+) '
> r'(?P<status_code>\d{3}) '
> r'(?P<bytes_read>\d+) '
> r'(?P<captured_request_cookie>\S+) '
> r'(?P<captured_response_cookie>\S+) '
> r'(?P<termination_state>[\w-]{4}) '
> r'(?P<actconn>\d+)/'
> r'(?P<feconn>\d+)/'
> r'(?P<beconn>\d+)/'
> r'(?P<srv_conn>\d+)/'
> r'(?P<retries>\d+) '
> r'(?P<srv_queue>\d+)/'
> r'(?P<backend_queue>\d+) '
> r'(\{(?P<request_id>.*?)\} )?'
> r'(\{(?P<captured_request_headers>.*?)\} )?'
> r'(\{(?P<captured_response_headers>.*?)\} )?'
> r'"(?P<http_request>.+)"'
> )
>
> And, for those of you who go running in the other direction every time
> regex is suggested as a solution, I challenge you to come up with easier
> to read (or write) code for parsing a line like this (probably
> hopelessly mangled by the time you read it):
>
> 2013-04-03T00:00:00+00:00 localhost haproxy[5199]: 10.159.19.244:57291
> [02/Apr/2013:23:59:59.811] app-nodes next-song-nodes/web8.songza.com
> 0/0/3/214/219 200 593 sessionid=NWiX5KGOdvg6dSaA
> sessionid=NWiX5KGOdvg6dSaA ---- 249/249/149/14/0 0/0
> {4C0ABFA9-515B6DEF-933229} "POST
> /api/1/station/892337/song/16024201/notify-play HTTP/1.0"
Is using csv.DictReader with delimiter=' ' not sufficient for this? I
did not actually read the regular expression in its entirety.
--
regards,
kushal
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
In defence of 80-char lines Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-04 01:36 +0000
Re: In defence of 80-char lines Andrew Berg <bahamutzero8825@gmail.com> - 2013-04-03 20:59 -0500
Re: In defence of 80-char lines Mitya Sirenef <msirenef@lightbird.net> - 2013-04-03 22:40 -0400
Re: In defence of 80-char lines llanitedave <llanitedave@veawb.coop> - 2013-04-03 21:32 -0700
Re: In defence of 80-char lines Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-04 06:33 +0000
Re: In defence of 80-char lines gregor <gregor@ediwo.com> - 2013-04-04 08:40 +0200
Re: In defence of 80-char lines Peter Otten <__peter__@web.de> - 2013-04-04 08:43 +0200
Re: In defence of 80-char lines Tim Chase <python.list@tim.thechases.com> - 2013-04-04 06:09 -0500
Re: In defence of 80-char lines Roy Smith <roy@panix.com> - 2013-04-04 07:52 -0400
Re: In defence of 80-char lines llanitedave <llanitedave@veawb.coop> - 2013-04-04 08:28 -0700
Re: In defence of 80-char lines Jason Swails <jason.swails@gmail.com> - 2013-04-04 08:18 -0400
Re: In defence of 80-char lines Joshua Landau <joshua.landau.ws@gmail.com> - 2013-04-04 18:18 +0100
Re: In defence of 80-char lines Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-04-04 18:22 -0400
Re: In defence of 80-char lines rusi <rustompmody@gmail.com> - 2013-04-03 21:56 -0700
Re: In defence of 80-char lines Rui Maciel <rui.maciel@gmail.com> - 2013-04-04 08:15 +0100
Re: In defence of 80-char lines Jason Swails <jason.swails@gmail.com> - 2013-04-04 08:13 -0400
Re: In defence of 80-char lines Roy Smith <roy@panix.com> - 2013-04-04 08:39 -0400
Re: In defence of 80-char lines Jason Swails <jason.swails@gmail.com> - 2013-04-04 09:23 -0400
Re: In defence of 80-char lines Neil Cerutti <neilc@norwich.edu> - 2013-04-04 15:56 +0000
Re: In defence of 80-char lines Kushal Kumaran <kushal.kumaran+python@gmail.com> - 2013-04-04 23:04 +0530
Re: In defence of 80-char lines Roy Smith <roy@panix.com> - 2013-04-04 19:55 -0400
Re: In defence of 80-char lines Mitya Sirenef <msirenef@lightbird.net> - 2013-04-04 12:12 -0400
Re: In defence of 80-char lines jmfauth <wxjmfauth@gmail.com> - 2013-04-04 13:28 -0700
Re: In defence of 80-char lines Jason Swails <jason.swails@gmail.com> - 2013-04-04 17:00 -0400
Re: In defence of 80-char lines Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-05 00:14 +0000
csiph-web