| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e506437 commit f5cff56
16 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -174,6 +174,8 @@ PyAPI_FUNC(PyObject *) PyCodec_XMLCharRefReplaceErrors(PyObject *exc); | |||
| 174 | 174 | /* replace the unicode encode error with backslash escapes (\x, \u and \U) */ | |
| 175 | 175 | PyAPI_FUNC(PyObject *) PyCodec_BackslashReplaceErrors(PyObject *exc); | |
| 176 | 176 | ||
| 177 | + extern const char *Py_hexdigits; | ||
| 178 | + | ||
| 177 | 179 | #ifdef __cplusplus | |
| 178 | 180 | } | |
| 179 | 181 | #endif | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -162,7 +162,6 @@ static PyObject * | |||
| 162 | 162 | escape_encode(PyObject *self, | |
| 163 | 163 | PyObject *args) | |
| 164 | 164 | { | |
| 165 | - static const char *hexdigits = "0123456789abcdef"; | ||
| 166 | 165 | PyObject *str; | |
| 167 | 166 | Py_ssize_t size; | |
| 168 | 167 | Py_ssize_t newsize; | |
@@ -205,8 +204,8 @@ escape_encode(PyObject *self, | |||
| 205 | 204 | else if (c < ' ' || c >= 0x7f) { | |
| 206 | 205 | *p++ = '\\'; | |
| 207 | 206 | *p++ = 'x'; | |
| 208 | - *p++ = hexdigits[(c & 0xf0) >> 4]; | ||
| 209 | - *p++ = hexdigits[c & 0xf]; | ||
| 207 | + *p++ = Py_hexdigits[(c & 0xf0) >> 4]; | ||
| 208 | + *p++ = Py_hexdigits[c & 0xf]; | ||
| 210 | 209 | } | |
| 211 | 210 | else | |
| 212 | 211 | *p++ = c; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -201,13 +201,11 @@ EVP_hexdigest(EVPobject *self, PyObject *unused) | |||
| 201 | 201 | ||
| 202 | 202 | /* Make hex version of the digest */ | |
| 203 | 203 | for(i=j=0; i<digest_size; i++) { | |
| 204 | - char c; | ||
| 204 | + unsigned char c; | ||
| 205 | 205 | c = (digest[i] >> 4) & 0xf; | |
| 206 | - c = (c>9) ? c+'a'-10 : c + '0'; | ||
| 207 | - hex_digest[j++] = c; | ||
| 206 | + hex_digest[j++] = Py_hexdigits[c]; | ||
| 208 | 207 | c = (digest[i] & 0xf); | |
| 209 | - c = (c>9) ? c+'a'-10 : c + '0'; | ||
| 210 | - hex_digest[j++] = c; | ||
| 208 | + hex_digest[j++] = Py_hexdigits[c]; | ||
| 211 | 209 | } | |
| 212 | 210 | retval = PyUnicode_FromStringAndSize(hex_digest, digest_size * 2); | |
| 213 | 211 | PyMem_Free(hex_digest); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -175,18 +175,18 @@ ascii_escape_unichar(Py_UCS4 c, unsigned char *output, Py_ssize_t chars) | |||
| 175 | 175 | Py_UCS4 v = c - 0x10000; | |
| 176 | 176 | c = 0xd800 | ((v >> 10) & 0x3ff); | |
| 177 | 177 | output[chars++] = 'u'; | |
| 178 | - output[chars++] = "0123456789abcdef"[(c >> 12) & 0xf]; | ||
| 179 | - output[chars++] = "0123456789abcdef"[(c >> 8) & 0xf]; | ||
| 180 | - output[chars++] = "0123456789abcdef"[(c >> 4) & 0xf]; | ||
| 181 | - output[chars++] = "0123456789abcdef"[(c ) & 0xf]; | ||
| 178 | + output[chars++] = Py_hexdigits[(c >> 12) & 0xf]; | ||
| 179 | + output[chars++] = Py_hexdigits[(c >> 8) & 0xf]; | ||
| 180 | + output[chars++] = Py_hexdigits[(c >> 4) & 0xf]; | ||
| 181 | + output[chars++] = Py_hexdigits[(c ) & 0xf]; | ||
| 182 | 182 | c = 0xdc00 | (v & 0x3ff); | |
| 183 | 183 | output[chars++] = '\\'; | |
| 184 | 184 | } | |
| 185 | 185 | output[chars++] = 'u'; | |
| 186 | - output[chars++] = "0123456789abcdef"[(c >> 12) & 0xf]; | ||
| 187 | - output[chars++] = "0123456789abcdef"[(c >> 8) & 0xf]; | ||
| 188 | - output[chars++] = "0123456789abcdef"[(c >> 4) & 0xf]; | ||
| 189 | - output[chars++] = "0123456789abcdef"[(c ) & 0xf]; | ||
| 186 | + output[chars++] = Py_hexdigits[(c >> 12) & 0xf]; | ||
| 187 | + output[chars++] = Py_hexdigits[(c >> 8) & 0xf]; | ||
| 188 | + output[chars++] = Py_hexdigits[(c >> 4) & 0xf]; | ||
| 189 | + output[chars++] = Py_hexdigits[(c ) & 0xf]; | ||
| 190 | 190 | } | |
| 191 | 191 | return chars; | |
| 192 | 192 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1776,7 +1776,6 @@ save_bytes(PicklerObject *self, PyObject *obj) | |||
| 1776 | 1776 | static PyObject * | |
| 1777 | 1777 | raw_unicode_escape(PyObject *obj) | |
| 1778 | 1778 | { | |
| 1779 | - static const char *hexdigits = "0123456789abcdef"; | ||
| 1780 | 1779 | PyObject *repr, *result; | |
| 1781 | 1780 | char *p; | |
| 1782 | 1781 | Py_ssize_t i, size, expandsize; | |
@@ -1809,23 +1808,23 @@ raw_unicode_escape(PyObject *obj) | |||
| 1809 | 1808 | if (ch >= 0x10000) { | |
| 1810 | 1809 | *p++ = '\\'; | |
| 1811 | 1810 | *p++ = 'U'; | |
| 1812 | - *p++ = hexdigits[(ch >> 28) & 0xf]; | ||
| 1813 | - *p++ = hexdigits[(ch >> 24) & 0xf]; | ||
| 1814 | - *p++ = hexdigits[(ch >> 20) & 0xf]; | ||
| 1815 | - *p++ = hexdigits[(ch >> 16) & 0xf]; | ||
| 1816 | - *p++ = hexdigits[(ch >> 12) & 0xf]; | ||
| 1817 | - *p++ = hexdigits[(ch >> 8) & 0xf]; | ||
| 1818 | - *p++ = hexdigits[(ch >> 4) & 0xf]; | ||
| 1819 | - *p++ = hexdigits[ch & 15]; | ||
| 1811 | + *p++ = Py_hexdigits[(ch >> 28) & 0xf]; | ||
| 1812 | + *p++ = Py_hexdigits[(ch >> 24) & 0xf]; | ||
| 1813 | + *p++ = Py_hexdigits[(ch >> 20) & 0xf]; | ||
| 1814 | + *p++ = Py_hexdigits[(ch >> 16) & 0xf]; | ||
| 1815 | + *p++ = Py_hexdigits[(ch >> 12) & 0xf]; | ||
| 1816 | + *p++ = Py_hexdigits[(ch >> 8) & 0xf]; | ||
| 1817 | + *p++ = Py_hexdigits[(ch >> 4) & 0xf]; | ||
| 1818 | + *p++ = Py_hexdigits[ch & 15]; | ||
| 1820 | 1819 | } | |
| 1821 | 1820 | /* Map 16-bit characters to '\uxxxx' */ | |
| 1822 | 1821 | else if (ch >= 256 || ch == '\\' || ch == '\n') { | |
| 1823 | 1822 | *p++ = '\\'; | |
| 1824 | 1823 | *p++ = 'u'; | |
| 1825 | - *p++ = hexdigits[(ch >> 12) & 0xf]; | ||
| 1826 | - *p++ = hexdigits[(ch >> 8) & 0xf]; | ||
| 1827 | - *p++ = hexdigits[(ch >> 4) & 0xf]; | ||
| 1828 | - *p++ = hexdigits[ch & 15]; | ||
| 1824 | + *p++ = Py_hexdigits[(ch >> 12) & 0xf]; | ||
| 1825 | + *p++ = Py_hexdigits[(ch >> 8) & 0xf]; | ||
| 1826 | + *p++ = Py_hexdigits[(ch >> 4) & 0xf]; | ||
| 1827 | + *p++ = Py_hexdigits[ch & 15]; | ||
| 1829 | 1828 | } | |
| 1830 | 1829 | /* Copy everything else as-is */ | |
| 1831 | 1830 | else | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1078,13 +1078,11 @@ binascii_hexlify(PyObject *self, PyObject *args) | |||
| 1078 | 1078 | ||
| 1079 | 1079 | /* make hex version of string, taken from shamodule.c */ | |
| 1080 | 1080 | for (i=j=0; i < arglen; i++) { | |
| 1081 | - char c; | ||
| 1081 | + unsigned char c; | ||
| 1082 | 1082 | c = (argbuf[i] >> 4) & 0xf; | |
| 1083 | - c = (c>9) ? c+'a'-10 : c + '0'; | ||
| 1084 | - retbuf[j++] = c; | ||
| 1083 | + retbuf[j++] = Py_hexdigits[c]; | ||
| 1085 | 1084 | c = argbuf[i] & 0xf; | |
| 1086 | - c = (c>9) ? c+'a'-10 : c + '0'; | ||
| 1087 | - retbuf[j++] = c; | ||
| 1085 | + retbuf[j++] = Py_hexdigits[c]; | ||
| 1088 | 1086 | } | |
| 1089 | 1087 | PyBuffer_Release(&parg); | |
| 1090 | 1088 | return retval; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -391,13 +391,11 @@ MD5_hexdigest(MD5object *self, PyObject *unused) | |||
| 391 | 391 | ||
| 392 | 392 | /* Make hex version of the digest */ | |
| 393 | 393 | for(i=j=0; i<MD5_DIGESTSIZE; i++) { | |
| 394 | - char c; | ||
| 394 | + unsigned char c; | ||
| 395 | 395 | c = (digest[i] >> 4) & 0xf; | |
| 396 | - c = (c>9) ? c+'a'-10 : c + '0'; | ||
| 397 | - hex_digest[j++] = c; | ||
| 396 | + hex_digest[j++] = Py_hexdigits[c]; | ||
| 398 | 397 | c = (digest[i] & 0xf); | |
| 399 | - c = (c>9) ? c+'a'-10 : c + '0'; | ||
| 400 | - hex_digest[j++] = c; | ||
| 398 | + hex_digest[j++] = Py_hexdigits[c]; | ||
| 401 | 399 | } | |
| 402 | 400 | return retval; | |
| 403 | 401 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -367,13 +367,11 @@ SHA1_hexdigest(SHA1object *self, PyObject *unused) | |||
| 367 | 367 | ||
| 368 | 368 | /* Make hex version of the digest */ | |
| 369 | 369 | for(i=j=0; i<SHA1_DIGESTSIZE; i++) { | |
| 370 | - char c; | ||
| 370 | + unsigned char c; | ||
| 371 | 371 | c = (digest[i] >> 4) & 0xf; | |
| 372 | - c = (c>9) ? c+'a'-10 : c + '0'; | ||
| 373 | - hex_digest[j++] = c; | ||
| 372 | + hex_digest[j++] = Py_hexdigits[c]; | ||
| 374 | 373 | c = (digest[i] & 0xf); | |
| 375 | - c = (c>9) ? c+'a'-10 : c + '0'; | ||
| 376 | - hex_digest[j++] = c; | ||
| 374 | + hex_digest[j++] = Py_hexdigits[c]; | ||
| 377 | 375 | } | |
| 378 | 376 | return retval; | |
| 379 | 377 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -460,13 +460,11 @@ SHA256_hexdigest(SHAobject *self, PyObject *unused) | |||
| 460 | 460 | ||
| 461 | 461 | /* Make hex version of the digest */ | |
| 462 | 462 | for(i=j=0; i<self->digestsize; i++) { | |
| 463 | - char c; | ||
| 463 | + unsigned char c; | ||
| 464 | 464 | c = (digest[i] >> 4) & 0xf; | |
| 465 | - c = (c>9) ? c+'a'-10 : c + '0'; | ||
| 466 | - hex_digest[j++] = c; | ||
| 465 | + hex_digest[j++] = Py_hexdigits[c]; | ||
| 467 | 466 | c = (digest[i] & 0xf); | |
| 468 | - c = (c>9) ? c+'a'-10 : c + '0'; | ||
| 469 | - hex_digest[j++] = c; | ||
| 467 | + hex_digest[j++] = Py_hexdigits[c]; | ||
| 470 | 468 | } | |
| 471 | 469 | return retval; | |
| 472 | 470 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -526,13 +526,11 @@ SHA512_hexdigest(SHAobject *self, PyObject *unused) | |||
| 526 | 526 | ||
| 527 | 527 | /* Make hex version of the digest */ | |
| 528 | 528 | for (i=j=0; i<self->digestsize; i++) { | |
| 529 | - char c; | ||
| 529 | + unsigned char c; | ||
| 530 | 530 | c = (digest[i] >> 4) & 0xf; | |
| 531 | - c = (c>9) ? c+'a'-10 : c + '0'; | ||
| 532 | - hex_digest[j++] = c; | ||
| 531 | + hex_digest[j++] = Py_hexdigits[c]; | ||
| 533 | 532 | c = (digest[i] & 0xf); | |
| 534 | - c = (c>9) ? c+'a'-10 : c + '0'; | ||
| 535 | - hex_digest[j++] = c; | ||
| 533 | + hex_digest[j++] = Py_hexdigits[c]; | ||
| 536 | 534 | } | |
| 537 | 535 | return retval; | |
| 538 | 536 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments