From d2dd9a8b7f3446b904600ec5de6945a2d9f5598c Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Mon, 19 Jan 1998 21:59:48 +0000 Subject: [PATCH] Some patches by Lars Marius Garshol: - fix type_to_name(); it never worked - add path_to_selector() add path_to_datatype_name() --- Lib/gopherlib.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Lib/gopherlib.py b/Lib/gopherlib.py index cf06e958301..e91ef99eb70 100644 --- a/Lib/gopherlib.py +++ b/Lib/gopherlib.py @@ -38,10 +38,10 @@ # 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