mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Ensure that the default encoding used by python is never ASCII (needed when running a non frozen version of calibre on linux)
This commit is contained in:
parent
d1145138a9
commit
8dd120a574
@ -329,7 +329,7 @@ icu_lower(PyObject *self, PyObject *args) {
|
|||||||
PyMem_Free(input);
|
PyMem_Free(input);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
} // }}}
|
||||||
|
|
||||||
// title {{{
|
// title {{{
|
||||||
static PyObject *
|
static PyObject *
|
||||||
@ -374,9 +374,22 @@ icu_title(PyObject *self, PyObject *args) {
|
|||||||
PyMem_Free(input);
|
PyMem_Free(input);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
} // }}}
|
||||||
|
|
||||||
|
|
||||||
|
// set_default_encoding {{{
|
||||||
|
static PyObject *
|
||||||
|
icu_set_default_encoding(PyObject *self, PyObject *args) {
|
||||||
|
char *encoding;
|
||||||
|
if (!PyArg_ParseTuple(args, "s:setdefaultencoding", &encoding))
|
||||||
|
return NULL;
|
||||||
|
if (PyUnicode_SetDefaultEncoding(encoding))
|
||||||
|
return NULL;
|
||||||
|
Py_INCREF(Py_None);
|
||||||
|
return Py_None;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
|
|
||||||
static PyMethodDef icu_methods[] = {
|
static PyMethodDef icu_methods[] = {
|
||||||
{"upper", icu_upper, METH_VARARGS,
|
{"upper", icu_upper, METH_VARARGS,
|
||||||
@ -391,6 +404,10 @@ static PyMethodDef icu_methods[] = {
|
|||||||
"title(locale, unicode object) -> Title cased unicode object using locale rules."
|
"title(locale, unicode object) -> Title cased unicode object using locale rules."
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{"set_default_encoding", icu_set_default_encoding, METH_VARARGS,
|
||||||
|
"set_default_encoding(encoding) -> Set the default encoding for the python unicode implementation."
|
||||||
|
},
|
||||||
|
|
||||||
{NULL} /* Sentinel */
|
{NULL} /* Sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ __copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
|||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
# Setup code {{{
|
# Setup code {{{
|
||||||
|
import sys
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from calibre.constants import plugins
|
from calibre.constants import plugins
|
||||||
@ -85,6 +86,12 @@ load_icu()
|
|||||||
load_collator()
|
load_collator()
|
||||||
_icu_not_ok = _icu is None or _collator is None
|
_icu_not_ok = _icu is None or _collator is None
|
||||||
|
|
||||||
|
try:
|
||||||
|
if sys.getdefaultencoding().lower() == 'ascii':
|
||||||
|
_icu.set_default_encoding('utf-8')
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
################# The string functions ########################################
|
################# The string functions ########################################
|
||||||
|
Loading…
x
Reference in New Issue
Block a user