Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #7756
| 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 | <ericsnowcurrently@gmail.com> |
| 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 | <mailman.8.1308188800.1164.python-list@python.org> <4DF9AADE.6090609@gmail.com> <4df9b7be$0$29973$c3e8da3$5496439d@news.astraweb.com> <mailman.20.1308240105.1164.python-list@python.org> <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 <ericsnowcurrently@gmail.com> |
| To | "Steven D'Aprano" <steve+comp.lang.python@pearwood.info> |
| 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 <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.26.1308244867.1164.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
On Thu, Jun 16, 2011 at 10:41 AM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> 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
>
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
os.path and Path Ethan Furman <ethan@stoneleaf.us> - 2011-06-15 19:00 -0700
Re: os.path and Path Laurent Claessens <moky.math@gmail.com> - 2011-06-16 09:03 +0200
Re: os.path and Path Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-16 07:58 +0000
Re: os.path and Path Ethan Furman <ethan@stoneleaf.us> - 2011-06-16 09:16 -0700
Re: os.path and Path Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-16 16:41 +0000
Re: os.path and Path Ethan Furman <ethan@stoneleaf.us> - 2011-06-16 10:18 -0700
Re: os.path and Path Eric Snow <ericsnowcurrently@gmail.com> - 2011-06-16 11:21 -0600
Re: os.path and Path Christian Heimes <lists@cheimes.de> - 2011-06-16 18:32 +0200
Re: os.path and Path Ethan Furman <ethan@stoneleaf.us> - 2011-06-16 10:07 -0700
Re: os.path and Path Chris Angelico <rosuav@gmail.com> - 2011-06-17 11:00 +1000
Re: os.path and Path Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-16 07:14 +0000
Re: os.path and Path Ethan Furman <ethan@stoneleaf.us> - 2011-06-16 09:05 -0700
Re: os.path and Path Chris Torek <nospam@torek.net> - 2011-06-17 00:48 +0000
Re: os.path and Path Ethan Furman <ethan@stoneleaf.us> - 2011-06-16 18:19 -0700
Re: os.path and Path Ned Deily <nad@acm.org> - 2011-06-16 19:55 -0700
Re: os.path and Path rusi <rustompmody@gmail.com> - 2011-06-16 21:24 -0700
csiph-web