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


Groups > comp.lang.python > #44920

Re: Making safe file names

Date 2013-05-07 18:30 -0500
From Andrew Berg <bahamutzero8825@gmail.com>
Subject Re: Making safe file names
References <mailman.1418.1367956750.3114.python-list@python.org> <aute0dFt9itU1@mid.uni-berlin.de>
Newsgroups comp.lang.python
Message-ID <mailman.1429.1367973138.3114.python-list@python.org> (permalink)

Show all headers | View raw


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

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


Thread

Making safe file names Andrew Berg <bahamutzero8825@gmail.com> - 2013-05-07 14:58 -0500
  Re: Making safe file names jt@toerring.de (Jens Thoms Toerring) - 2013-05-07 22:37 +0000
    Re: Making safe file names Andrew Berg <bahamutzero8825@gmail.com> - 2013-05-07 18:30 -0500

csiph-web