summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSol Jerome <sol.jerome@gmail.com>2011-06-14 15:23:31 -0500
committerSol Jerome <sol.jerome@gmail.com>2011-06-14 15:23:31 -0500
commitb1ab3e2bab9f07c13daf5dcfd4a9502eb84dcf0d (patch)
treeea17ecbdf858a28520e9e86ece2ef68483be64ab
parent2c9a76cdfcce02f8d89129405f1f477753c47d3c (diff)
downloadbcfg2-b1ab3e2bab9f07c13daf5dcfd4a9502eb84dcf0d.tar.gz
bcfg2-b1ab3e2bab9f07c13daf5dcfd4a9502eb84dcf0d.tar.bz2
bcfg2-b1ab3e2bab9f07c13daf5dcfd4a9502eb84dcf0d.zip
PY3K: Finish server-side code fixes
Signed-off-by: Sol Jerome <sol.jerome@gmail.com>
-rw-r--r--src/lib/SSLServer.py18
-rw-r--r--src/lib/Server/Core.py4
-rw-r--r--src/lib/Server/Plugin.py3
-rw-r--r--src/lib/Server/Plugins/Cfg.py5
-rw-r--r--src/lib/Server/Plugins/Metadata.py2
-rw-r--r--src/lib/Server/Plugins/Probes.py5
-rw-r--r--src/lib/Server/Plugins/SSHbase.py21
7 files changed, 39 insertions, 19 deletions
diff --git a/src/lib/SSLServer.py b/src/lib/SSLServer.py
index 8cac8a53f..bb0f61198 100644
--- a/src/lib/SSLServer.py
+++ b/src/lib/SSLServer.py
@@ -46,7 +46,11 @@ class XMLRPCDispatcher (SimpleXMLRPCServer.SimpleXMLRPCDispatcher):
if '.' not in method:
params = (address, ) + params
response = self.instance._dispatch(method, params, self.funcs)
- response = (response, )
+ # py3k compatibility
+ if isinstance(response, bool) or isinstance(response, str):
+ response = (response, )
+ else:
+ response = (response.decode('utf-8'), )
raw_response = xmlrpclib.dumps(response, methodresponse=1,
allow_none=self.allow_none,
encoding=self.encoding)
@@ -191,9 +195,14 @@ class XMLRPCRequestHandler (SimpleXMLRPCServer.SimpleXMLRPCRequestHandler):
self.logger.error("No authentication data presented")
return False
auth_type, auth_content = header.split()
- auth_content = base64.standard_b64decode(auth_content)
+ auth_content = base64.standard_b64decode(bytes(auth_content.encode('ascii')))
try:
- username, password = auth_content.split(":")
+ # py3k compatibility
+ try:
+ username, password = auth_content.split(":")
+ except TypeError:
+ username, pw = auth_content.split(b":")
+ password = pw.decode('utf-8')
except ValueError:
username = auth_content
password = ""
@@ -234,11 +243,12 @@ class XMLRPCRequestHandler (SimpleXMLRPCServer.SimpleXMLRPCRequestHandler):
print("got select timeout")
raise
chunk_size = min(size_remaining, max_chunk_size)
- L.append(self.rfile.read(chunk_size))
+ L.append(self.rfile.read(chunk_size).decode('utf-8'))
size_remaining -= len(L[-1])
data = ''.join(L)
response = self.server._marshaled_dispatch(self.client_address,
data)
+ response = response.encode('utf-8')
except:
try:
self.send_response(500)
diff --git a/src/lib/Server/Core.py b/src/lib/Server/Core.py
index 8f9d3e746..5adfa5381 100644
--- a/src/lib/Server/Core.py
+++ b/src/lib/Server/Core.py
@@ -384,7 +384,7 @@ class Core(Component):
# clear dynamic groups
self.metadata.cgroups[meta.hostname] = []
try:
- xpdata = lxml.etree.XML(probedata)
+ xpdata = lxml.etree.XML(probedata.encode('utf-8'))
except:
self.logger.error("Failed to parse probe data from client %s" % \
(address[0]))
@@ -433,7 +433,7 @@ class Core(Component):
@exposed
def RecvStats(self, address, stats):
"""Act on statistics upload."""
- sdata = lxml.etree.XML(stats)
+ sdata = lxml.etree.XML(stats.encode('utf-8'))
client = self.metadata.resolve_client(address)
self.process_statistics(client, sdata)
return "<ok/>"
diff --git a/src/lib/Server/Plugin.py b/src/lib/Server/Plugin.py
index 3b331b300..3a36baf8e 100644
--- a/src/lib/Server/Plugin.py
+++ b/src/lib/Server/Plugin.py
@@ -693,6 +693,9 @@ class Specificity:
self.prio = prio
self.delta = delta
+ def __lt__(self, other):
+ return self.__cmp__(other) < 0
+
def matches(self, metadata):
return self.all or \
self.hostname == metadata.hostname or \
diff --git a/src/lib/Server/Plugins/Cfg.py b/src/lib/Server/Plugins/Cfg.py
index c08e8c4b6..4a0fd2dfe 100644
--- a/src/lib/Server/Plugins/Cfg.py
+++ b/src/lib/Server/Plugins/Cfg.py
@@ -4,6 +4,7 @@ __revision__ = '$Revision$'
import binascii
import logging
import lxml
+import operator
import os
import os.path
import re
@@ -25,7 +26,7 @@ logger = logging.getLogger('Bcfg2.Plugins.Cfg')
def u_str(string, encoding):
if sys.hexversion >= 0x03000000:
- return str(string, encoding)
+ return string.encode(encoding)
else:
return unicode(string, encoding)
@@ -105,7 +106,7 @@ class CfgEntrySet(Bcfg2.Server.Plugin.EntrySet):
"""
matching = [ent for ent in list(self.entries.values()) if \
ent.specific.matches(metadata)]
- matching.sort(self.sort_by_specific)
+ matching.sort(key=operator.attrgetter('specific'))
non_delta = [matching.index(m) for m in matching
if not m.specific.delta]
if not non_delta:
diff --git a/src/lib/Server/Plugins/Metadata.py b/src/lib/Server/Plugins/Metadata.py
index ca6e43851..6570f2912 100644
--- a/src/lib/Server/Plugins/Metadata.py
+++ b/src/lib/Server/Plugins/Metadata.py
@@ -766,7 +766,7 @@ class Metadata(Bcfg2.Server.Plugin.Plugin,
(address[0]))
return False
# populate the session cache
- if user != 'root':
+ if user.decode('utf-8') != 'root':
self.session_cache[address] = (time.time(), client)
return True
diff --git a/src/lib/Server/Plugins/Probes.py b/src/lib/Server/Plugins/Probes.py
index ea2e79ccc..3599f2af1 100644
--- a/src/lib/Server/Plugins/Probes.py
+++ b/src/lib/Server/Plugins/Probes.py
@@ -1,4 +1,5 @@
import lxml.etree
+import operator
import re
import Bcfg2.Server.Plugin
@@ -27,7 +28,7 @@ class ProbeSet(Bcfg2.Server.Plugin.EntrySet):
ret = []
build = dict()
candidates = self.get_matching(metadata)
- candidates.sort(lambda x, y: cmp(x.specific, y.specific))
+ candidates.sort(key=operator.attrgetter('specific'))
for entry in candidates:
rem = specific_probe_matcher.match(entry.name)
if not rem:
@@ -90,7 +91,7 @@ class Probes(Bcfg2.Server.Plugin.Plugin,
datafile = open("%s/%s" % (self.data, 'probed.xml'), 'w')
except IOError:
self.logger.error("Failed to write probed.xml")
- datafile.write(data)
+ datafile.write(data.decode('utf-8'))
def load_data(self):
try:
diff --git a/src/lib/Server/Plugins/SSHbase.py b/src/lib/Server/Plugins/SSHbase.py
index cf0998aaa..4a33c0cb0 100644
--- a/src/lib/Server/Plugins/SSHbase.py
+++ b/src/lib/Server/Plugins/SSHbase.py
@@ -39,12 +39,17 @@ class SSHbase(Bcfg2.Server.Plugin.Plugin,
__author__ = 'bcfg-dev@mcs.anl.gov'
pubkeys = ["ssh_host_dsa_key.pub.H_%s",
- "ssh_host_rsa_key.pub.H_%s", "ssh_host_key.pub.H_%s"]
+ "ssh_host_rsa_key.pub.H_%s",
+ "ssh_host_key.pub.H_%s"]
hostkeys = ["ssh_host_dsa_key.H_%s",
- "ssh_host_rsa_key.H_%s", "ssh_host_key.H_%s"]
- keypatterns = ['ssh_host_dsa_key', 'ssh_host_rsa_key', 'ssh_host_key',
- 'ssh_host_dsa_key.pub', 'ssh_host_rsa_key.pub',
- 'ssh_host_key.pub']
+ "ssh_host_rsa_key.H_%s",
+ "ssh_host_key.H_%s"]
+ keypatterns = ["ssh_host_dsa_key",
+ "ssh_host_rsa_key",
+ "ssh_host_key",
+ "ssh_host_dsa_key.pub",
+ "ssh_host_rsa_key.pub",
+ "ssh_host_key.pub"]
def __init__(self, core, datastore):
Bcfg2.Server.Plugin.Plugin.__init__(self, core, datastore)
@@ -74,7 +79,7 @@ class SSHbase(Bcfg2.Server.Plugin.Plugin,
def get_skn(self):
"""Build memory cache of the ssh known hosts file."""
if not self.__skn:
- self.__skn = "\n".join([str(value.data) for key, value in \
+ self.__skn = "\n".join([value.data.decode() for key, value in \
list(self.entries.items()) if \
key.endswith('.static')])
names = dict()
@@ -117,7 +122,7 @@ class SSHbase(Bcfg2.Server.Plugin.Plugin,
self.logger.error("SSHbase: Unknown host %s; ignoring public keys" % hostname)
continue
self.__skn += "%s %s" % (','.join(names[hostname]),
- self.entries[pubkey].data)
+ self.entries[pubkey].data.decode())
return self.__skn
def set_skn(self, value):
@@ -206,7 +211,7 @@ class SSHbase(Bcfg2.Server.Plugin.Plugin,
hostkeys.sort()
for hostkey in hostkeys:
entry.text += "localhost,localhost.localdomain,127.0.0.1 %s" % (
- self.entries[hostkey].data)
+ self.entries[hostkey].data.decode())
permdata = {'owner': 'root',
'group': 'root',
'type': 'file',