[Xapian-tickets] [Xapian] #346: Python 3 support
Xapian
nobody at xapian.org
Wed Sep 25 16:17:14 BST 2013
#346: Python 3 support
--------------------------------------+------------------------------
Reporter: olly | Owner: richard
Type: defect | Status: assigned
Priority: highest | Milestone: 1.3.2
Component: Xapian-bindings (Python) | Version: SVN trunk
Severity: normal | Resolution:
Keywords: | Blocked By:
Blocking: | Operating System: All
--------------------------------------+------------------------------
\
\
\
\
\
\
Comment (by barry):
Totally agree that inputs should accept either (utf-8) str or bytes.
Output could return a hybrid object that knows how to convert between
(utf-8) str and bytes. Very roughly something like the following:
{{{
def foo():
return b'abc'
def bar():
return foo() + b'def'
class BS:
def __init__(self, some_bytes):
self._value = some_bytes
@property
def str(self):
return self._value.decode('utf-8')
@property
def bytes(self):
return self._value
def __str__(self):
return self.str
def __bytes__(self):
return self.bytes
v = BS(bar())
print(repr(v.bytes))
print(repr(v.str))
print(repr(bytes(v)))
print(repr(str(v)))
}}}
Users wouldn't have to write their own wrappers, but they'd have to be
explicit about whether they wanted bytes or str in their own code.
{{{
% python3 /tmp/foo.py
b'abcdef'
'abcdef'
b'abcdef'
'abcdef'
}}}
\
\
\
--
Ticket URL: <http://trac.xapian.org/ticket/346#comment:60>
Xapian <http://xapian.org/>
Xapian
More information about the Xapian-tickets
mailing list