added comments, reverted to popen and print

some error messages about invalid arguments
This commit is contained in:
Dimitur Kirov 2006-02-04 00:13:12 +00:00
parent ec1d354c80
commit 2525fef3a8
1 changed files with 11 additions and 5 deletions

View File

@ -92,6 +92,9 @@ class Resolver:
except ValueError: except ValueError:
continue continue
elif prop_type.find('host') > -1: elif prop_type.find('host') > -1:
# strip '.' at the end of hostname
if prop_value[-1] == '.':
prop_value = prop_value[:-1]
current_host['host'] = prop_value current_host['host'] = prop_value
if len(current_host) == 4: if len(current_host) == 4:
hosts.append(current_host) hosts.append(current_host)
@ -99,7 +102,8 @@ class Resolver:
return hosts return hosts
def _parse_srv_result_posix(self, fqdn, result): def _parse_srv_result_posix(self, fqdn, result):
# typical output of bind-tools nslookup command # typical output of bind-tools nslookup command:
# _xmpp-client._tcp.jabber.org service = 30 30 5222 jabber.org.
if not result: if not result:
return [] return []
hosts = [] hosts = []
@ -167,6 +171,7 @@ class Resolver:
self.handlers[host] = [on_ready] self.handlers[host] = [on_ready]
self.start_resolve(host) self.start_resolve(host)
# TODO: move IdleCommand class in other file, maybe helpers ?
class IdleCommand(IdleObject): class IdleCommand(IdleObject):
def __init__(self, on_result): def __init__(self, on_result):
# how long (sec.) to wait for result ( 0 - forever ) # how long (sec.) to wait for result ( 0 - forever )
@ -229,10 +234,9 @@ class IdleCommand(IdleObject):
self.idlequeue.set_alarm(self.wait_child, 0.1) self.idlequeue.set_alarm(self.wait_child, 0.1)
def _start_posix(self): def _start_posix(self):
write_d, self.pipe = os.popen4(self._compose_command_line()) self.pipe = os.popen(self._compose_command_line())
write_d.close()
self.fd = self.pipe.fileno() self.fd = self.pipe.fileno()
#~ fcntl.fcntl(self.pipe, fcntl.F_SETFL, os.O_NONBLOCK) fcntl.fcntl(self.pipe, fcntl.F_SETFL, os.O_NONBLOCK)
self.idlequeue.plug_idle(self, False, True) self.idlequeue.plug_idle(self, False, True)
if self.commandtimeout >= 0: if self.commandtimeout >= 0:
self.idlequeue.set_read_timeout(self.fd, self.commandtimeout) self.idlequeue.set_read_timeout(self.fd, self.commandtimeout)
@ -271,11 +275,12 @@ class NsLookup(IdleCommand):
self.type = type.lower() self.type = type.lower()
if not host_pattern.match(self.host): if not host_pattern.match(self.host):
# invalid host name # invalid host name
# TODO: notify user about this. Maybe message to stderr will be enough print >> sys.stderr, 'Invalid host: %s' % self.host
self.host = None self.host = None
self.canexecute = False self.canexecute = False
return return
if not ns_type_pattern.match(self.type): if not ns_type_pattern.match(self.type):
print >> sys.stderr, 'Invalid querytype: %s' % self.type
self.type = None self.type = None
self.host = None self.host = None
self.canexecute = False self.canexecute = False
@ -289,6 +294,7 @@ class NsLookup(IdleCommand):
self.result_handler(self.host, self.result) self.result_handler(self.host, self.result)
self.result_handler = None self.result_handler = None
# TODO: remove below lines if there is nothing more to test
if __name__ == '__main__': if __name__ == '__main__':
if os.name != 'posix': if os.name != 'posix':
sys.exit() sys.exit()