Skip to content

Commit 73884a0

Browse files
Merge branch 'main' into fix-compression-block-decompress-error-handling
2 parents 31170c4 + 98b1e51 commit 73884a0

9 files changed

Lines changed: 38 additions & 16 deletions

File tree

Lib/locale.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -570,10 +570,6 @@ def _getdefaultlocale(envvars=('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE')):
570570
except (ImportError, AttributeError):
571571
pass
572572
else:
573-
# make sure the code/encoding values are valid
574-
if sys.platform == "win32" and code and code[:2] == "0x":
575-
# map windows language identifier to language name
576-
code = windows_locale.get(int(code, 0))
577573
# ...add other platform-specific processing here, if
578574
# necessary...
579575
return code, encoding

Lib/test/test_py_compile.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,14 @@ def test_quiet(self):
239239
with self.assertRaises(py_compile.PyCompileError):
240240
py_compile.compile(bad_coding, self.pyc_path, doraise=True, quiet=1)
241241

242+
def test_utf7_decoded_cr_compiles(self):
243+
with open(self.source_path, 'wb') as file:
244+
file.write(b"#coding=U7+AA0''\n")
245+
246+
pyc_path = py_compile.compile(self.source_path, self.pyc_path, doraise=True)
247+
self.assertEqual(pyc_path, self.pyc_path)
248+
self.assertTrue(os.path.exists(self.pyc_path))
249+
242250

243251
class PyCompileTestsWithSourceEpoch(PyCompileTestsBase,
244252
unittest.TestCase,

Lib/test/test_sqlite3/test_dbapi.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,6 +1379,11 @@ def test_blob_get_slice(self):
13791379
def test_blob_get_empty_slice(self):
13801380
self.assertEqual(self.blob[5:5], b"")
13811381

1382+
def test_blob_get_empty_slice_oob_indices(self):
1383+
self.cx.execute("insert into test(b) values (?)", (b"abc",))
1384+
with self.cx.blobopen("test", "b", 2) as blob:
1385+
self.assertEqual(blob[5:-5], b"")
1386+
13821387
def test_blob_get_slice_negative_index(self):
13831388
self.assertEqual(self.blob[5:-5], self.data[5:-5])
13841389

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Fixed a ``SystemError`` in the parser when an encoding cookie (for example,
2+
UTF-7) decodes to carriage returns (``\r``). Newlines are now normalized after
3+
decoding in the string tokenizer.
4+
5+
Patch by Pablo Galindo.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix assertion failure in :mod:`sqlite3` blob subscript when slicing with
2+
indices that result in an empty slice.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Removed Windows 95 compatibility for :func:`locale.getdefaultlocale`.

Modules/_localemodule.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -555,19 +555,7 @@ _locale__getdefaultlocale_impl(PyObject *module)
555555
return Py_BuildValue("ss", locale, encoding);
556556
}
557557

558-
/* If we end up here, this windows version didn't know about
559-
ISO639/ISO3166 names (it's probably Windows 95). Return the
560-
Windows language identifier instead (a hexadecimal number) */
561-
562-
locale[0] = '0';
563-
locale[1] = 'x';
564-
if (GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_IDEFAULTLANGUAGE,
565-
locale+2, sizeof(locale)-2)) {
566-
return Py_BuildValue("ss", locale, encoding);
567-
}
568-
569558
/* cannot determine the language code (very unlikely) */
570-
Py_INCREF(Py_None);
571559
return Py_BuildValue("Os", Py_None, encoding);
572560
}
573561
#endif

Modules/_sqlite/blob.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,10 @@ subscript_slice(pysqlite_Blob *self, PyObject *item)
439439
return NULL;
440440
}
441441

442+
if (len == 0) {
443+
return PyBytes_FromStringAndSize(NULL, 0);
444+
}
445+
442446
if (step == 1) {
443447
return read_multiple(self, len, start);
444448
}

Parser/tokenizer/string_tokenizer.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,19 @@ decode_str(const char *input, int single, struct tok_state *tok, int preserve_cr
108108
else if (!_PyTokenizer_ensure_utf8(str, tok, 1)) {
109109
return _PyTokenizer_error_ret(tok);
110110
}
111+
if (utf8 != NULL) {
112+
char *translated = _PyTokenizer_translate_newlines(
113+
str, single, preserve_crlf, tok);
114+
if (translated == NULL) {
115+
Py_DECREF(utf8);
116+
return _PyTokenizer_error_ret(tok);
117+
}
118+
PyMem_Free(tok->input);
119+
tok->input = translated;
120+
str = translated;
121+
Py_CLEAR(utf8);
122+
}
123+
tok->str = str;
111124
assert(tok->decoding_buffer == NULL);
112125
tok->decoding_buffer = utf8; /* CAUTION */
113126
return str;

0 commit comments

Comments
 (0)