mirror of https://github.com/explosion/spaCy.git
* Fix unicode error for Python3
This commit is contained in:
parent
dbda6c27fa
commit
1406e24327
|
@ -1,3 +1,5 @@
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from libc.string cimport memcpy
|
from libc.string cimport memcpy
|
||||||
|
|
||||||
# Note that we're setting the most significant bits here first, when in practice
|
# Note that we're setting the most significant bits here first, when in practice
|
||||||
|
@ -14,7 +16,7 @@ cdef Code bit_append(Code code, bint bit) nogil:
|
||||||
|
|
||||||
|
|
||||||
cdef class BitArray:
|
cdef class BitArray:
|
||||||
def __init__(self, data=b''):
|
def __init__(self, bytes data=b''):
|
||||||
self.data = data
|
self.data = data
|
||||||
self.byte = 0
|
self.byte = 0
|
||||||
self.bit_of_byte = 0
|
self.bit_of_byte = 0
|
||||||
|
@ -78,7 +80,14 @@ cdef class BitArray:
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def as_bytes(self):
|
def as_bytes(self):
|
||||||
|
cdef unsigned char byte
|
||||||
if self.bit_of_byte != 0:
|
if self.bit_of_byte != 0:
|
||||||
|
byte = chr(self.byte)
|
||||||
|
# Jump through some hoops for Python3
|
||||||
|
if isinstance(byte, unicode):
|
||||||
|
byte_char = <unsigned char>byte
|
||||||
|
return self.data + <bytes>&byte_char
|
||||||
|
else:
|
||||||
return self.data + chr(self.byte)
|
return self.data + chr(self.byte)
|
||||||
else:
|
else:
|
||||||
return self.data
|
return self.data
|
||||||
|
|
Loading…
Reference in New Issue