[Python-checkins] CVS: python/dist/src/Lib/plat-riscos riscosenviron.py,1.3,1.3.6.1 riscospath.py,1.2,1.2.4.1 rourl2path.py,1.1,1.1.6.1
Tim Peters
tim_one@users.sourceforge.net
Fri, 06 Jul 2001 00:28:38 -0700
Update of /cvsroot/python/python/dist/src/Lib/plat-riscos
In directory usw-pr-cvs1:/tmp/cvs-serv18828
Modified Files:
Tag: descr-branch
riscosenviron.py riscospath.py rourl2path.py
Log Message:
Harmless merge.
Index: riscosenviron.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/plat-riscos/riscosenviron.py,v
retrieving revision 1.3
retrieving revision 1.3.6.1
diff -C2 -r1.3 -r1.3.6.1
*** riscosenviron.py 2001/03/07 09:08:11 1.3
--- riscosenviron.py 2001/07/06 07:28:36 1.3.6.1
***************
*** 43,45 ****
else:
return failobj
-
--- 43,44 ----
Index: riscospath.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/plat-riscos/riscospath.py,v
retrieving revision 1.2
retrieving revision 1.2.4.1
diff -C2 -r1.2 -r1.2.4.1
*** riscospath.py 2001/04/10 22:03:14 1.2
--- riscospath.py 2001/07/06 07:28:36 1.2.4.1
***************
*** 20,30 ****
try:
! import swi
except ImportError:
! class _swi:
! def swi(*a):
! raise AttributeError, 'This function only available under RISC OS'
! block= swi
! swi= _swi()
[_false, _true]= range(2)
--- 20,30 ----
try:
! import swi
except ImportError:
! class _swi:
! def swi(*a):
! raise AttributeError, 'This function only available under RISC OS'
! block= swi
! swi= _swi()
[_false, _true]= range(2)
***************
*** 46,179 ****
def _split(p):
! """
! split filing system name (including special field) and drive specifier from rest
! of path. This is needed by many riscospath functions.
! """
! dash= _allowMOSFSNames and p[:1]=='-'
! if dash:
! q= string.find(p, '-', 1)+1
! else:
! if p[:1]==':':
! q= 0
else:
! q= string.find(p, ':')+1 # q= index of start of non-FS portion of path
! s= string.find(p, '#')
! if s==-1 or s>q:
! s= q # find end of main FS name, not including special field
! else:
! for c in p[dash:s]:
! if c not in string.letters:
! q= 0
! break # disallow invalid non-special-field characters in FS name
! r= q
! if p[q:q+1]==':':
! r= string.find(p, '.', q+1)+1
! if r==0:
! r= len(p) # find end of drive name (if any) following FS name (if any)
! return (p[:q], p[q:r], p[r:])
def normcase(p):
"""
! Normalize the case of a pathname. This converts to lowercase as the native RISC
! OS filesystems are case-insensitive. However, not all filesystems have to be,
! and there's no simple way to find out what type an FS is argh.
! """
! return string.lower(p)
def isabs(p):
"""
! Return whether a path is absolute. Under RISC OS, a file system specifier does
! not make a path absolute, but a drive name or number does, and so does using the
! symbol for root, URD, library, CSD or PSD. This means it is perfectly possible
! to have an "absolute" URL dependent on the current working directory, and
! equally you can have a "relative" URL that's on a completely different device to
! the current one argh.
! """
! (fs, drive, path)= _split(p)
! return drive!='' or path[:1] in _roots
def join(a, *p):
! """
! Join path elements with the directory separator, replacing the entire path when
! an absolute or FS-changing path part is found.
! """
! j= a
! for b in p:
! (fs, drive, path)= _split(b)
! if fs!='' or drive!='' or path[:1] in _roots:
! j= b
! else:
! j= j+'.'+b
! return j
def split(p):
! """
! Split a path in head (everything up to the last '.') and tail (the rest). FS
! name must still be dealt with separately since special field may contain '.'.
! """
! (fs, drive, path)= _split(p)
! q= string.rfind(path, '.')
! if q!=-1:
! return (fs+drive+path[:q], path[q+1:])
! return ('', p)
def splitext(p):
! """
! Split a path in root and extension. This assumes the 'using slash for dot and
! dot for slash with foreign files' convention common in RISC OS is in force.
! """
! (tail, head)= split(p)
! if '/' in head:
! q= len(head)-string.rfind(head, '/')
! return (p[:-q], p[-q:])
! return (p, '')
def splitdrive(p):
"""
! Split a pathname into a drive specification (including FS name) and the rest of
! the path. The terminating dot of the drive name is included in the drive
! specification.
! """
! (fs, drive, path)= _split(p)
! return (fs+drive, p)
def basename(p):
"""
! Return the tail (basename) part of a path.
! """
! return split(p)[1]
def dirname(p):
"""
! Return the head (dirname) part of a path.
! """
! return split(p)[0]
def commonprefix(ps):
! """
! Return the longest prefix of all list elements. Purely string-based; does not
! separate any path parts. Why am I in os.path?
! """
! if len(ps)==0:
! return ''
! prefix= ps[0]
! for p in ps[1:]:
! prefix= prefix[:len(p)]
! for i in range(len(prefix)):
! if prefix[i] <> p[i]:
! prefix= prefix[:i]
! if i==0:
! return ''
! break
! return prefix
--- 46,179 ----
def _split(p):
! """
! split filing system name (including special field) and drive specifier from rest
! of path. This is needed by many riscospath functions.
! """
! dash= _allowMOSFSNames and p[:1]=='-'
! if dash:
! q= string.find(p, '-', 1)+1
! else:
! if p[:1]==':':
! q= 0
! else:
! q= string.find(p, ':')+1 # q= index of start of non-FS portion of path
! s= string.find(p, '#')
! if s==-1 or s>q:
! s= q # find end of main FS name, not including special field
else:
! for c in p[dash:s]:
! if c not in string.letters:
! q= 0
! break # disallow invalid non-special-field characters in FS name
! r= q
! if p[q:q+1]==':':
! r= string.find(p, '.', q+1)+1
! if r==0:
! r= len(p) # find end of drive name (if any) following FS name (if any)
! return (p[:q], p[q:r], p[r:])
def normcase(p):
+ """
+ Normalize the case of a pathname. This converts to lowercase as the native RISC
+ OS filesystems are case-insensitive. However, not all filesystems have to be,
+ and there's no simple way to find out what type an FS is argh.
"""
! return string.lower(p)
def isabs(p):
+ """
+ Return whether a path is absolute. Under RISC OS, a file system specifier does
+ not make a path absolute, but a drive name or number does, and so does using the
+ symbol for root, URD, library, CSD or PSD. This means it is perfectly possible
+ to have an "absolute" URL dependent on the current working directory, and
+ equally you can have a "relative" URL that's on a completely different device to
+ the current one argh.
"""
! (fs, drive, path)= _split(p)
! return drive!='' or path[:1] in _roots
def join(a, *p):
! """
! Join path elements with the directory separator, replacing the entire path when
! an absolute or FS-changing path part is found.
! """
! j= a
! for b in p:
! (fs, drive, path)= _split(b)
! if fs!='' or drive!='' or path[:1] in _roots:
! j= b
! else:
! j= j+'.'+b
! return j
def split(p):
! """
! Split a path in head (everything up to the last '.') and tail (the rest). FS
! name must still be dealt with separately since special field may contain '.'.
! """
! (fs, drive, path)= _split(p)
! q= string.rfind(path, '.')
! if q!=-1:
! return (fs+drive+path[:q], path[q+1:])
! return ('', p)
def splitext(p):
! """
! Split a path in root and extension. This assumes the 'using slash for dot and
! dot for slash with foreign files' convention common in RISC OS is in force.
! """
! (tail, head)= split(p)
! if '/' in head:
! q= len(head)-string.rfind(head, '/')
! return (p[:-q], p[-q:])
! return (p, '')
def splitdrive(p):
+ """
+ Split a pathname into a drive specification (including FS name) and the rest of
+ the path. The terminating dot of the drive name is included in the drive
+ specification.
"""
! (fs, drive, path)= _split(p)
! return (fs+drive, p)
def basename(p):
+ """
+ Return the tail (basename) part of a path.
"""
! return split(p)[1]
def dirname(p):
+ """
+ Return the head (dirname) part of a path.
"""
! return split(p)[0]
def commonprefix(ps):
! """
! Return the longest prefix of all list elements. Purely string-based; does not
! separate any path parts. Why am I in os.path?
! """
! if len(ps)==0:
! return ''
! prefix= ps[0]
! for p in ps[1:]:
! prefix= prefix[:len(p)]
! for i in range(len(prefix)):
! if prefix[i] <> p[i]:
! prefix= prefix[:i]
! if i==0:
! return ''
! break
! return prefix
***************
*** 181,197 ****
def getsize(p):
"""
! Return the size of a file, reported by os.stat().
! """
! st= os.stat(p)
! return st[stat.ST_SIZE]
def getmtime(p):
"""
! Return the last modification time of a file, reported by os.stat().
! """
! st = os.stat(p)
! return st[stat.ST_MTIME]
getatime= getmtime
--- 181,197 ----
def getsize(p):
+ """
+ Return the size of a file, reported by os.stat().
"""
! st= os.stat(p)
! return st[stat.ST_SIZE]
def getmtime(p):
+ """
+ Return the last modification time of a file, reported by os.stat().
"""
! st = os.stat(p)
! return st[stat.ST_MTIME]
getatime= getmtime
***************
*** 201,238 ****
def exists(p):
"""
! Test whether a path exists.
! """
! try:
! return swi.swi('OS_File', '5s;i', p)!=0
! except swi.error:
! return 0
def isdir(p):
"""
! Is a path a directory? Includes image files.
! """
! try:
! return swi.swi('OS_File', '5s;i', p) in [2, 3]
! except swi.error:
! return 0
def isfile(p):
"""
! Test whether a path is a file, including image files.
! """
! try:
! return swi.swi('OS_File', '5s;i', p) in [1, 3]
! except swi.error:
! return 0
def islink(p):
"""
! RISC OS has no links or mounts.
! """
! return _false
ismount= islink
--- 201,238 ----
def exists(p):
+ """
+ Test whether a path exists.
"""
! try:
! return swi.swi('OS_File', '5s;i', p)!=0
! except swi.error:
! return 0
def isdir(p):
+ """
+ Is a path a directory? Includes image files.
"""
! try:
! return swi.swi('OS_File', '5s;i', p) in [2, 3]
! except swi.error:
! return 0
def isfile(p):
+ """
+ Test whether a path is a file, including image files.
"""
! try:
! return swi.swi('OS_File', '5s;i', p) in [1, 3]
! except swi.error:
! return 0
def islink(p):
+ """
+ RISC OS has no links or mounts.
"""
! return _false
ismount= islink
***************
*** 247,267 ****
def samefile(fa, fb):
"""
! Test whether two pathnames reference the same actual file.
! """
! l= 512
! b= swi.block(l)
! swi.swi('OS_FSControl', 'isb..i', 37, fa, b, l)
! fa= b.ctrlstring()
! swi.swi('OS_FSControl', 'isb..i', 37, fb, b, l)
! fb= b.ctrlstring()
! return fa==fb
def sameopenfile(a, b):
"""
! Test whether two open file objects reference the same file.
! """
! return os.fstat(a)[stat.ST_INO]==os.fstat(b)[stat.ST_INO]
--- 247,267 ----
def samefile(fa, fb):
+ """
+ Test whether two pathnames reference the same actual file.
"""
! l= 512
! b= swi.block(l)
! swi.swi('OS_FSControl', 'isb..i', 37, fa, b, l)
! fa= b.ctrlstring()
! swi.swi('OS_FSControl', 'isb..i', 37, fb, b, l)
! fb= b.ctrlstring()
! return fa==fb
def sameopenfile(a, b):
+ """
+ Test whether two open file objects reference the same file.
"""
! return os.fstat(a)[stat.ST_INO]==os.fstat(b)[stat.ST_INO]
***************
*** 272,311 ****
def expanduser(p):
! (fs, drive, path)= _split(p)
! l= 512
! b= swi.block(l)
!
! if path[:1]!='@':
! return p
! if fs=='':
! fsno= swi.swi('OS_Args', '00;i')
! swi.swi('OS_FSControl', 'iibi', 33, fsno, b, l)
! fsname= b.ctrlstring()
! else:
! if fs[:1]=='-':
! fsname= fs[1:-1]
else:
! fsname= fs[:-1]
! fsname= string.split(fsname, '#', 1)[0] # remove special field from fs
! x= swi.swi('OS_FSControl', 'ib2s.i;.....i', 54, b, fsname, l)
! if x<l:
! urd= b.tostring(0, l-x-1)
! else: # no URD! try CSD
! x= swi.swi('OS_FSControl', 'ib0s.i;.....i', 54, b, fsname, l)
if x<l:
! urd= b.tostring(0, l-x-1)
! else: # no CSD! use root
! urd= '$'
! return fsname+':'+urd+path[1:]
# Environment variables are in angle brackets.
def expandvars(p):
"""
! Expand environment variables using OS_GSTrans.
! """
! l= 512
! b= swi.block(l)
! return b.tostring(0, swi.swi('OS_GSTrans', 'sbi;..i', p, b, l))
--- 272,311 ----
def expanduser(p):
! (fs, drive, path)= _split(p)
! l= 512
! b= swi.block(l)
!
! if path[:1]!='@':
! return p
! if fs=='':
! fsno= swi.swi('OS_Args', '00;i')
! swi.swi('OS_FSControl', 'iibi', 33, fsno, b, l)
! fsname= b.ctrlstring()
else:
! if fs[:1]=='-':
! fsname= fs[1:-1]
! else:
! fsname= fs[:-1]
! fsname= string.split(fsname, '#', 1)[0] # remove special field from fs
! x= swi.swi('OS_FSControl', 'ib2s.i;.....i', 54, b, fsname, l)
if x<l:
! urd= b.tostring(0, l-x-1)
! else: # no URD! try CSD
! x= swi.swi('OS_FSControl', 'ib0s.i;.....i', 54, b, fsname, l)
! if x<l:
! urd= b.tostring(0, l-x-1)
! else: # no CSD! use root
! urd= '$'
! return fsname+':'+urd+path[1:]
# Environment variables are in angle brackets.
def expandvars(p):
+ """
+ Expand environment variables using OS_GSTrans.
"""
! l= 512
! b= swi.block(l)
! return b.tostring(0, swi.swi('OS_GSTrans', 'sbi;..i', p, b, l))
***************
*** 313,317 ****
def abspath(p):
! return normpath(join(os.getcwd(), p))
--- 313,317 ----
def abspath(p):
! return normpath(join(os.getcwd(), p))
***************
*** 319,344 ****
def normpath(p):
"""
! Normalize path, eliminating up-directory ^s.
! """
! (fs, drive, path)= _split(p)
! rhs= ''
! ups= 0
! while path!='':
! (path, el)= split(path)
! if el=='^':
! ups= ups+1
! else:
! if ups>0:
! ups= ups-1
! else:
! if rhs=='':
! rhs= el
else:
! rhs= el+'.'+rhs
! while ups>0:
! ups= ups-1
! rhs= '^.'+rhs
! return fs+drive+rhs
--- 319,344 ----
def normpath(p):
+ """
+ Normalize path, eliminating up-directory ^s.
"""
! (fs, drive, path)= _split(p)
! rhs= ''
! ups= 0
! while path!='':
! (path, el)= split(path)
! if el=='^':
! ups= ups+1
else:
! if ups>0:
! ups= ups-1
! else:
! if rhs=='':
! rhs= el
! else:
! rhs= el+'.'+rhs
! while ups>0:
! ups= ups-1
! rhs= '^.'+rhs
! return fs+drive+rhs
***************
*** 347,363 ****
def walk(top, func, arg):
! """
! walk(top,func,args) calls func(arg, d, files) for each directory "d" in the tree
! rooted at "top" (including "top" itself). "files" is a list of all the files and
! subdirs in directory "d".
! """
! try:
! names= os.listdir(top)
! except os.error:
! return
! func(arg, top, names)
! for name in names:
! name= join(top, name)
! if isdir(name) and not islink(name):
! walk(name, func, arg)
!
--- 347,362 ----
def walk(top, func, arg):
! """
! walk(top,func,args) calls func(arg, d, files) for each directory "d" in the tree
! rooted at "top" (including "top" itself). "files" is a list of all the files and
! subdirs in directory "d".
! """
! try:
! names= os.listdir(top)
! except os.error:
! return
! func(arg, top, names)
! for name in names:
! name= join(top, name)
! if isdir(name) and not islink(name):
! walk(name, func, arg)
Index: rourl2path.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/plat-riscos/rourl2path.py,v
retrieving revision 1.1
retrieving revision 1.1.6.1
diff -C2 -r1.1 -r1.1.6.1
*** rourl2path.py 2001/03/02 05:55:07 1.1
--- rourl2path.py 2001/07/06 07:28:36 1.1.6.1
***************
*** 14,62 ****
tp = urllib.splittype(pathname)[0]
if tp and tp <> 'file':
! raise RuntimeError, 'Cannot convert non-local URL to pathname'
components = string.split(pathname, '/')
# Remove . and embedded ..
i = 0
while i < len(components):
! if components[i] == '.':
! del components[i]
! elif components[i] == '..' and i > 0 and \
! components[i-1] not in ('', '..'):
! del components[i-1:i+1]
! i = i-1
! elif components[i] == '' and i > 0 and components[i-1] <> '':
! del components[i]
! else:
! if components[i]<>'..' and string.find(components[i], '.')<>-1 :
! components[i] = string.join(string.split(components[i],'.'),'/')
! i = i+1
if not components[0]:
! # Absolute unix path, don't start with colon
! return string.join(components[1:], '.')
else:
! # relative unix path, start with colon. First replace
! # leading .. by empty strings (giving ::file)
! i = 0
! while i < len(components) and components[i] == '..':
! components[i] = '^'
! i = i + 1
! return string.join(components, '.')
def pathname2url(pathname):
"convert mac pathname to /-delimited pathname"
if '/' in pathname:
! raise RuntimeError, "Cannot convert pathname containing slashes"
components = string.split(pathname, ':')
# Replace empty string ('::') by .. (will result in '/../' later)
for i in range(1, len(components)):
! if components[i] == '':
! components[i] = '..'
# Truncate names longer than 31 bytes
components = map(lambda x: x[:31], components)
if os.path.isabs(pathname):
! return '/' + string.join(components, '/')
else:
! return string.join(components, '/')
def test():
--- 14,62 ----
tp = urllib.splittype(pathname)[0]
if tp and tp <> 'file':
! raise RuntimeError, 'Cannot convert non-local URL to pathname'
components = string.split(pathname, '/')
# Remove . and embedded ..
i = 0
while i < len(components):
! if components[i] == '.':
! del components[i]
! elif components[i] == '..' and i > 0 and \
! components[i-1] not in ('', '..'):
! del components[i-1:i+1]
! i = i-1
! elif components[i] == '' and i > 0 and components[i-1] <> '':
! del components[i]
! else:
! if components[i]<>'..' and string.find(components[i], '.')<>-1 :
! components[i] = string.join(string.split(components[i],'.'),'/')
! i = i+1
if not components[0]:
! # Absolute unix path, don't start with colon
! return string.join(components[1:], '.')
else:
! # relative unix path, start with colon. First replace
! # leading .. by empty strings (giving ::file)
! i = 0
! while i < len(components) and components[i] == '..':
! components[i] = '^'
! i = i + 1
! return string.join(components, '.')
def pathname2url(pathname):
"convert mac pathname to /-delimited pathname"
if '/' in pathname:
! raise RuntimeError, "Cannot convert pathname containing slashes"
components = string.split(pathname, ':')
# Replace empty string ('::') by .. (will result in '/../' later)
for i in range(1, len(components)):
! if components[i] == '':
! components[i] = '..'
# Truncate names longer than 31 bytes
components = map(lambda x: x[:31], components)
if os.path.isabs(pathname):
! return '/' + string.join(components, '/')
else:
! return string.join(components, '/')
def test():
***************
*** 64,81 ****
"/SCSI::SCSI4/$/Anwendung/Comm/Apps/!Fresco/Welcome",
"../index.html",
! "bar/index.html",
! "/foo/bar/index.html",
! "/foo/bar/",
! "/"]:
! print `url`, '->', `url2pathname(url)`
for path in ["drive:",
! "drive:dir:",
! "drive:dir:file",
! "drive:file",
! "file",
! ":file",
! ":dir:",
! ":dir:file"]:
! print `path`, '->', `pathname2url(path)`
if __name__ == '__main__':
--- 64,81 ----
"/SCSI::SCSI4/$/Anwendung/Comm/Apps/!Fresco/Welcome",
"../index.html",
! "bar/index.html",
! "/foo/bar/index.html",
! "/foo/bar/",
! "/"]:
! print `url`, '->', `url2pathname(url)`
for path in ["drive:",
! "drive:dir:",
! "drive:dir:file",
! "drive:file",
! "file",
! ":file",
! ":dir:",
! ":dir:file"]:
! print `path`, '->', `pathname2url(path)`
if __name__ == '__main__':