Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python3 compatibility in FWCore/ParameterSet #26367

Merged
merged 2 commits into from Apr 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
55 changes: 40 additions & 15 deletions FWCore/ParameterSet/python/Types.py
Expand Up @@ -4,7 +4,7 @@
from .Mixins import saveOrigin
from .ExceptionHandling import format_typename, format_outerframe
from past.builtins import long

import codecs
import copy
import math
import six
Expand Down Expand Up @@ -167,7 +167,13 @@ def pythonValue(self, options=PrintOptions()):
@staticmethod
def formatValueForConfig(value):
l = len(value)
value = value.encode("string-escape")
import sys
if sys.version_info >= (3, 0): #python2 and python3 are different due to byptes vs strings
import codecs
t=codecs.escape_encode(value.encode('utf-8'))
value = t[0].decode('utf-8')
else: #be conservative and don't change the python2 version
value = value.encode("string-escape")
newL = len(value)
if l != newL:
#get rid of the hex encoding
Expand Down Expand Up @@ -481,13 +487,26 @@ def pythonValue(self, options=PrintOptions()):
@staticmethod
def _isValid(value):
return True
def __cmp__(self,other):
v = self.__moduleLabel != other.__moduleLabel
if not v:
v= self.__productInstance != other.__productInstance
if not v:
v=self.__processName != other.__processName
return v
def __eq__(self,other):
return ((self.__moduleLabel,self.__productInstance,self.__processName) ==
(other.__moduleLabel,other.__productInstance,other.__processName))
def __ne__(self,other):
return ((self.__moduleLabel,self.__productInstance,self.__processName) !=
(other.__moduleLabel,other.__productInstance,other.__processName))
def __lt__(self,other):
return ((self.__moduleLabel,self.__productInstance,self.__processName) <
(other.__moduleLabel,other.__productInstance,other.__processName))
def __gt__(self,other):
return ((self.__moduleLabel,self.__productInstance,self.__processName) >
(other.__moduleLabel,other.__productInstance,other.__processName))
def __le__(self,other):
return ((self.__moduleLabel,self.__productInstance,self.__processName) <=
(other.__moduleLabel,other.__productInstance,other.__processName))
def __ge__(self,other):
return ((self.__moduleLabel,self.__productInstance,self.__processName) >=
(other.__moduleLabel,other.__productInstance,other.__processName))


def value(self):
"Return the string rep"
return self.configValue()
Expand All @@ -505,7 +524,6 @@ def _setValues(self,moduleLabel,productInstanceLabel='',processName=''):
self.__moduleLabel = moduleLabel
self.__productInstance = productInstanceLabel
self.__processName=processName

if -1 != moduleLabel.find(":"):
toks = moduleLabel.split(":")
self.__moduleLabel = toks[0]
Expand Down Expand Up @@ -557,11 +575,18 @@ def pythonValue(self, options=PrintOptions()):
@staticmethod
def _isValid(value):
return True
def __cmp__(self,other):
v = self.__moduleLabel != other.__moduleLabel
if not v:
v= self.__data != other.__data
return v
def __eq__(self,other):
return ((self.__moduleLabel,self.__data) == (other.__moduleLabel,other.__data))
def __ne__(self,other):
return ((self.__moduleLabel,self.__data) != (other.__moduleLabel,other.__data))
def __lt__(self,other):
return ((self.__moduleLabel,self.__data) < (other.__moduleLabel,other.__data))
def __gt__(self,other):
return ((self.__moduleLabel,self.__data) > (other.__moduleLabel,other.__data))
def __le__(self,other):
return ((self.__moduleLabel,self.__data) <= (other.__moduleLabel,other.__data))
def __ge__(self,other):
return ((self.__moduleLabel,self.__data) >= (other.__moduleLabel,other.__data))
def value(self):
"Return the string rep"
return self.configValue()
Expand Down