Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #17936

Backslash Escapes

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <pip.261@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'string.': 0.04; 'python': 0.08; 'backslash': 0.09; 'parsing': 0.09; 'def': 0.13; 'received:209.85.210.174': 0.13; 'received:mail- iy0-f174.google.com': 0.13; 'backslashes': 0.16; 'escapes': 0.16; 'eval': 0.16; 'this:': 0.16; 'thanks,': 0.18; 'source.': 0.18; 'file,': 0.19; 'written': 0.20; 'input': 0.22; 'statement': 0.23; 'dictionary': 0.23; 'guess': 0.26; "i'm": 0.26; 'all,': 0.28; 'message-id:@mail.gmail.com': 0.28; "skip:' 10": 0.29; 'skip:p 30': 0.29; 'support,': 0.30; 'there': 0.33; 'to:addr:python-list': 0.34; 'elegant': 0.34; 'two': 0.37; 'but': 0.37; 'received:google.com': 0.37; 'could': 0.37; 'received:209.85': 0.38; 'should': 0.39; 'goes': 0.39; "it's": 0.40; 'received:209': 0.40; 'to:addr:python.org': 0.40; 'alternative': 0.65; 'safe': 0.70; 'spaces': 0.73; 'accounts.': 0.77
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type; bh=DWyi0FFSQ5yqCdAklcqOqjIv1G8JgJ6K8KnbqbcrvQU=; b=WtoWq3L0hqCOYB9HnV/tApzz5i8bd09/sjEGMzKcWlKWovLbPWr/jQ+wt/x+dDH64r Utf9j447QEW3ESM0B5HU/KAtDgTOeqz3Y7ZupzCptcmof+bzACEqjzGe2Ex26/61GttZ rbVGyDOmqiODZH74s5k5053kRUy4BSoUzwbYo=
MIME-Version 1.0
From Felipe O <pip.261@gmail.com>
Date Sun, 25 Dec 2011 20:04:54 -0500
Subject Backslash Escapes
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
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.4086.1324861519.27778.python-list@python.org> (permalink)
Lines 21
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1324861519 news.xs4all.nl 6925 [2001:888:2000:d::a6]:53067
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:17936

Show key headers only | View raw


Hi all,
Whenever I take any input (raw_input, of course!) or I read from a
file, etc., any backslashes get escaped automatically. Is there any
elegant way of parsing the backslashes as though they were written in
a python string. The best I have so far right now goes like this:

def parse_backslash_escapes(input_string):
    parts = input_string.split("'''")  # That's ' " " " ' without the spaces
    '"""'.join(eval + p + '"""') for p in parts)

I'm not entirely convinced that it's safe on two accounts.
+ Is that eval statement safe? The input could be coming from an
unfriendly source.
+ Are there any obscure backslash escapes or other tricks I should be aware of?

I guess the alternative is to make a dictionary of all the escapes I
want to support, but that sounds tedious and error-prone.

Thanks,

Felipe

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Backslash Escapes Felipe O <pip.261@gmail.com> - 2011-12-25 20:04 -0500

csiph-web