Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'svn': 0.05; 'debugging': 0.07; 'subject:file': 0.07; 'currently,': 0.09; 'api': 0.11; 'cc:addr:python-list': 0.11; "wouldn't": 0.14; 'caches': 0.16; 'doubles': 0.16; 'easier.': 0.16; 'naming': 0.16; 'readable': 0.16; 'tends': 0.16; 'url:py': 0.16; 'url:svn': 0.16; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; 'artist': 0.24; 'string,': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'andrew': 0.30; 'characters': 0.30; 'message-id:@mail.gmail.com': 0.30; 'produces': 0.31; 'though.': 0.31; 'file': 0.32; 'run': 0.32; "i'd": 0.34; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'really': 0.36; '(e.g.,': 0.36; 'url:org': 0.36; 'easily': 0.37; 'problems': 0.38; 'files': 0.38; 'most': 0.60; 'length': 0.61; 'such': 0.63; 'forward': 0.65; 'to:addr:gmail.com': 0.65; 'strategies': 0.77; 'conflicts': 0.84; 'subject:Making': 0.84; 'obtained': 0.96 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=pvz71jhDlKnnYGR2fQPkSPc+v/bgIFioslZT9J+AMjI=; b=Ys+OszKfKvGLEqOLf6loHlVkKeZY/WSuPoqEqyj7xJPukNHjrwr0t9+OdsZy5eIUON XdNfqmgbZJNNljTm6b+wiSoCPBsCwT7A8FIPpFDBDMmgFlEQXrRcvkWJd3HdEpdBrYa8 9Lum5p993WHrUbQkLJ00Q+8seDcYlngwNq77QgGYKIfXopKl1c4GtcOhlMue9TUMLlst 6V43C56ffREmkcdLr42lJ2eQ2sJXNq5vmbpH8hyR6XTlES4JlkbMDX1jcaPaqDlD9lw/ gzUKtzQEH3bhUrrEfh9rWa8x0LLGE7wpuGUCjExT1KHb5wzS8bZb0zakqGQNz9hbbQcI iyKQ== MIME-Version: 1.0 X-Received: by 10.49.0.163 with SMTP id 3mr3288125qef.14.1367965772894; Tue, 07 May 2013 15:29:32 -0700 (PDT) In-Reply-To: <51895D03.4000300@gmail.com> References: <51895D03.4000300@gmail.com> Date: Tue, 7 May 2013 15:29:32 -0700 Subject: Re: Making safe file names From: Dan Stromberg To: Andrew Berg Content-Type: text/plain; charset=ISO-8859-1 Cc: "comp.lang.python" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 19 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1367965782 news.xs4all.nl 15884 [2001:888:2000:d::a6]:42738 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:44912 On 5/7/13, Andrew Berg wrote: > Currently, I keep Last.fm artist data caches to avoid unnecessary API calls > and have been naming the files using the artist name. However, > artist names can have characters that are not allowed in file names for most > file systems (e.g., C/A/T has forward slashes). Are there any > recommended strategies for naming such files while avoiding conflicts (I > wouldn't want to run into problems for an artist named C-A-T or > CAT, for example)? I'd like to make the files easily identifiable, and there > really are no limits on what characters can be in an artist name. You might consider: http://stromberg.dnsalias.org/svn/backshift/trunk/escape_mod.py http://stromberg.dnsalias.org/svn/backshift/trunk/test-escape_mod It doubles the length of the string, but it produces safe, easily readable escaped strings - which tends to make debugging easier. It requires a couple of other modules (easily obtained from the same SVN repo) though.