summaryrefslogtreecommitdiffstats
path: root/Lib/dos-8x3/gopherli.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/dos-8x3/gopherli.py')
-rwxr-xr-xLib/dos-8x3/gopherli.py23
1 files changed, 20 insertions, 3 deletions
diff --git a/Lib/dos-8x3/gopherli.py b/Lib/dos-8x3/gopherli.py
index cf06e95..033e579 100755
--- a/Lib/dos-8x3/gopherli.py
+++ b/Lib/dos-8x3/gopherli.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,22 @@ 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=="/":
+ # No way to tell, although "INDEX" is likely
+ return "TYPE='unknown'"
+ 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
@@ -103,7 +119,8 @@ def get_directory(f):
continue
if len(parts) > 4:
if parts[4:] != ['+']:
- print '(Extra info from server:', parts[4:], ')'
+ print '(Extra info from server:',
+ print parts[4:], ')'
else:
parts.append('')
parts.insert(0, gtype)