Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeder.news-service.com!tudelft.nl!txtfeed1.tudelft.nl!multikabel.net!newsfeed20.multikabel.net!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '"""': 0.07; 'paths': 0.07; 'whatever.': 0.07; 'none.': 0.09; 'none:': 0.09; 'path.': 0.09; 'sys.platform': 0.09; 'linux': 0.11; 'def': 0.12; 'am,': 0.14; 'wrote:': 0.14; '(does': 0.16; 'formats:': 0.16; 'independent,': 0.16; 'likewise': 0.16; 'path:': 0.16; 'posix': 0.16; '16,': 0.16; 'cc:addr:python-list': 0.17; 'header:In-Reply-To:1': 0.21; 'thu,': 0.22; 'cc:2**0': 0.22; 'cc:no real name:2**0': 0.23; 'systems.': 0.23; "doesn't": 0.25; 'url:mailman': 0.26; 'message- id:@mail.gmail.com': 0.28; 'raise': 0.28; 'like,': 0.29; 'class': 0.29; 'cc:addr:python.org': 0.30; 'url:listinfo': 0.30; 'module': 0.30; 'conversion.': 0.30; 'received:209.85.215': 0.30; 'received:209.85.215.46': 0.30; 'received:mail- ew0-f46.google.com': 0.30; 'anyone': 0.32; "can't": 0.32; 'determined': 0.32; 'steven': 0.32; "isn't": 0.33; 'lines': 0.33; '...': 0.34; 'file': 0.34; 'that,': 0.34; 'there': 0.35; "d'aprano": 0.35; 'explicit': 0.35; 'skip:@ 10': 0.35; 'format.': 0.36; 'platform': 0.36; 'received:google.com': 0.37; 'something': 0.37; 'received:209.85': 0.37; 'url:python': 0.38; 'could': 0.38; 'url:org': 0.38; 'but': 0.38; 'component': 0.38; 'worry': 0.38; 'subject:: ': 0.38; 'some': 0.38; 'perhaps': 0.39; 'received:209': 0.39; 'map': 0.39; 'windows.': 0.39; 'add': 0.39; 'under': 0.40; 'format': 0.40; 'more': 0.60; 'your': 0.60; 'legal': 0.70 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=3Tn0ylNbZz9jYen2ojUBCJ8KnVREMJUaY2qs5oe3pI4=; b=sjEkVkxwOwYDnLZ9ZM6EnE/4pOVs0bgxe3rVi8qOBe56EwOYfuRsT1xnpaYUnsz15q O8MMhJyl2GH5e0sZT2sen11hQaIxv6b7XtjbNGEdq5QSbd4YioVp61ZKiPjGVvE8VS37 fQe15FvBWXdMQmcs+kQM9hI0cQRCsY/Qoqz+8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=MME77JtZEmRFLUvn5JHQehlv1W57Jhsbl4Jax2LUj0o9v/Aq+j/g3ki43hCkxsD5FL hekAM8F/jX75U50aAS4osDBRAdjmKNsMOaF5Lg4ZwGLgrUB1j/T1JnscP3lcbFlOCNhP aPV3tpLrKxVqQE1cwWztEPHGt268j25LhmtSg= MIME-Version: 1.0 In-Reply-To: <4dfa324e$0$30002$c3e8da3$5496439d@news.astraweb.com> References: <4DF9AADE.6090609@gmail.com> <4df9b7be$0$29973$c3e8da3$5496439d@news.astraweb.com> <4dfa324e$0$30002$c3e8da3$5496439d@news.astraweb.com> Date: Thu, 16 Jun 2011 11:21:05 -0600 Subject: Re: os.path and Path From: Eric Snow To: "Steven D'Aprano" Content-Type: text/plain; charset=ISO-8859-1 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 75 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1308244867 news.xs4all.nl 49178 [::ffff:82.94.164.166]:38151 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:7756 On Thu, Jun 16, 2011 at 10:41 AM, Steven D'Aprano wrote: > > On a Linux or OS X box, you could have a file e inside a directory c:d > inside b inside a. It can't be treated as platform independent, because > c:d is not a legal path component under classic Mac or Windows. > > On a classic Mac (does anyone still use them?), you could have a file e > inside a directory c/d inside b inside a. Likewise c/d isn't legal under > POSIX or Windows. > > So there are paths that are legal under one file system, but not others, > and hence there is no single normalization that can represent all legal > paths under arbitrary file systems. > Perhaps one solution is to have the Path class accept registrations of valid path formats: class PathFormat: @abstractmethod def map_path(self, pathstring): """Map the pathstring to the canonical path. This could take the form of some regex or an even a more explicit conversion. If there is no match, return None. """ @abstractmethod def unmap_path(self, pathstring): """Map the pathstring from a canonical path to this format. If there is no match, return None. """ class Path: ... _formats = [] @classmethod def register_format(cls, format): cls._formats.append(format) def map_path(self, pathstring): for format in self._formats: result = format.map_path(pathstring) if result is None: continue # remember which format matched? return result raise TypeError("No formatters could map the pathstring.") def unmap_path(self, pathstring): ... With something like that, you have a PathFormat class for each platform that matters. Anyone would be able to add more, as they like, through register_format. This module could also include a few lines to register a particular PathFormat depending on the platform determined through sys.platform or whatever. This way your path class doesn't have to try to worry about the conversion to and from the canonical path format. -eric > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list >