#!/usr/bin/env python """emano schemes - http.py""" import urllib, httplib, urlparse # @@ Redefine URI getter def read(doc, uri): u = urllib.urlopen(uri) info = u.info() if isinstance(info, list): pass # @@ got some kind of error message elif info.has_key('Content-Type'): contentType = info.get('Content-Type') if 'charset=' in contentType: # @@ Check for a better charset= parsing algorithm charset = contentType[contentType.find('charset=')+8:] doc.encoding = charset.strip('"') for line in u: doc.append(line) if line.endswith('\n'): doc.append('') u.close() def write(doc, uri): scheme, host, path, params, query, frag = urlparse.urlparse(uri) body = doc.getContent() h = httplib.HTTPConnection(host) h.request("PUT", path, body) response = h.getresponse() msg = 'Got: %s %s from %s (200, 201, or 204 indicate success)' msg = msg % (response.status, response.reason or '-', host) if int(response.status) in (200, 201, 204): doc.rehash() return msg if __name__=="__main__": print __doc__