Skip to content

Commit f439ca6

Browse files
committed
conn->codec rename to pyenc
1 parent 7caba16 commit f439ca6

File tree

14 files changed

+67
-67
lines changed

14 files changed

+67
-67
lines changed

doc/src/extensions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ details.
417417

418418
.. data:: encodings
419419

420-
Mapping from `PostgreSQL encoding`__ names to `Python codec`__ names.
420+
Mapping from `PostgreSQL encoding`__ to `Python encoding`__ names.
421421
Used by Psycopg when adapting or casting unicode strings. See
422422
:ref:`unicode-handling`.
423423

doc/src/usage.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ Unicode handling
355355
Psycopg can exchange Unicode data with a PostgreSQL database. Python
356356
`!unicode` objects are automatically *encoded* in the client encoding
357357
defined on the database connection (the `PostgreSQL encoding`__, available in
358-
`connection.encoding`, is translated into a `Python codec`__ using the
358+
`connection.encoding`, is translated into a `Python encoding`__ using the
359359
`~psycopg2.extensions.encodings` mapping)::
360360

361361
>>> print u, type(u)

psycopg/adapter_qstring.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ _qstring_get_encoding(qstringObject *self)
4343
conn->encoding but if the encoding is not specified we don't know what
4444
to do and we raise an exception */
4545
if (self->conn) {
46-
return self->conn->codec;
46+
return self->conn->pyenc;
4747
}
4848
else {
4949
return self->encoding ? self->encoding : default_encoding;

psycopg/connection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ struct connectionObject {
8383
char *dsn; /* data source name */
8484
char *critical; /* critical error on this connection */
8585
char *encoding; /* current backend encoding */
86-
char *codec; /* python codec name for encoding */
86+
char *pyenc; /* connection encoding python name */
8787

8888
long int closed; /* 1 means connection has been closed;
8989
2 that something horrible happened */

psycopg/connection_int.c

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ conn_text_from_chars(connectionObject *self, const char *str)
6161
#if PY_MAJOR_VERSION < 3
6262
return PyString_FromString(str);
6363
#else
64-
const char *codec = self ? self->codec : "ascii";
65-
return PyUnicode_Decode(str, strlen(str), codec, "replace");
64+
const char *pyenc = self ? self->pyenc : "ascii";
65+
return PyUnicode_Decode(str, strlen(str), pyenc, "replace");
6666
#endif
6767
}
6868

@@ -321,43 +321,43 @@ clear_encoding_name(const char *enc, char **clean)
321321
return rv;
322322
}
323323

324-
/* Convert a PostgreSQL encoding to a Python codec.
324+
/* Convert a PostgreSQL encoding name to a Python encoding name.
325325
*
326-
* Set 'codec' to a new copy of the codec name allocated on the Python heap.
326+
* Set 'pyenc' to a new copy of the encoding name allocated on the Python heap.
327327
* Return 0 in case of success, else -1 and set an exception.
328328
*
329-
* 'enc' should be already normalized (uppercase, no - or _).
329+
* 'pgenc' should be already normalized (uppercase, no - or _).
330330
*/
331331
RAISES_NEG static int
332-
conn_encoding_to_codec(const char *enc, char **codec)
332+
conn_pgenc_to_pyenc(const char *pgenc, char **pyenc)
333333
{
334334
char *tmp;
335335
Py_ssize_t size;
336-
PyObject *pyenc = NULL;
336+
PyObject *opyenc = NULL;
337337
int rv = -1;
338338

339-
/* Find the Py codec name from the PG encoding */
340-
if (!(pyenc = PyDict_GetItemString(psycoEncodings, enc))) {
339+
/* Find the Py encoding name from the PG encoding */
340+
if (!(opyenc = PyDict_GetItemString(psycoEncodings, pgenc))) {
341341
PyErr_Format(OperationalError,
342-
"no Python codec for client encoding '%s'", enc);
342+
"no Python encoding for PostgreSQL encoding '%s'", pgenc);
343343
goto exit;
344344
}
345345

346-
/* Convert the codec in a bytes string to extract the c string. */
347-
Py_INCREF(pyenc);
348-
if (!(pyenc = psycopg_ensure_bytes(pyenc))) {
346+
/* Convert the encoding in a bytes string to extract the c string. */
347+
Py_INCREF(opyenc);
348+
if (!(opyenc = psycopg_ensure_bytes(opyenc))) {
349349
goto exit;
350350
}
351351

352-
if (-1 == Bytes_AsStringAndSize(pyenc, &tmp, &size)) {
352+
if (-1 == Bytes_AsStringAndSize(opyenc, &tmp, &size)) {
353353
goto exit;
354354
}
355355

356-
/* have our own copy of the python codec name */
357-
rv = psycopg_strdup(codec, tmp, size);
356+
/* have our own copy of the python encoding name */
357+
rv = psycopg_strdup(pyenc, tmp, size);
358358

359359
exit:
360-
Py_XDECREF(pyenc);
360+
Py_XDECREF(opyenc);
361361
return rv;
362362
}
363363

@@ -367,15 +367,15 @@ conn_encoding_to_codec(const char *enc, char **codec)
367367
void
368368
conn_set_fast_codec(connectionObject *self)
369369
{
370-
Dprintf("conn_set_fast_codec: codec=%s", self->codec);
370+
Dprintf("conn_set_fast_codec: encoding=%s", self->pyenc);
371371

372-
if (0 == strcmp(self->codec, "utf_8")) {
372+
if (0 == strcmp(self->pyenc, "utf_8")) {
373373
Dprintf("conn_set_fast_codec: PyUnicode_DecodeUTF8");
374374
self->cdecoder = PyUnicode_DecodeUTF8;
375375
return;
376376
}
377377

378-
if (0 == strcmp(self->codec, "iso8859_1")) {
378+
if (0 == strcmp(self->pyenc, "iso8859_1")) {
379379
Dprintf("conn_set_fast_codec: PyUnicode_DecodeLatin1");
380380
self->cdecoder = PyUnicode_DecodeLatin1;
381381
return;
@@ -389,15 +389,15 @@ conn_set_fast_codec(connectionObject *self)
389389
/* Read the client encoding from the connection.
390390
*
391391
* Store the encoding in the pgconn->encoding field and the name of the
392-
* matching python codec in codec. The buffers are allocated on the Python
392+
* matching python encoding in pyenc. The buffers are allocated on the Python
393393
* heap.
394394
*
395395
* Return 0 on success, else nonzero.
396396
*/
397397
RAISES_NEG static int
398398
conn_read_encoding(connectionObject *self, PGconn *pgconn)
399399
{
400-
char *enc = NULL, *codec = NULL;
400+
char *pgenc = NULL, *pyenc = NULL;
401401
const char *tmp;
402402
int rv = -1;
403403

@@ -409,31 +409,31 @@ conn_read_encoding(connectionObject *self, PGconn *pgconn)
409409
goto exit;
410410
}
411411

412-
if (0 > clear_encoding_name(tmp, &enc)) {
412+
if (0 > clear_encoding_name(tmp, &pgenc)) {
413413
goto exit;
414414
}
415415

416416
/* Look for this encoding in Python codecs. */
417-
if (0 > conn_encoding_to_codec(enc, &codec)) {
417+
if (0 > conn_pgenc_to_pyenc(pgenc, &pyenc)) {
418418
goto exit;
419419
}
420420

421-
/* Good, success: store the encoding/codec in the connection. */
421+
/* Good, success: store the encoding/pyenc in the connection. */
422422
PyMem_Free(self->encoding);
423-
self->encoding = enc;
424-
enc = NULL;
423+
self->encoding = pgenc;
424+
pgenc = NULL;
425425

426-
PyMem_Free(self->codec);
427-
self->codec = codec;
428-
codec = NULL;
426+
PyMem_Free(self->pyenc);
427+
self->pyenc = pyenc;
428+
pyenc = NULL;
429429

430430
conn_set_fast_codec(self);
431431

432432
rv = 0;
433433

434434
exit:
435-
PyMem_Free(enc);
436-
PyMem_Free(codec);
435+
PyMem_Free(pgenc);
436+
PyMem_Free(pyenc);
437437
return rv;
438438
}
439439

@@ -1252,21 +1252,21 @@ conn_switch_isolation_level(connectionObject *self, int level)
12521252
/* conn_set_client_encoding - switch client encoding on connection */
12531253

12541254
RAISES_NEG int
1255-
conn_set_client_encoding(connectionObject *self, const char *enc)
1255+
conn_set_client_encoding(connectionObject *self, const char *pgenc)
12561256
{
12571257
PGresult *pgres = NULL;
12581258
char *error = NULL;
12591259
int res = -1;
1260-
char *codec = NULL;
1260+
char *pyenc = NULL;
12611261
char *clean_enc = NULL;
12621262

12631263
/* If the current encoding is equal to the requested one we don't
12641264
issue any query to the backend */
1265-
if (strcmp(self->encoding, enc) == 0) return 0;
1265+
if (strcmp(self->encoding, pgenc) == 0) return 0;
12661266

1267-
/* We must know what python codec this encoding is. */
1268-
if (0 > clear_encoding_name(enc, &clean_enc)) { goto exit; }
1269-
if (0 > conn_encoding_to_codec(clean_enc, &codec)) { goto exit; }
1267+
/* We must know what python encoding this encoding is. */
1268+
if (0 > clear_encoding_name(pgenc, &clean_enc)) { goto exit; }
1269+
if (0 > conn_pgenc_to_pyenc(clean_enc, &pyenc)) { goto exit; }
12701270

12711271
Py_BEGIN_ALLOW_THREADS;
12721272
pthread_mutex_lock(&self->lock);
@@ -1290,18 +1290,18 @@ conn_set_client_encoding(connectionObject *self, const char *enc)
12901290
clean_enc = NULL;
12911291
}
12921292

1293-
/* Store the python codec too. */
1293+
/* Store the python encoding name too. */
12941294
{
1295-
char *tmp = self->codec;
1296-
self->codec = codec;
1295+
char *tmp = self->pyenc;
1296+
self->pyenc = pyenc;
12971297
PyMem_Free(tmp);
1298-
codec = NULL;
1298+
pyenc = NULL;
12991299
}
13001300

13011301
conn_set_fast_codec(self);
13021302

1303-
Dprintf("conn_set_client_encoding: set encoding to %s (codec: %s)",
1304-
self->encoding, self->codec);
1303+
Dprintf("conn_set_client_encoding: set encoding to %s (Python: %s)",
1304+
self->encoding, self->pyenc);
13051305

13061306
endlock:
13071307
pthread_mutex_unlock(&self->lock);
@@ -1312,7 +1312,7 @@ conn_set_client_encoding(connectionObject *self, const char *enc)
13121312

13131313
exit:
13141314
PyMem_Free(clean_enc);
1315-
PyMem_Free(codec);
1315+
PyMem_Free(pyenc);
13161316

13171317
return res;
13181318
}

psycopg/connection_type.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1164,7 +1164,7 @@ connection_dealloc(PyObject* obj)
11641164

11651165
PyMem_Free(self->dsn);
11661166
PyMem_Free(self->encoding);
1167-
PyMem_Free(self->codec);
1167+
PyMem_Free(self->pyenc);
11681168
if (self->critical) free(self->critical);
11691169
if (self->cancel) PQfreeCancel(self->cancel);
11701170

psycopg/cursor_type.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ static PyObject *_psyco_curs_validate_sql_basic(
286286
Py_INCREF(sql);
287287
}
288288
else if (PyUnicode_Check(sql)) {
289-
char *enc = self->conn->codec;
289+
char *enc = self->conn->pyenc;
290290
sql = PyUnicode_AsEncodedString(sql, enc, NULL);
291291
/* if there was an error during the encoding from unicode to the
292292
target encoding, we just let the exception propagate */

psycopg/error.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ typedef struct {
3434
PyObject *pgerror;
3535
PyObject *pgcode;
3636
cursorObject *cursor;
37-
char *codec;
37+
char *pyenc;
3838
PGresult *pgres;
3939
} errorObject;
4040

psycopg/error_type.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ error_text_from_chars(errorObject *self, const char *str)
4343
return PyString_FromString(str);
4444
#else
4545
return PyUnicode_Decode(str, strlen(str),
46-
self->codec ? self->codec : "ascii", "replace");
46+
self->pyenc ? self->pyenc : "ascii", "replace");
4747
#endif
4848
}
4949

@@ -113,7 +113,7 @@ error_dealloc(errorObject *self)
113113
{
114114
PyObject_GC_UnTrack((PyObject *)self);
115115
error_clear(self);
116-
PyMem_Free(self->codec);
116+
PyMem_Free(self->pyenc);
117117
CLEARPGRES(self->pgres);
118118

119119
Py_TYPE(self)->tp_free((PyObject *)self);

psycopg/lobject_type.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ psyco_lobj_write(lobjectObject *self, PyObject *args)
8686
data = obj;
8787
}
8888
else if (PyUnicode_Check(obj)) {
89-
if (!(data = PyUnicode_AsEncodedString(obj, self->conn->codec, NULL))) {
89+
if (!(data = PyUnicode_AsEncodedString(obj, self->conn->pyenc, NULL))) {
9090
goto exit;
9191
}
9292
}
@@ -150,7 +150,7 @@ psyco_lobj_read(lobjectObject *self, PyObject *args)
150150
if (self->mode & LOBJECT_BINARY) {
151151
res = Bytes_FromStringAndSize(buffer, size);
152152
} else {
153-
res = PyUnicode_Decode(buffer, size, self->conn->codec, NULL);
153+
res = PyUnicode_Decode(buffer, size, self->conn->pyenc, NULL);
154154
}
155155
PyMem_Free(buffer);
156156

0 commit comments

Comments
 (0)