Beispiel #1
0
 def get_uri(self, password, interface, protocol, name, stype, domain, host,
             address, port, text):
     dstr = ""
     tt = typedict(text)
     display = tt.strget("display", "")
     username = tt.strget("username", "")
     mode = tt.strget("mode", "")
     if display and display.startswith(":"):
         dstr = display[1:]
     #append interface to IPv6 host URI for link local addresses ("fe80:"):
     if interface and if_indextoname and address.lower().startswith(
             "fe80:"):
         #ie: "fe80::c1:ac45:7351:ea69%eth1"
         address += "%%%s" % if_indextoname(interface)
     if username:
         if password:
             uri = "%s://%s:%s@%s" % (mode, username, password, address)
         else:
             uri = "%s://%s@%s" % (mode, username, address)
     else:
         uri = "%s://%s" % (mode, address)
     if port > 0 and DEFAULT_PORTS.get(mode, 0) != port:
         uri += ":%s" % port
     if protocol not in ("socket", "namedpipe"):
         uri += "/"
         if dstr:
             uri += "%s" % dstr
     return uri
Beispiel #2
0
 def get_uri(self, password, interface, protocol, name, stype, domain, host,
             address, port, text):
     dstr = ""
     tt = typedict(text)
     display = tt.strget("display", "")
     username = tt.strget("username", "")
     mode = tt.strget("mode", "")
     if not mode:
         #guess the mode from the service name,
         #ie: "localhost.localdomain :2 (wss)" -> "wss"
         #ie: "localhost.localdomain :2 (ssh-2)" -> "ssh"
         pos = name.rfind("(")
         if name.endswith(")") and pos > 0:
             mode = name[pos + 1:-1].split("-")[0]
             if mode not in ("tcp", "ws", "wss", "ssl", "ssh"):
                 return ""
         else:
             mode = "tcp"
     if display and display.startswith(":"):
         dstr = display[1:]
     #append interface to IPv6 host URI for link local addresses ("fe80:"):
     if interface and if_indextoname and address.lower().startswith(
             "fe80:"):
         #ie: "fe80::c1:ac45:7351:ea69%eth1"
         address += "%%%s" % if_indextoname(interface)
     if username:
         if password:
             uri = "%s://%s:%s@%s" % (mode, username, password, address)
         else:
             uri = "%s://%s@%s" % (mode, username, address)
     else:
         uri = "%s://%s" % (mode, address)
     if port > 0 and DEFAULT_PORTS.get(mode, 0) != port:
         uri += ":%s" % port
     if protocol not in ("socket", "namedpipe"):
         uri += "/"
         if dstr:
             uri += "%s" % dstr
     return uri