Path: csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.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.033 X-Spam-Evidence: '*H*': 0.93; '*S*': 0.00; 'cpython': 0.05; 'encoding': 0.05; '(so': 0.07; 'received:209.85.160.174': 0.07; 'subject:file': 0.07; 'transform': 0.07; 'ascii': 0.09; 'encode': 0.09; 'translate': 0.10; 'windows': 0.15; "'/'": 0.16; 'well- known': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'trying': 0.19; 'header :User-Agent:1': 0.23; 'artist': 0.24; 'effort.': 0.24; 'replace': 0.24; 'unicode': 0.24; "i've": 0.25; 'header:In-Reply-To:1': 0.27; 'character': 0.29; 'characters': 0.30; 'assumes': 0.31; 'file': 0.32; 'could': 0.34; 'received:209.85': 0.35; 'problem.': 0.35; 'something': 0.35; 'one,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'version': 0.36; 'scheme': 0.36; "i'll": 0.36; 'too': 0.37; 'received:209': 0.37; 'message- id:@gmail.com': 0.38; 'e.g.': 0.38; 'mapping': 0.38; 'to:addr :python-list': 0.38; 'itself': 0.39; 'to:addr:python.org': 0.39; 'changed': 0.39; 'days': 0.60; 'back': 0.62; 'name': 0.63; 'pick': 0.64; 'become': 0.64; 'series': 0.66; 'between': 0.67; 'gotten': 0.74; 'forth': 0.81; '3.3.1': 0.84; '9.1': 0.84; 'freebsd': 0.84; 'games.': 0.84; 'subject:Making': 0.84; 'in-': 0.91; 'responses': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:message-id:date:from:user-agent:mime-version:to:subject :references:in-reply-to:x-enigmail-version:content-type :content-transfer-encoding; bh=rhgmsywhHyaAlgrOX5UYBH65Zg5PPYe0CFrs6TIcZ1M=; b=lXACfLFDLjW8OrlJJGzl+ME/QlUBOs0LaLxcvb9s/CmK1sbSP6Uo9V4rdQdwRDGLU0 PyRBgihI3t+kV3jfbeSJC0JYMKBUgCMT+V1eOjBow7zOXzFJ4K73p7v7AXen8XvR7EkF ufF0x289oELmqiJ96Lzj1TqyQY6BSCQEB0Y1kTa5qUA7nKBjZse2xH0Jl0HrOVMjm3Jy 3grERDtb9doVnlkVAzJzFtJeqdrSpnnMh6lIuAvYeCAp8viFX0HLyVeX2JaiMiUVipbi o/ewxuLwsn+8i9H9SgCZZRcgsaj1+mroMPGN/OIc99LGoUHVOapNSGoGg7XEMIuKNmeF WXoA== X-Received: by 10.236.47.136 with SMTP id t8mr4004101yhb.64.1367969455396; Tue, 07 May 2013 16:30:55 -0700 (PDT) Date: Tue, 07 May 2013 18:30:53 -0500 From: Andrew Berg User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20130107 Thunderbird/17.0.2 MIME-Version: 1.0 To: "comp.lang.python" Subject: Re: Making safe file names References: In-Reply-To: X-Enigmail-Version: 1.5.1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: 30 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1367973138 news.xs4all.nl 15909 [2001:888:2000:d::a6]:46756 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:44920 On 2013.05.07 17:37, Jens Thoms Toerring wrote: > You > could e.g. replace all characters not allowed by the file > system by their hexidecimal (ASCII) values, preceeded by a > '%" (so '/' would be changed to '%2F', and also encode a '%' > itself in a name by '%25'). Then you have a well-defined > two-way mapping ("isomorphic" if I remember my math-lear- > nining days correctly) between the original name and the > way you store it. E.g. > > "C/A/T" would become "C%2FA%2FT" > > and > > "C%2FA/T" would become "C%252FA%2FT" > > You can translate back and forth between them with not too > much effort. > > Of course, that assumes that '%' is a character allowed by > your file system - otherwise pick some other one, any one > will do in principle. It's a bit harder for a human to in- > terpret but rathe likely not that much of a problem. Yes, something like this is what I am trying to achieve. Judging by the responses I've gotten so far, I think I'll have to roll my own transformation scheme since URL encoding and the like transform Unicode characters. I can memorize that 植松伸夫 is a Japanese composer who is well-known for his works in the Final Fantasy series of video games. Trying to match up the URL-encoded version to an artist would be almost impossible when I have several other artist names that have no ASCII characters. -- CPython 3.3.1 | Windows NT 6.2.9200 / FreeBSD 9.1