summaryrefslogtreecommitdiff
path: root/psycopg/connection_int.c
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2010-12-23 19:25:59 +0100
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2010-12-31 03:18:26 +0100
commit014b6a6d5b6ba1cbc35c49f7200644ba3dfb86be (patch)
treee4215f71e0425cf08eb181f848ecbc9809f30181 /psycopg/connection_int.c
parent89e4d4c7bb9534711c03df054f90fcad4787d209 (diff)
downloadpsycopg2-014b6a6d5b6ba1cbc35c49f7200644ba3dfb86be.tar.gz
Use psycopg_ensure_bytes() to unify Py2/3 code paths.
Diffstat (limited to 'psycopg/connection_int.c')
-rw-r--r--psycopg/connection_int.c16
1 files changed, 2 insertions, 14 deletions
diff --git a/psycopg/connection_int.c b/psycopg/connection_int.c
index 2188993..6d87622 100644
--- a/psycopg/connection_int.c
+++ b/psycopg/connection_int.c
@@ -235,20 +235,8 @@ conn_encoding_to_codec(const char *enc)
goto exit;
}
- /* Convert the codec in a bytes string to extract the c string.
- * At the end of the block we have pybenc with a new ref. */
- if (PyUnicode_Check(pyenc)) {
- if (!(pybenc = PyUnicode_AsEncodedString(pyenc, "ascii", NULL))) {
- goto exit;
- }
- }
- else if (Bytes_Check(pyenc)) {
- Py_INCREF(pyenc);
- pybenc = pyenc;
- }
- else {
- PyErr_Format(PyExc_TypeError, "bad type for encoding: %s",
- Py_TYPE(pyenc)->tp_name);
+ /* Convert the codec in a bytes string to extract the c string. */
+ if (!(pybenc = psycopg_ensure_bytes(pyenc))) {
goto exit;
}