def parse_srv_result(self, fqdn, result): """ Parse the output of host command and return list of properties: 'host', 'port','weight', 'priority' corresponding to the found srv hosts """ # typical output of host command: # _xmpp-client._tcp.jabber.org has SRV record 30 30 5222 jabber.org. if not result: return [] ufqdn = helpers.ascii_to_idn(fqdn) # Unicode domain name hosts = [] lines = result.split('\n') for line in lines: if line == '': continue domain = None if line.startswith(fqdn): domain = fqdn # For nslookup 9.5 elif helpers.decode_string(line).startswith(ufqdn): line = helpers.decode_string(line) domain = ufqdn # For nslookup 9.6 if domain: # add 4 for ' has' after domain name rest = line[len(domain)+4:].split('record') if len(rest) != 2: continue answer_type, props_str = rest if answer_type.strip() != 'SRV': continue props = props_str.strip().split(' ') if len(props) < 4: continue prio, weight, port, host = props[-4:] if host[-1] == '.': host = host[:-1] try: prio = int(prio) weight = int(weight) port = int(port) except ValueError: continue hosts.append({'host': host, 'port': port, 'weight': weight, 'prio': prio}) return hosts
def _parse_srv_result_posix(self, fqdn, result): # typical output of bind-tools nslookup command: # _xmpp-client._tcp.jabber.org service = 30 30 5222 jabber.org. if not result: return [] ufqdn = helpers.ascii_to_idn(fqdn) # Unicode domain name hosts = [] lines = result.split('\n') for line in lines: if line == '': continue domain = None if line.startswith(fqdn): domain = fqdn elif helpers.decode_string(line).startswith(ufqdn): line = helpers.decode_string(line) domain = ufqdn if domain: rest = line[len(domain):].split('=') if len(rest) != 2: continue answer_type, props_str = rest if answer_type.strip() != 'service': continue props = props_str.strip().split(' ') if len(props) < 4: continue prio, weight, port, host = props[-4:] if host[-1] == '.': host = host[:-1] try: prio = int(prio) weight = int(weight) port = int(port) except ValueError: continue hosts.append({ 'host': host, 'port': port, 'weight': weight, 'prio': prio }) return hosts
def try_run(argv, directory): try: p = popen_nt_friendly(argv, directory) out = p.communicate()[0] log.info(out) return p.wait() except Exception, e: return _('Error executing "%(command)s": %(error)s') % { 'command': " ".join(argv), 'error': helpers.decode_string(str(e))}
def try_run(argv, directory): try: p = popen_nt_friendly(argv, directory) out = p.communicate()[0] log.info(out) return p.wait() except Exception, e: return _('Error executing "%(command)s": %(error)s') % { 'command': " ".join(argv), 'error': helpers.decode_string(str(e)) }
def _parse_srv_result_posix(self, fqdn, result): # typical output of bind-tools nslookup command: # _xmpp-client._tcp.jabber.org service = 30 30 5222 jabber.org. if not result: return [] ufqdn = helpers.ascii_to_idn(fqdn) # Unicode domain name hosts = [] lines = result.split('\n') for line in lines: if line == '': continue domain = None if line.startswith(fqdn): domain = fqdn elif helpers.decode_string(line).startswith(ufqdn): line = helpers.decode_string(line) domain = ufqdn if domain: rest = line[len(domain):].split('=') if len(rest) != 2: continue answer_type, props_str = rest if answer_type.strip() != 'service': continue props = props_str.strip().split(' ') if len(props) < 4: continue prio, weight, port, host = props[-4:] if host[-1] == '.': host = host[:-1] try: prio = int(prio) weight = int(weight) port = int(port) except ValueError: continue hosts.append({'host': host, 'port': port,'weight': weight, 'prio': prio}) return hosts
def get_keys(self, secret = False): if secret: opt = '--list-secret-keys' else: opt = '--list-keys' proc = self.run(['--with-colons', opt], create_fhs=['stdout']) output = proc.handles['stdout'].read() proc.handles['stdout'].close() keys = {} lines = output.split('\n') for line in lines: sline = line.split(':') if (sline[0] == 'sec' and secret) or \ (sline[0] == 'pub' and not secret): # decode escaped chars name = eval('"' + sline[9].replace('"', '\\"') + '"') # make it unicode instance keys[sline[4][8:]] = helpers.decode_string(name) return keys try: proc.wait() except IOError: pass
def get_keys(self, secret=False): if secret: opt = '--list-secret-keys' else: opt = '--list-keys' proc = self.run(['--with-colons', opt], create_fhs=['stdout']) output = proc.handles['stdout'].read() proc.handles['stdout'].close() keys = {} lines = output.split('\n') for line in lines: sline = line.split(':') if (sline[0] == 'sec' and secret) or \ (sline[0] == 'pub' and not secret): # decode escaped chars name = eval('"' + sline[9].replace('"', '\\"') + '"') # make it unicode instance keys[sline[4][8:]] = helpers.decode_string(name) return keys try: proc.wait() except IOError: pass