def gopher_open(self, req):
     host = req.get_host()
     if not host:
         raise GopherError("no host given")
     host = unquote(host)
     selector = req.get_selector()
     type, selector = splitgophertype(selector)
     selector, query = splitquery(selector)
     selector = unquote(selector)
     if query:
         query = unquote(query)
         fp = gopherlib.send_query(selector, query, host)
     else:
         fp = gopherlib.send_selector(selector, host)
     return addinfourl(fp, noheaders(), req.get_full_url())
示例#2
0
 def gopher_open(self, req):
     host = req.get_host()
     if not host:
         raise GopherError('no host given')
     host = unquote(host)
     selector = req.get_selector()
     type, selector = splitgophertype(selector)
     selector, query = splitquery(selector)
     selector = unquote(selector)
     if query:
         query = unquote(query)
         fp = gopherlib.send_query(selector, query, host)
     else:
         fp = gopherlib.send_selector(selector, host)
     return addinfourl(fp, noheaders(), req.get_full_url())
示例#3
0
 def gopher_open(self, req):
     # XXX can raise socket.error
     import gopherlib  # this raises DeprecationWarning in 2.5
     host = req.get_host()
     if not host:
         raise GopherError('no host given')
     host = unquote(host)
     selector = req.get_selector()
     type, selector = splitgophertype(selector)
     selector, query = splitquery(selector)
     selector = unquote(selector)
     if query:
         query = unquote(query)
         fp = gopherlib.send_query(selector, query, host)
     else:
         fp = gopherlib.send_selector(selector, host)
     return addinfourl(fp, noheaders(), req.get_full_url())
示例#4
0
 def gopher_open(self, req):
     # XXX can raise socket.error
     import gopherlib  # this raises DeprecationWarning in 2.5
     host = req.get_host()
     if not host:
         raise GopherError('no host given')
     host = unquote(host)
     selector = req.get_selector()
     type, selector = splitgophertype(selector)
     selector, query = splitquery(selector)
     selector = unquote(selector)
     if query:
         query = unquote(query)
         fp = gopherlib.send_query(selector, query, host)
     else:
         fp = gopherlib.send_selector(selector, host)
     return addinfourl(fp, noheaders(), req.get_full_url())
示例#5
0
class FTPHandler(BaseHandler):
    def ftp_open(self, req):
        host = req.get_host()
        if not host:
            raise IOError, ('ftp error', 'no host given')
        # XXX handle custom username & password
        try:
            host = socket.gethostbyname(host)
        except socket.error, msg:
            raise URLError(msg)
        host, port = splitport(host)
        if port is None:
            port = ftplib.FTP_PORT
        path, attrs = splitattr(req.get_selector())
        path = unquote(path)
        dirs = string.splitfields(path, '/')
        dirs, file = dirs[:-1], dirs[-1]
        if dirs and not dirs[0]:
            dirs = dirs[1:]
        user = passwd = ''  # XXX
        try:
            fw = self.connect_ftp(user, passwd, host, port, dirs)
            type = file and 'I' or 'D'
            for attr in attrs:
                attr, value = splitattr(attr)
                if string.lower(attr) == 'type' and \
                   value in ('a', 'A', 'i', 'I', 'd', 'D'):
                    type = string.upper(value)
            fp, retrlen = fw.retrfile(file, type)
            if retrlen is not None and retrlen >= 0:
                sf = StringIO('Content-Length: %d\n' % retrlen)
                headers = mimetools.Message(sf)
            else:
                headers = noheaders()
            return addinfourl(fp, headers, req.get_full_url())
        except ftplib.all_errors, msg:
            raise IOError, ('ftp error', msg), sys.exc_info()[2]
示例#6
0
"""An extensible library for opening URLs using a variety of protocols
示例#7
0
"""An extensible library for opening URLs using a variety of protocols