Re: Details about the psycopg porting
On Mon, Jan 24, 2011 at 4:21 PM, Antoine Pitrou <solipsis@...> wrote:
> Daniele Varrazzo <daniele.varrazzo <at> ...> writes:
>> >> the data (bytes) from the libpq are passed to file.write() using
>> >> PyObject_CallFunction(func, "s#", buffer, len)”
>> > You shouldn't use "s#" as it will implicitly decode the buffer to unicode.
>> > Instead, use "y#" to write bytes.
>> Yes, the #s is a leftover from before the conversion: I just have to
>> decide whether it's better to always emit bytes and break on text
>> files or if to check for the file capability. Because text mode is the
>> default for open() I think the former would be surprising: I'll go for
>> the second option if not overly complex (seems trivial if
>> PyTextIOBase_Type is available in C without the need of importing
>> anything from Python, annoying otherwise).
> No, you'll have to import. The actual TextIOBase ABC is declared in Python.
> (see Lib/io.py if you are curious)
Annoying, then :) Will give it a try.
>> >> bytea fields are returned as MemoryView, from which is easy to get bytes
>> > Is this because it is easier for you to return a memoryview? Otherwise it
>> > make more sense to return a bytes object.
>> In Py2 bytea is converted to buffer objects, passing through a "chunk"
>> object implementing the buffer interface. so yes, MemoryView is a more
>> direct port.