summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1998-01-19 21:59:48 (GMT)
committerGuido van Rossum <guido@python.org>1998-01-19 21:59:48 (GMT)
commitd2dd9a8b7f3446b904600ec5de6945a2d9f5598c (patch)
tree7ebfa77e6eab7929b8a8fbe94f3188aaee51f466
parent758eec01728e41bce41ccc31ae96a856a4de6abc (diff)
downloadcpython-d2dd9a8b7f3446b904600ec5de6945a2d9f5598c.zip
cpython-d2dd9a8b7f3446b904600ec5de6945a2d9f5598c.tar.gz
cpython-d2dd9a8b7f3446b904600ec5de6945a2d9f5598c.tar.bz2
Some patches by Lars Marius Garshol:
- fix type_to_name(); it never worked - add path_to_selector() add path_to_datatype_name()
-rw-r--r--Lib/gopherlib.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/Lib/gopherlib.py b/Lib/gopherlib.py
index cf06e95..e91ef99 100644
--- a/Lib/gopherlib.py
+++ b/Lib/gopherlib.py
@@ -38,10 +38,10 @@ A_PLUS_SOUND = '<'
# Function mapping all file types to strings; unknown types become TYPE='x'
_names = dir()
-_type_to_name_map = None
+_type_to_name_map = {}
def type_to_name(gtype):
global _type_to_name_map
- if not _type_to_name_map:
+ if _type_to_name_map=={}:
for name in _names:
if name[:2] == 'A_':
_type_to_name_map[eval(name)] = name[2:]
@@ -75,6 +75,21 @@ def send_selector(selector, host, port = 0):
def send_query(selector, query, host, port = 0):
return send_selector(selector + '\t' + query, host, port)
+# Takes a path as returned by urlparse and returns the appropriate selector
+def path_to_selector(path):
+ if path=="/":
+ return "/"
+ else:
+ return path[2:] # Cuts initial slash and data type identifier
+
+# Takes a path as returned by urlparse and maps it to a string
+# See section 3.4 of RFC 1738 for details
+def path_to_datatype_name(path):
+ if path=="/":
+ return "TYPE='unknown'" # No way to tell, although "INDEX" is probable
+ else:
+ return type_to_name(path[1])
+
# The following functions interpret the data returned by the gopher
# server according to the expected type, e.g. textfile or directory