----- Original Message -----
> [...]
> > $ python
> > Python 2.7.5 (default, Nov 3 2014, 14:26:24)
> > [GCC 4.8.3 20140911 (Red Hat 4.8.3-7)] on linux2
> > Type "help", "copyright", "credits" or "license" for more information.
> >>>> from pcp import pmapi
> >>>> import cpmapi as c_api
> >>>> context = pmapi.pmContext()
> >>>> context.pmParseUnitsStr("count")
> > (<pcp.pmapi.pmUnits object at 0x7ff718e7c710>, 1.0)
> >>>> ^D
> >
> > $ python3
> > Python 3.3.2 (default, Dec 4 2014, 12:49:00)
> > [GCC 4.8.3 20140911 (Red Hat 4.8.3-7)] on linux
> > Type "help", "copyright", "credits" or "license" for more information.
> >>>> from pcp import pmapi
> >>>> import cpmapi as c_api
> >>>> context = pmapi.pmContext()
> >>>> context.pmParseUnitsStr("count")
> > (<pcp.pmapi.pmUnits object at 0x7f9e3952fb00>, 1.0)
> >>>> ^D
> >
> >
> > I guess one of those fails with an exception for you locally?
>
> Your example works fine:
>
> >>> from pcp import pmapi
> >>> context = pmapi.pmContext()
> >>> context.pmParseUnitsStr("count")
> (<pcp.pmapi.pmUnits object at 0x7f5a105a1710>, 1.0)
>
> But the following fails:
>
> >>> context.pmParseUnitsStr(u'count')
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "/usr/lib64/python2.7/site-packages/pcp/pmapi.py", line 1927, in
> pmParseUnitsStr
> raise pmErr(c_api.PM_ERR_CONV, str(string))
> pcp.pmapi.pmErr: PM_ERR_CONV Impossible value or scale conversion count
>
> You weren't passing in a unicode string.
In python3, strings are unicode. So, I guess you are using Unicode strings
on python2? (explicitly?)
$ python3
Python 3.3.2 (default, Dec 4 2014, 12:49:00)
[GCC 4.8.3 20140911 (Red Hat 4.8.3-7)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> type('x')
<class 'str'>
>>> type(u'x')
<class 'str'>
>>> type(b'x')
<class 'bytes'>
>>>
$ python
Python 2.7.5 (default, Nov 3 2014, 14:26:24)
[GCC 4.8.3 20140911 (Red Hat 4.8.3-7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> type('x')
<type 'str'>
>>> type(u'x')
<type 'unicode'>
>>> type(b'x')
<type 'str'>
>>>
Anyway, we should certainly tackle this below the API; we'll need to audit
all the byte/unicode conversion points and make sure they explicitly check
for unicode, e.g. this:
@staticmethod
def pmParseUnitsStr(string):
if type(string) != type('') and type(string) != type(b''):
raise pmErr(c_api.PM_ERR_CONV, str(string))
if type(string) != type(b''):
string = string.encode('utf-8')
should become
@staticmethod
def pmParseUnitsStr(string):
if type(string) != type(u'') and type(string) != type(b''):
raise pmErr(c_api.PM_ERR_CONV, str(string))
if type(string) != type(b''):
string = string.encode('utf-8')
and the exception you're seeing will be avoided I think. Thanks David!
cheers.
--
Nathan
|