Skip to content
This repository was archived by the owner on Dec 10, 2018. It is now read-only.

Commit

Permalink
Merge pull request #211 from jparise/cymemory-utf8
Browse files Browse the repository at this point in the history
Drop to_bytes() in favor of inline UTF-8 encoding
  • Loading branch information
lxyu authored Jun 28, 2016
2 parents 073ec0b + 0cd962f commit 43bd436
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions thriftpy/transport/memory/cymemory.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ from thriftpy.transport.cybase cimport (
)


def to_bytes(s):
try:
return s.encode("utf-8")
except Exception:
return s


cdef class TCyMemoryBuffer(CyTransportBase):
cdef TCyBuffer buf

Expand Down Expand Up @@ -64,7 +57,8 @@ cdef class TCyMemoryBuffer(CyTransportBase):
return self.get_string(sz)

def write(self, data):
data = to_bytes(data)
if isinstance(data, unicode):
data = (<unicode>data).encode('utf-8')

cdef int sz = len(data)
return self.c_write(data, sz)
Expand All @@ -88,5 +82,6 @@ cdef class TCyMemoryBuffer(CyTransportBase):
return self._getvalue()

def setvalue(self, value):
value = to_bytes(value)
if isinstance(value, unicode):
value = (<unicode>value).encode('utf-8')
self._setvalue(len(value), value)

0 comments on commit 43bd436

Please sign in to comment.