Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > No validation routine for an os.path

Reply
Thread Tools

No validation routine for an os.path

 
 
Edward Diener
Guest
Posts: n/a
 
      08-17-2004
Try as I might I can not find a routine in os.path which validates whether
or not a path is syntactically valid, either as a directory or as a file.
This is surprising since, although I know this is OS dependent, Python has
many other classes and functions which will work properly depending on what
OS they are currently running under. Is there such a path validation routine
in any of the libraries distributed with Python or in any other 3rd party
Python libraries ?


 
Reply With Quote
 
 
 
 
Peter Hansen
Guest
Posts: n/a
 
      08-17-2004
Edward Diener wrote:

> Try as I might I can not find a routine in os.path which validates whether
> or not a path is syntactically valid, either as a directory or as a file.
> This is surprising since, although I know this is OS dependent, Python has
> many other classes and functions which will work properly depending on what
> OS they are currently running under. Is there such a path validation routine
> in any of the libraries distributed with Python or in any other 3rd party
> Python libraries ?


I don't really think so, and the last time this sort of thing
was discussed, I believe the conclusion was that it's not
actually possible to do such a thing in all cases anyway,
unless you are willing to actually attempt to create the
file or directory during the validation.

One reason I recall being given is that even on a given OS, different
file systems may support different sets of characters for filenames.
For example, a CDROM might disallow certain characters which the
standard file system allows, or a networked device (e.g. NFS, or
Samba) might allow a wider range of possibilities than the permitted
names on a hard drive.

In the end, this is somewhat like validating email addresses. Until
you actually try and succeed (or fail) to send the message, you cannot
verify whether an address is "valid" for many definitions of valid.

-Peter
 
Reply With Quote
 
 
 
 
Edward Diener
Guest
Posts: n/a
 
      08-18-2004
Peter Hansen wrote:
> Edward Diener wrote:
>
>> Try as I might I can not find a routine in os.path which validates
>> whether or not a path is syntactically valid, either as a directory
>> or as a file. This is surprising since, although I know this is OS
>> dependent, Python has many other classes and functions which will
>> work properly depending on what OS they are currently running under.
>> Is there such a path validation routine in any of the libraries
>> distributed with Python or in any other 3rd party Python libraries ?

>
> I don't really think so, and the last time this sort of thing
> was discussed, I believe the conclusion was that it's not
> actually possible to do such a thing in all cases anyway,
> unless you are willing to actually attempt to create the
> file or directory during the validation.


Operating systems do have rules for what constitutes a valid file
specification and/or directory specification. Some even have API functions
which can be called to directly find out.

>
> One reason I recall being given is that even on a given OS, different
> file systems may support different sets of characters for filenames.
> For example, a CDROM might disallow certain characters which the
> standard file system allows, or a networked device (e.g. NFS, or
> Samba) might allow a wider range of possibilities than the permitted
> names on a hard drive.


You have a good point there. But with a file spec and a bit of work, one
should be able to tell what sort of drive is being accessed.

>
> In the end, this is somewhat like validating email addresses. Until
> you actually try and succeed (or fail) to send the message, you cannot
> verify whether an address is "valid" for many definitions of valid.


I do not totally agree, especially as the OS will know whether something is
valid so it obviously has rules itself. But I grant it is more difficult
than might be assumed. BTW email addresses actually do have a format which
can be parsed ( RFC 822 originally ), although again it is complicated.


 
Reply With Quote
 
Peter Hansen
Guest
Posts: n/a
 
      08-18-2004
Edward Diener wrote:

> Operating systems do have rules for what constitutes a valid file
> specification and/or directory specification. Some even have API functions
> which can be called to directly find out.


True, but with dynamically loadable extensions to the OS, it
seems unlikely that the builtin API for checking filename
validity will necessarily handle a completely new filesystem
that was created after the OS was released...

> Peter Hansen wrote:
>>In the end, this is somewhat like validating email addresses. Until
>>you actually try and succeed (or fail) to send the message, you cannot
>>verify whether an address is "valid" for many definitions of valid.

>
> I do not totally agree, especially as the OS will know whether something is
> valid so it obviously has rules itself.


Again, the OS might have rules, but they can't always apply
to things that are not really part of the OS, as an add-on
might be. I'm sure that in most cases the add-on would not
be expanding the set of allowable characters, but it's
certainly not unusual for the set to be narrowed.

> BTW email addresses actually do have a format which
> can be parsed ( RFC 822 originally ), although again it is complicated.


I was careful to say "for many definitions of valid". Valid might
be as trivial as checking whether it matches a particular format
(though I think the term "legal" might be more usual there), but
it could also mean "the address actually exists and can receive
mail" in which case you really can't know for sure unless you
try.

In the end, however, I still think the answer to your query is
an unfortunate "sorry, not available".

-Peter
 
Reply With Quote
 
Roger Binns
Guest
Posts: n/a
 
      08-18-2004
Edward Diener wrote:
> I do not totally agree, especially as the OS will know whether
> something is valid so it obviously has rules itself. But I grant it
> is more difficult than might be assumed. BTW email addresses actually
> do have a format which can be parsed ( RFC 822 originally ), although
> again it is complicated.


I don't think Peter meant whether or not you can extract an email
address, but rather if it is actually valid. For example,
which of these are valid?

http://www.velocityreviews.com/forums/(E-Mail Removed)
(E-Mail Removed)
fred!foovax!kremvax!nasa
one@(E-Mail Removed)

As a bonus question, are email addresses case sensitive?

Roger


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
my validation routine =?Utf-8?B?cm9kY2hhcg==?= ASP .Net 0 06-01-2007 02:10 PM
Received non-routine Notify message: Invalid ID info f.pusch@klopotek.de Cisco 2 08-22-2005 09:35 AM
credit card validation routine dries Javascript 9 08-16-2004 06:06 PM
Easiest way to get page name from error routine? =?Utf-8?B?QmlsbCBCb3Jn?= ASP .Net 1 03-03-2004 01:03 PM
just tinkering with a Sub Routine in ASP.NET D. Shane Fowlkes ASP .Net 5 11-13-2003 02:15 AM



Advertisments