[Ironpython-users] issue with chardtect.detect with unicode type

Andrew Graham andy at agraham.demon.co.uk
Thu Jun 4 14:29:30 CEST 2015


Yes, the unicode type in IronPython is is the same as string by design,

‘unicode == str’  will return True


From: Daniel Fernandez 
Sent: Thursday, June 04, 2015 12:17 PM
To: ironpython-users at python.org 
Subject: [Ironpython-users] issue with chardtect.detect with unicode type

Hi All,
 
I'm playing with request but running into an issue with chardet.detect call. 
 
def detect(aBuf):
    if ((version_info < (3, 0) and isinstance(aBuf, unicode)) or
            (version_info >= (3, 0) and not isinstance(aBuf, bytes))):
        raise ValueError('Expected a bytes object, not a unicode object')
    from . import universaldetector
    u = universaldetector.UniversalDetector()
    u.reset()
    u.feed(aBuf)
    u.close()
    return u.result
 
It always throws ValueError exception 'Expected a bytes object, not a unicode object'.  The problem is the isinstance(aBuff,unicode) which returns True for IronPython and not CPython.  I guess in IronPython strings are both a str and unicode types
 
>>> v = 'value'
>>> isinstance(v,unicode)
True
>>> isinstance(v,str)
True
 
 
I was wondering if this is expected behavior for IronPython? At the moment I just removed this check in my local copy so I get pass this issue with requests. 

Thanks.
  


--------------------------------------------------------------------------------
_______________________________________________
Ironpython-users mailing list
Ironpython-users at python.org
https://mail.python.org/mailman/listinfo/ironpython-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20150604/c4feaaa0/attachment.html>


More information about the Ironpython-users mailing list