Skip to content

Commit

Permalink
unify strings
Browse files Browse the repository at this point in the history
  • Loading branch information
cygnusb committed Nov 3, 2018
1 parent c4daed1 commit e1d23d4
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions pypureomapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ def lookup_host(self, name):
ip = unpack_ip(dict(response.obj)[b"ip-address"])
mac = unpack_mac(dict(response.obj)[b"hardware-address"])
hostname = dict(response.obj)[b"name"]
return {'ip': ip, 'mac': mac, 'hostname': hostname.decode('utf-8')}
return {"ip": ip, "mac": mac, "hostname": hostname.decode('utf-8')}
except KeyError:
raise OmapiErrorNotFound()

Expand All @@ -1201,7 +1201,7 @@ def lookup_host_host(self, mac):
could be found or the object lacks an ip address or mac
@raises socket.error:
"""
return self.lookup('host', ['ip', 'mac', 'name'], mac=mac)
return self.lookup("host", ["ip", "mac", "name"], mac=mac)

def lookup_hostname(self, ip):
"""Look up a lease object with given ip address and return the associated client hostname.
Expand Down Expand Up @@ -1248,16 +1248,16 @@ def lookup(self, ltype, rvalues=[], ip=None, mac=None, name=None):
print("response is ", dict(response.obj))
result = {}
for elem in rvalues:
if elem == 'ip':
result['ip'] = unpack_ip(dict(response.obj)[b"ip-address"])
if elem == 'mac':
result['mac'] = unpack_mac(dict(response.obj)[b"hardware-address"])
if elem == 'name':
if elem == "ip":
result["ip"] = unpack_ip(dict(response.obj)[b"ip-address"])
if elem == "mac":
result["mac"] = unpack_mac(dict(response.obj)[b"hardware-address"])
if elem == "name":
hostname = dict(response.obj)[b"name"]
result['hostname'] = hostname.decode('utf-8')
if elem == 'client-hostname':
result["hostname"] = hostname.decode("utf-8")
if elem == "client-hostname":
hostname = dict(response.obj)[b"client-hostname"]
result['client-hostname'] = hostname.decode('utf-8')
result["client-hostname"] = hostname.decode("utf-8")
if len(result) == 1:
result = list(result.values())[0]
return result
Expand Down Expand Up @@ -1330,14 +1330,14 @@ def add_host_supersede(self, ip, mac, name, hostname=None, router=None, domain=N
if domain:
stmts.append('supersede domain-name "{0}";'.format(domain))
if stmts:
encoded_stmts = ''.join(stmts).encode('utf-8')
encoded_stmts = "".join(stmts).encode("utf-8")
msg.obj.append((b"statements", encoded_stmts))

response = self.query_server(msg)
if response.opcode != OMAPI_OP_UPDATE:
raise OmapiError("add failed")


if __name__ == '__main__':
if __name__ == "__main__":
import doctest
doctest.testmod()

0 comments on commit e1d23d4

Please sign in to comment.