@@ -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 */
331331RAISES_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
359359exit :
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)
367367void
368368conn_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 */
397397RAISES_NEG static int
398398conn_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
434434exit :
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
12541254RAISES_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
13061306endlock :
13071307 pthread_mutex_unlock (& self -> lock );
@@ -1312,7 +1312,7 @@ conn_set_client_encoding(connectionObject *self, const char *enc)
13121312
13131313exit :
13141314 PyMem_Free (clean_enc );
1315- PyMem_Free (codec );
1315+ PyMem_Free (pyenc );
13161316
13171317 return res ;
13181318}
0 commit comments