summaryrefslogtreecommitdiff
path: root/Lib/macpath.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1990-12-26 15:40:07 +0000
committerGuido van Rossum <guido@python.org>1990-12-26 15:40:07 +0000
commit8aea97f072f02c97172370551cbad832de9f59b4 (patch)
treeb0bdfd34e5a72346a63106565acc7622a28b2a30 /Lib/macpath.py
parentf933243f378c90cab883fdfbb25e8ee0e434634c (diff)
downloadcpython-8aea97f072f02c97172370551cbad832de9f59b4.tar.gz
Initial revision
Diffstat (limited to 'Lib/macpath.py')
-rw-r--r--Lib/macpath.py70
1 files changed, 70 insertions, 0 deletions
diff --git a/Lib/macpath.py b/Lib/macpath.py
new file mode 100644
index 0000000000..30d2f27ad9
--- /dev/null
+++ b/Lib/macpath.py
@@ -0,0 +1,70 @@
+# module 'macpath'
+
+import mac
+
+import string
+
+from stat import *
+
+def isabs(s):
+ return ':' in s and s[0] <> ':'
+
+def cat(s, t):
+ if (not s) or isabs(t): return t
+ if t[:1] = ':': t = t[1:]
+ if ':' not in s:
+ s = ':' + s
+ if s[-1:] <> ':':
+ s = s + ':'
+ return s + t
+
+norm_error = 'path cannot be normalized'
+
+def norm(s):
+ if ':' not in s:
+ return ':' + s
+ f = string.splitfields(s, ':')
+ pre = []
+ post = []
+ if not f[0]:
+ pre = f[:1]
+ f = f[1:]
+ if not f[len(f)-1]:
+ post = f[-1:]
+ f = f[:-1]
+ res = []
+ for seg in f:
+ if seg:
+ res.append(seg)
+ else:
+ if not res: raise norm_error # starts with '::'
+ del res[len(res)-1]
+ if not (pre or res):
+ raise norm_error # starts with 'vol::'
+ if pre: res = pre + res
+ if post: res = res + post
+ s = res[0]
+ for seg in res[1:]:
+ s = s + ':' + seg
+ return s
+
+def isdir(s):
+ try:
+ st = mac.stat(s)
+ except mac.error:
+ return 0
+ return S_ISDIR(st[ST_MODE])
+
+def isfile(s):
+ try:
+ st = mac.stat(s)
+ except mac.error:
+ return 0
+ return S_ISREG(st[ST_MODE])
+
+def exists(s):
+ try:
+ st = mac.stat(s)
+ except mac.error:
+ return 0
+ return 1