Commit 04324a26 authored by Rafael Monnerat's avatar Rafael Monnerat

py3: Use unicode2str

parent b2db5730
...@@ -33,7 +33,7 @@ import collections ...@@ -33,7 +33,7 @@ import collections
from Products.ERP5Type.UnrestrictedMethod import UnrestrictedMethod from Products.ERP5Type.UnrestrictedMethod import UnrestrictedMethod
from erp5.component.module.SlapOSCloud import _assertACI from erp5.component.module.SlapOSCloud import _assertACI
from Products.ERP5Type.Utils import unicode2str
from zLOG import LOG, INFO from zLOG import LOG, INFO
try: try:
...@@ -198,14 +198,14 @@ class SoftwareInstance(Item): ...@@ -198,14 +198,14 @@ class SoftwareInstance(Item):
for internet_protocol_address in compute_partition.contentValues(portal_type='Internet Protocol Address'): for internet_protocol_address in compute_partition.contentValues(portal_type='Internet Protocol Address'):
# XXX - There is new values, and we must keep compatibility # XXX - There is new values, and we must keep compatibility
address_tuple = ( address_tuple = (
internet_protocol_address.getNetworkInterface('').decode("UTF-8"), unicode2str(internet_protocol_address.getNetworkInterface('')),
internet_protocol_address.getIpAddress().decode("UTF-8")) unicode2str(internet_protocol_address.getIpAddress()))
if internet_protocol_address.getGatewayIpAddress('') and \ if internet_protocol_address.getGatewayIpAddress('') and \
internet_protocol_address.getNetmask(''): internet_protocol_address.getNetmask(''):
address_tuple = address_tuple + ( address_tuple = address_tuple + (
internet_protocol_address.getGatewayIpAddress().decode("UTF-8"), unicode2str(internet_protocol_address.getGatewayIpAddress()),
internet_protocol_address.getNetmask().decode("UTF-8"), unicode2str(internet_protocol_address.getNetmask()),
internet_protocol_address.getNetworkAddress('').decode("UTF-8")) unicode2str(internet_protocol_address.getNetworkAddress('')))
full_ip_list.append(address_tuple) full_ip_list.append(address_tuple)
else: else:
ip_list.append(address_tuple) ip_list.append(address_tuple)
...@@ -228,31 +228,31 @@ class SoftwareInstance(Item): ...@@ -228,31 +228,31 @@ class SoftwareInstance(Item):
self._getModificationDateAsTimestamp(shared_instance))) self._getModificationDateAsTimestamp(shared_instance)))
append({ append({
'slave_title': shared_instance.getTitle().decode("UTF-8"), 'slave_title': unicode2str(shared_instance.getTitle()),
'slap_software_type': \ 'slap_software_type': \
shared_instance.getSourceReference().decode("UTF-8"), unicode2str(shared_instance.getSourceReference()),
'slave_reference': shared_instance.getReference().decode("UTF-8"), 'slave_reference': unicode2str(shared_instance.getReference()),
'timestamp': shared_timestamp, 'timestamp': shared_timestamp,
'xml': shared_instance.getTextContent(), 'xml': shared_instance.getTextContent(),
'connection_xml': shared_instance.getConnectionXml(), 'connection_xml': shared_instance.getConnectionXml(),
}) })
timestamp = max(timestamp, shared_timestamp) timestamp = max(timestamp, shared_timestamp)
return { return {
'instance_guid': self.getReference().decode("UTF-8"), 'instance_guid': unicode2str(self.getReference()),
'instance_title': self.getTitle().decode("UTF-8"), 'instance_title': unicode2str(self.getTitle()),
'root_instance_title': instance_tree.getTitle().decode("UTF-8"), 'root_instance_title': unicode2str(instance_tree.getTitle()),
'root_instance_short_title': instance_tree.getShortTitle().decode("UTF-8"), 'root_instance_short_title': unicode2str(instance_tree.getShortTitle()),
'xml': self.getTextContent(), 'xml': self.getTextContent(),
'connection_xml': self.getConnectionXml(), 'connection_xml': self.getConnectionXml(),
'filter_xml': self.getSlaXml(), 'filter_xml': self.getSlaXml(),
'slap_computer_id': \ 'slap_computer_id': \
compute_partition.getParentValue().getReference().decode("UTF-8"), unicode2str(compute_partition.getParentValue().getReference()),
'slap_computer_partition_id': \ 'slap_computer_partition_id': \
compute_partition.getReference().decode("UTF-8"), unicode2str(compute_partition.getReference()),
'slap_software_type': \ 'slap_software_type': \
self.getSourceReference().decode("UTF-8"), unicode2str(self.getSourceReference()),
'slap_software_release_url': \ 'slap_software_release_url': \
self.getUrlString().decode("UTF-8"), unicode2str(self.getUrlString()),
'slave_instance_list': shared_instance_list, 'slave_instance_list': shared_instance_list,
'ip_list': ip_list, 'ip_list': ip_list,
'full_ip_list': full_ip_list, 'full_ip_list': full_ip_list,
...@@ -276,8 +276,8 @@ class SoftwareInstance(Item): ...@@ -276,8 +276,8 @@ class SoftwareInstance(Item):
for internet_protocol_address in compute_partition.contentValues( for internet_protocol_address in compute_partition.contentValues(
portal_type='Internet Protocol Address'): portal_type='Internet Protocol Address'):
ip_address_list.append( ip_address_list.append(
(internet_protocol_address.getNetworkInterface('').decode("UTF-8"), (unicode2str(internet_protocol_address.getNetworkInterface('')),
internet_protocol_address.getIpAddress().decode("UTF-8")) unicode2str(internet_protocol_address.getIpAddress()))
) )
return ip_address_list return ip_address_list
......
...@@ -32,6 +32,7 @@ from Products.ERP5Type.UnrestrictedMethod import UnrestrictedMethod ...@@ -32,6 +32,7 @@ from Products.ERP5Type.UnrestrictedMethod import UnrestrictedMethod
from Products.ERP5Type.tests.utils import DummyMailHostMixin from Products.ERP5Type.tests.utils import DummyMailHostMixin
from OFS.Traversable import NotFound from OFS.Traversable import NotFound
from erp5.component.module.SlapOSCloud import _assertACI from erp5.component.module.SlapOSCloud import _assertACI
from Products.ERP5Type.Utils import unicode2str
import time import time
from lxml import etree from lxml import etree
...@@ -64,8 +65,8 @@ class SlapOSComputeNodeMixin(object): ...@@ -64,8 +65,8 @@ class SlapOSComputeNodeMixin(object):
): ):
software_installation = _assertACI(software_installation.getObject()) software_installation = _assertACI(software_installation.getObject())
software_release_dict = { software_release_dict = {
"software_release": software_installation.getUrlString().decode('UTF-8'), "software_release": unicode2str(software_installation.getUrlString()),
"computer_guid": self.getReference().decode('UTF-8') "computer_guid": unicode2str(self.getReference())
} }
if software_installation.getSlapState() == 'destroy_requested': if software_installation.getSlapState() == 'destroy_requested':
software_release_dict["_requested_state"] = 'destroyed' software_release_dict["_requested_state"] = 'destroyed'
...@@ -85,7 +86,7 @@ class SlapOSComputeNodeMixin(object): ...@@ -85,7 +86,7 @@ class SlapOSComputeNodeMixin(object):
def _getCacheComputeNodeInformation(self, user): def _getCacheComputeNodeInformation(self, user):
compute_node_dict = { compute_node_dict = {
"_computer_id": self.getReference().decode("UTF-8"), "_computer_id": unicode2str(self.getReference()),
"_computer_partition_list": [], "_computer_partition_list": [],
"_software_release_list": self._getSoftwareReleaseValueList() "_software_release_list": self._getSoftwareReleaseValueList()
} }
...@@ -192,7 +193,7 @@ class SlapOSComputeNodeMixin(object): ...@@ -192,7 +193,7 @@ class SlapOSComputeNodeMixin(object):
return self._getCacheComputeNodeInformation(user), None return self._getCacheComputeNodeInformation(user), None
else: else:
compute_node_dict = { compute_node_dict = {
"_computer_id": self.getReference().decode("UTF-8"), "_computer_id": unicode2str(self.getReference()),
"_computer_partition_list": [], "_computer_partition_list": [],
"_software_release_list": [] "_software_release_list": []
} }
...@@ -259,10 +260,10 @@ class SlapOSComputeNodeMixin(object): ...@@ -259,10 +260,10 @@ class SlapOSComputeNodeMixin(object):
compute_node = compute_partition_document compute_node = compute_partition_document
while compute_node.getPortalType() != 'Compute Node': while compute_node.getPortalType() != 'Compute Node':
compute_node = compute_node.getParentValue() compute_node = compute_node.getParentValue()
compute_node_id = compute_node.getReference().decode("UTF-8") compute_node_id = unicode2str(compute_node.getReference())
partition_dict = { partition_dict = {
"compute_node_id": compute_node_id, "compute_node_id": compute_node_id,
"partition_id": compute_partition_document.getReference().decode("UTF-8"), "partition_id": unicode2str(compute_partition_document.getReference()),
"_software_release_document": None, "_software_release_document": None,
"_requested_state": 'destroyed', "_requested_state": 'destroyed',
"_need_modification": 0 "_need_modification": 0
...@@ -288,7 +289,7 @@ class SlapOSComputeNodeMixin(object): ...@@ -288,7 +289,7 @@ class SlapOSComputeNodeMixin(object):
partition_dict['_access_status'] = software_instance.getTextAccessStatus() partition_dict['_access_status'] = software_instance.getTextAccessStatus()
partition_dict['_software_release_document'] = { partition_dict['_software_release_document'] = {
"software_release": software_instance.getUrlString().decode("UTF-8"), "software_release": unicode2str(software_instance.getUrlString()),
"computer_guid": compute_node_id "computer_guid": compute_node_id
} }
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
from erp5.component.module.SlapOSCloud import _assertACI from erp5.component.module.SlapOSCloud import _assertACI
from zLOG import LOG, INFO from zLOG import LOG, INFO
from OFS.Traversable import NotFound from OFS.Traversable import NotFound
from Products.ERP5Type.Utils import unicode2str
try: try:
from slapos.util import calculate_dict_hash from slapos.util import calculate_dict_hash
...@@ -76,11 +77,11 @@ class SlapOSComputePartitionMixin(object): ...@@ -76,11 +77,11 @@ class SlapOSComputePartitionMixin(object):
compute_node = self compute_node = self
while compute_node.getPortalType() != 'Compute Node': while compute_node.getPortalType() != 'Compute Node':
compute_node = compute_node.getParentValue() compute_node = compute_node.getParentValue()
compute_node_id = compute_node.getReference().decode("UTF-8") compute_node_id = unicode2str(compute_node.getReference())
partition_dict = { partition_dict = {
"compute_node_id": compute_node_id, "compute_node_id": compute_node_id,
"partition_id": self.getReference().decode("UTF-8"), "partition_id": unicode2str(self.getReference()),
"_software_release_document": None, "_software_release_document": None,
"_requested_state": 'destroyed', "_requested_state": 'destroyed',
"_need_modification": 0 "_need_modification": 0
...@@ -110,7 +111,7 @@ class SlapOSComputePartitionMixin(object): ...@@ -110,7 +111,7 @@ class SlapOSComputePartitionMixin(object):
partition_dict['_requested_state'] = 'started' partition_dict['_requested_state'] = 'started'
partition_dict['_software_release_document'] = { partition_dict['_software_release_document'] = {
"software_release": software_instance.getUrlString().decode("UTF-8"), "software_release": unicode2str(software_instance.getUrlString()),
"computer_guid": compute_node_id "computer_guid": compute_node_id
} }
partition_dict['_access_status'] = software_instance.getTextAccessStatus() partition_dict['_access_status'] = software_instance.getTextAccessStatus()
......
...@@ -16,6 +16,7 @@ import hashlib ...@@ -16,6 +16,7 @@ import hashlib
import json import json
from binascii import hexlify from binascii import hexlify
from OFS.Traversable import NotFound from OFS.Traversable import NotFound
from Products.ERP5Type.Utils import unicode2str
def hashData(data): def hashData(data):
...@@ -42,11 +43,10 @@ class Simulator: ...@@ -42,11 +43,10 @@ class Simulator:
def canonical_xml(xml): def canonical_xml(xml):
return etree.tostring( return unicode2str(etree.tostring(
etree.fromstring(xml), etree.fromstring(xml),
method="c14n", method="c14n",
).decode('utf-8') ))
class TestSlapOSSlapToolMixin(SlapOSTestCaseMixin): class TestSlapOSSlapToolMixin(SlapOSTestCaseMixin):
def afterSetUp(self): def afterSetUp(self):
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
# #
############################################################################## ##############################################################################
from Products.ERP5Type.Utils import unicode2str
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from AccessControl import Unauthorized from AccessControl import Unauthorized
from OFS.Traversable import NotFound from OFS.Traversable import NotFound
...@@ -124,7 +124,7 @@ def castToStr(dict_kw): ...@@ -124,7 +124,7 @@ def castToStr(dict_kw):
if not isinstance(_value, str): if not isinstance(_value, str):
text = str(_value) text = str(_value)
etree.SubElement(instance, "parameter", etree.SubElement(instance, "parameter",
attrib={'id': _id}).text = text.decode("utf-8") attrib={'id': _id}).text = unicode2str(text)
return etree.tostring(instance, pretty_print=True, return etree.tostring(instance, pretty_print=True,
xml_declaration=True, encoding='utf-8') xml_declaration=True, encoding='utf-8')
...@@ -522,7 +522,7 @@ class SlapTool(BaseTool): ...@@ -522,7 +522,7 @@ class SlapTool(BaseTool):
portal = self.getPortalObject() portal = self.getPortalObject()
person = portal.portal_membership.getAuthenticatedMember().getUserValue() person = portal.portal_membership.getAuthenticatedMember().getUserValue()
person.requestComputeNode(compute_node_title=compute_node_title, project_reference=project_reference) person.requestComputeNode(compute_node_title=compute_node_title, project_reference=project_reference)
compute_node = ComputeNode(self.REQUEST.get('compute_node_reference').decode("UTF-8")) compute_node = ComputeNode(unicode2str(self.REQUEST.get('compute_node_reference')))
return dumps(compute_node) return dumps(compute_node)
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
...@@ -699,8 +699,8 @@ class SlapTool(BaseTool): ...@@ -699,8 +699,8 @@ class SlapTool(BaseTool):
def _generateComputerCertificate(self, compute_node_id): def _generateComputerCertificate(self, compute_node_id):
self.getPortalObject().portal_catalog.getComputeNodeObject(compute_node_id).generateCertificate() self.getPortalObject().portal_catalog.getComputeNodeObject(compute_node_id).generateCertificate()
result = { result = {
'certificate': self.REQUEST.get('compute_node_certificate').decode("UTF-8"), 'certificate': unicode2str(self.REQUEST.get('compute_node_certificate')),
'key': self.REQUEST.get('compute_node_key').decode("UTF-8") 'key': unicode2str(self.REQUEST.get('compute_node_key'))
} }
return dumps(result) return dumps(result)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment