Commit 84de1f46 authored by Jérome Perrin's avatar Jérome Perrin

syncml: pylint for py3

parent a205509f
......@@ -541,7 +541,7 @@ class SyncMLSubscription(XMLObject):
xml_document = etree.tostring(xml_document, encoding='utf-8',
pretty_print=True)
if six.PY2 and isinstance(xml_document, unicode):
if six.PY2 and isinstance(xml_document, six.text_type):
xml_document = xml_document.encode('utf-8')
# Link the signature to the document
if signature:
......
......@@ -76,11 +76,10 @@ class SyncMLEngineMixin(object):
status['authentication_type']))
# XXX Not working To Review !
raise NotImplementedError("Adding credentials")
"""
syncml_response = domain.generateBaseResponse()
syncml_response.addCredentialMessage(domain)
return syncml_response
"""
# syncml_response = domain.generateBaseResponse()
# syncml_response.addCredentialMessage(domain)
# return syncml_response
elif status['status_code'] == \
resolveSyncmlStatusCode('invalid_credentials'):
syncml_logger.error("\tClient authentication refused")
......
......@@ -92,5 +92,4 @@ class BaseConduit(object):
Method called when update command is received
XXX It should returns the list of conflicts ?
"""
pass
......@@ -489,9 +489,8 @@ class ERP5Conduit(XMLSyncUtilsMixin):
first_object = False
elif sub_context is not None:
context = sub_context
else:
# else:
# Ignore non existing objects
pass
#LOG('ERP5Conduit', INFO, 'sub document of %s not found with id:%r'%\
#(context.getPath(), sub_context_id))
xpath = xpath.replace(object_block, '', 1)
......@@ -694,7 +693,6 @@ class ERP5Conduit(XMLSyncUtilsMixin):
def afterNewObject(self, object): # pylint: disable=redefined-builtin
"""Overloadable method
"""
pass
security.declareProtected(Permissions.AccessContentsInformation,
'getStatusFromXml')
......@@ -855,7 +853,7 @@ class ERP5Conduit(XMLSyncUtilsMixin):
if xupdated_node_list:
xupdated_node = xupdated_node_list[0]
else:
ValueError('Wrong xpath expression:%r' % base_xpath_expression)
raise ValueError('Wrong xpath expression:%r' % base_xpath_expression)
if base_xpath_expression not in xpath_expression_update_dict:
xpath_expression_update_dict[base_xpath_expression] = \
dict(xml=xupdated_node,
......@@ -875,7 +873,7 @@ class ERP5Conduit(XMLSyncUtilsMixin):
if xupdated_node_list:
xupdated_node = xupdated_node_list[0]
else:
ValueError('Wrong xpath expression:%r' % base_xpath_expression)
raise ValueError('Wrong xpath expression:%r' % base_xpath_expression)
if base_xpath_expression not in xpath_expression_update_dict:
xpath_expression_update_dict[base_xpath_expression] = \
dict(xml=xupdated_node,
......
......@@ -145,7 +145,7 @@ class SyncMLAsynchronousEngine(SyncMLEngineMixin):
"""
Process the package 4 of the SyncML DS exchange
"""
if False:
if False: # pylint:disable=using-constant-test
pass
# not subscriber.checkCorrectRemoteMessageId(
# syncml_request.header['message_id']):
......
......@@ -225,41 +225,41 @@ class SyncMLResponse(object):
receiving a challenge message
"""
raise NotImplementedError("To review")
"""
# create element 'SyncML' with a default namespace
xml = E.SyncML()
# syncml header
xml.append(self.buildHeader(
session_id=subscription.incrementSessionId(),
msg_id=subscription.incrementMessageId(),
target=subscription.getUrlString(),
source=subscription.getSubscriptionUrlString(),
user_id=subscription.getUserId(),
password=subscription.getPassword(),
authentication_format=subscription.getAuthenticationFormat(),
authentication_type=subscription.getAuthenticationType()))
# Build the message body
sync_body = E.SyncBody()
# alert message
sync_body.append(self.buildAlertMessage(
command_id=self._getNextCommandId(),
alert_code=subscription.getSyncmlAlertCode(),
target=subscription.getDestinationReference(),
source=subscription.getSourceReference(),
last_anchor=subscription.getLastAnchor(),
next_anchor=subscription.getNextAnchor()))
syncml_put = self.buildPutMessage(subscription)
if syncml_put is not None:
sync_body.append(syncml_put)
sync_body.append(E.Final())
xml.append(sync_body)
xml_string = etree.tostring(xml, encoding='utf-8', xml_declaration=True,
pretty_print=True)
self.data_append(xml_string)
"""
# # create element 'SyncML' with a default namespace
# xml = E.SyncML()
# # syncml header
# xml.append(self.buildHeader(
# session_id=subscription.incrementSessionId(),
# msg_id=subscription.incrementMessageId(),
# target=subscription.getUrlString(),
# source=subscription.getSubscriptionUrlString(),
# user_id=subscription.getUserId(),
# password=subscription.getPassword(),
# authentication_format=subscription.getAuthenticationFormat(),
# authentication_type=subscription.getAuthenticationType()))
#
# # Build the message body
# sync_body = E.SyncBody()
#
# # alert message
# sync_body.append(self.buildAlertMessage(
# command_id=self._getNextCommandId(),
# alert_code=subscription.getSyncmlAlertCode(),
# target=subscription.getDestinationReference(),
# source=subscription.getSourceReference(),
# last_anchor=subscription.getLastAnchor(),
# next_anchor=subscription.getNextAnchor()))
# syncml_put = self.buildPutMessage(subscription)
# if syncml_put is not None:
# sync_body.append(syncml_put)
# sync_body.append(E.Final())
#
# xml.append(sync_body)
# xml_string = etree.tostring(xml, encoding='utf-8', xml_declaration=True,
# pretty_print=True)
# self.data_append(xml_string)
def addPutMessage(self,subscription, markup='Put',
cmd_ref=None, message_id=None):
......@@ -280,61 +280,59 @@ class SyncMLResponse(object):
Both must be able to handle and process these informations
"""
return
"""
# XXX-Aurel : must be reviewed according to specification
# This part can be skipped for now
conduit = subscription.getConduit()
xml = None
# The conduit defined what capabilities the service offers
if getattr(conduit, 'getCapabilitiesCTTypeList', None) and \
getattr(conduit, 'getCapabilitiesVerCTList', None) and \
getattr(conduit, 'getPreferedCapabilitieVerCT', None):
xml = Element('{%s}%s' % (SYNCML_NAMESPACE, markup))
xml.append(E.CmdID(self._getNextCommandId()))
if message_id:
xml.append(E.MsgRef('%s' % message_id))
if cmd_ref:
xml.append(E.CmdRef('%s' % cmd_ref))
xml.extend((E.Meta(E.Type('application/vnd.syncml-devinf+xml')),
E.Item(E.Source(E.LocURI('./devinf12')),
E.Data(E.DevInf(E.VerDTD('1.2'),
E.Man('Nexedi'),
E.Mod('ERP5SyncML'),
E.OEM('Open Source'),
E.SwV('0.1'),
E.DevID(subscription.getSubscriptionUrlString()),
E.DevTyp('workstation'),
E.UTC(),
E.DataStore(E.SourceRef(subscription.getSourceReference()))
)
)
)))
data_store = xml.find('{%(ns)s}Item/{%(ns)s}Data/{%(ns)s}DevInf/{%(ns)s}DataStore' % {'ns': SYNCML_NAMESPACE})
tx_element_list = []
rx_element_list = []
for cttype in conduit.getCapabilitiesCTTypeList():
if cttype != 'text/xml':
for x_version in conduit.getCapabilitiesVerCTList(cttype):
rx_element_list.append(E.Rx(E.CTType(cttype), E.VerCT(x_version)))
tx_element_list.append(E.Tx(E.CTType(cttype), E.VerCT(x_version)))
rx_pref = Element('{%s}Rx-Pref' % SYNCML_NAMESPACE)
rx_pref.extend((E.CTType(conduit.getPreferedCapabilitieCTType()),
E.VerCT(conduit.getPreferedCapabilitieVerCT())))
data_store.append(rx_pref)
data_store.extend(rx_element_list)
tx_pref = Element('{%s}Tx-Pref' % SYNCML_NAMESPACE)
tx_pref.extend((E.CTType(conduit.getPreferedCapabilitieCTType()),
E.VerCT(conduit.getPreferedCapabilitieVerCT())))
data_store.append(tx_pref)
data_store.extend(tx_element_list)
data_store.append(E.SyncCap(
E.SyncType('2'),
E.SyncType('1'),
E.SyncType('4'),
E.SyncType('6')
))
self.data_append(xml)
"""
# # XXX-Aurel : must be reviewed according to specification
# # This part can be skipped for now
# conduit = subscription.getConduit()
# xml = None
# # The conduit defined what capabilities the service offers
# if getattr(conduit, 'getCapabilitiesCTTypeList', None) and \
# getattr(conduit, 'getCapabilitiesVerCTList', None) and \
# getattr(conduit, 'getPreferedCapabilitieVerCT', None):
# xml = Element('{%s}%s' % (SYNCML_NAMESPACE, markup))
# xml.append(E.CmdID(self._getNextCommandId()))
# if message_id:
# xml.append(E.MsgRef('%s' % message_id))
# if cmd_ref:
# xml.append(E.CmdRef('%s' % cmd_ref))
# xml.extend((E.Meta(E.Type('application/vnd.syncml-devinf+xml')),
# E.Item(E.Source(E.LocURI('./devinf12')),
# E.Data(E.DevInf(E.VerDTD('1.2'),
# E.Man('Nexedi'),
# E.Mod('ERP5SyncML'),
# E.OEM('Open Source'),
# E.SwV('0.1'),
# E.DevID(subscription.getSubscriptionUrlString()),
# E.DevTyp('workstation'),
# E.UTC(),
# E.DataStore(E.SourceRef(subscription.getSourceReference()))
# )
# )
# )))
# data_store = xml.find('{%(ns)s}Item/{%(ns)s}Data/{%(ns)s}DevInf/{%(ns)s}DataStore' % {'ns': SYNCML_NAMESPACE})
# tx_element_list = []
# rx_element_list = []
# for cttype in conduit.getCapabilitiesCTTypeList():
# if cttype != 'text/xml':
# for x_version in conduit.getCapabilitiesVerCTList(cttype):
# rx_element_list.append(E.Rx(E.CTType(cttype), E.VerCT(x_version)))
# tx_element_list.append(E.Tx(E.CTType(cttype), E.VerCT(x_version)))
# rx_pref = Element('{%s}Rx-Pref' % SYNCML_NAMESPACE)
# rx_pref.extend((E.CTType(conduit.getPreferedCapabilitieCTType()),
# E.VerCT(conduit.getPreferedCapabilitieVerCT())))
# data_store.append(rx_pref)
# data_store.extend(rx_element_list)
# tx_pref = Element('{%s}Tx-Pref' % SYNCML_NAMESPACE)
# tx_pref.extend((E.CTType(conduit.getPreferedCapabilitieCTType()),
# E.VerCT(conduit.getPreferedCapabilitieVerCT())))
# data_store.append(tx_pref)
# data_store.extend(tx_element_list)
# data_store.append(E.SyncCap(
# E.SyncType('2'),
# E.SyncType('1'),
# E.SyncType('4'),
# E.SyncType('6')
# ))
# self.data_append(xml)
def addSyncCommand(self, sync_command, gid, data, media_type, more_data):
......
......@@ -25,7 +25,7 @@
#
##############################################################################
from erp5.component.module.SyncMLTransportHTTP import ConnectionError
from erp5.component.module.SyncMLTransportHTTP import ConnectionError as _ConnectionError
class FileTransport:
......@@ -35,4 +35,4 @@ class FileTransport:
with open(filename, 'wb') as stream:
stream.write(data)
except IOError:
raise ConnectionError
raise _ConnectionError
......@@ -31,7 +31,7 @@ from requests import post
syncml_logger = getLogger('ERP5SyncML')
class ConnectionError(Exception):
class ConnectionError(Exception): # pylint:disable=redefined-builtin
pass
......
......@@ -25,7 +25,7 @@
#
##############################################################################
from erp5.component.module.SyncMLTransportHTTP import ConnectionError
from erp5.component.module.SyncMLTransportHTTP import ConnectionError as _ConnectionError
from Products.ERP5.ERP5Site import getSite
class MailTransport:
......@@ -36,4 +36,4 @@ class MailTransport:
try:
getSite().sendMail(from_address, to_address, sync_id, xml)
except:
raise ConnectionError
raise _ConnectionError
......@@ -141,7 +141,7 @@ class VCardConduit(ERP5Conduit):
property_value_list_well_incoded=[]
if encoding == 'QUOTED-PRINTABLE':
import mimify
import mimify # pylint:disable=import-error
for property_value in property_value_list:
property_value = mimify.mime_decode(property_value)
property_value_list_well_incoded.append(property_value)
......
......@@ -26,6 +26,7 @@
#
##############################################################################
import six
from erp5.component.module.XMLSyncUtils import XMLSyncUtilsMixin
from xml.dom.ext.reader.Sax2 import FromXml # pylint:disable=no-name-in-module,import-error
......@@ -40,7 +41,7 @@ class XupdateUtils(XMLSyncUtilsMixin):
Parse the xupdate and then it will call the conduit
"""
conflict_list = []
if isinstance(xupdate, (str, unicode)):
if isinstance(xupdate, six.string_types):
xupdate = FromXml(xupdate)
for subnode in xupdate:
......
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