#endif /* HAVE_LONG_LONG */
PyAPI_FUNC(PyObject *) PyLong_FromString(char *, char **, int);
-#ifdef Py_USING_UNICODE
PyAPI_FUNC(PyObject *) PyLong_FromUnicode(Py_UNICODE*, Py_ssize_t, int);
-#endif
/* _PyLong_Sign. Return 0 if v is 0, -1 if v < 0, +1 if v > 0.
v must not be NULL, and must be a normalized long.
PyAPI_FUNC(PyObject *) PyObject_Repr(PyObject *);
PyAPI_FUNC(PyObject *) _PyObject_Str(PyObject *);
PyAPI_FUNC(PyObject *) PyObject_Str(PyObject *);
-#ifdef Py_USING_UNICODE
PyAPI_FUNC(PyObject *) PyObject_Unicode(PyObject *);
-#endif
PyAPI_FUNC(int) PyObject_Compare(PyObject *, PyObject *);
PyAPI_FUNC(PyObject *) PyObject_RichCompare(PyObject *, PyObject *, int);
PyAPI_FUNC(int) PyObject_RichCompareBool(PyObject *, PyObject *, int);
PyObject *print_file_and_line;
} PySyntaxErrorObject;
-#ifdef Py_USING_UNICODE
typedef struct {
PyObject_HEAD
PyObject *dict;
PyObject *end;
PyObject *reason;
} PyUnicodeErrorObject;
-#endif
typedef struct {
PyObject_HEAD
PyAPI_FUNC(void) PyErr_SyntaxLocation(const char *, int);
PyAPI_FUNC(PyObject *) PyErr_ProgramText(const char *, int);
-#ifdef Py_USING_UNICODE
/* The following functions are used to create and modify unicode
exceptions from C */
PyObject *, const char *);
PyAPI_FUNC(int) PyUnicodeTranslateError_SetReason(
PyObject *, const char *);
-#endif
/* These APIs aren't really part of the error implementation, but
/* --- Internal Unicode Format -------------------------------------------- */
-#ifndef Py_USING_UNICODE
-
-#define PyUnicode_Check(op) 0
-#define PyUnicode_CheckExact(op) 0
-
-#else
-
/* FIXME: MvL's new implementation assumes that Py_UNICODE_SIZE is
properly set, but the default rules below doesn't set it. I'll
sort this out some other day -- fredrik@pythonware.com */
#ifdef __cplusplus
}
#endif
-#endif /* Py_USING_UNICODE */
#endif /* !Py_UNICODEOBJECT_H */
if (!PyArg_ParseTuple(args, "O|ss:encode", &v, &encoding, &errors))
return NULL;
-#ifdef Py_USING_UNICODE
if (encoding == NULL)
encoding = PyUnicode_GetDefaultEncoding();
-#else
- if (encoding == NULL) {
- PyErr_SetString(PyExc_ValueError, "no encoding specified");
- return NULL;
- }
-#endif
/* Encode via the codec registry */
return PyCodec_Encode(v, encoding, errors);
if (!PyArg_ParseTuple(args, "O|ss:decode", &v, &encoding, &errors))
return NULL;
-#ifdef Py_USING_UNICODE
if (encoding == NULL)
encoding = PyUnicode_GetDefaultEncoding();
-#else
- if (encoding == NULL) {
- PyErr_SetString(PyExc_ValueError, "no encoding specified");
- return NULL;
- }
-#endif
/* Decode via the codec registry */
return PyCodec_Decode(v, encoding, errors);
return codec_tuple(str, PyString_Size(str));
}
-#ifdef Py_USING_UNICODE
/* --- Decoder ------------------------------------------------------------ */
static PyObject *
}
#endif /* MS_WINDOWS */
-#endif /* Py_USING_UNICODE */
/* --- Error handler registry --------------------------------------------- */
decode__doc__},
{"escape_encode", escape_encode, METH_VARARGS},
{"escape_decode", escape_decode, METH_VARARGS},
-#ifdef Py_USING_UNICODE
{"utf_8_encode", utf_8_encode, METH_VARARGS},
{"utf_8_decode", utf_8_decode, METH_VARARGS},
{"utf_7_encode", utf_7_encode, METH_VARARGS},
{"mbcs_encode", mbcs_encode, METH_VARARGS},
{"mbcs_decode", mbcs_decode, METH_VARARGS},
#endif
-#endif /* Py_USING_UNICODE */
{"register_error", register_error, METH_VARARGS,
register_error__doc__},
{"lookup_error", lookup_error, METH_VARARGS,
#define LOCAL(type) static type
#endif
-/* compatibility macros */
-#if (PY_VERSION_HEX < 0x02050000)
-typedef int Py_ssize_t;
-#define lenfunc inquiry
-#endif
-
-#if (PY_VERSION_HEX < 0x02040000)
-#define PyDict_CheckExact PyDict_Check
-#if (PY_VERSION_HEX < 0x02020000)
-#define PyList_CheckExact PyList_Check
-#define PyString_CheckExact PyString_Check
-#if (PY_VERSION_HEX >= 0x01060000)
-#define Py_USING_UNICODE /* always enabled for 2.0 and 2.1 */
-#endif
-#endif
-#endif
-
-#if !defined(Py_RETURN_NONE)
-#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
-#endif
-
/* macros used to store 'join' flags in string object pointers. note
that all use of text and tail as object pointers must be wrapped in
JOIN_OBJ. see comments in the ElementObject definition for more
#define PATHCHAR(ch) (ch == '/' || ch == '*' || ch == '[' || ch == '@')
-#if defined(Py_USING_UNICODE)
if (PyUnicode_Check(tag)) {
Py_UNICODE *p = PyUnicode_AS_UNICODE(tag);
for (i = 0; i < PyUnicode_GET_SIZE(tag); i++) {
}
return 0;
}
-#endif
if (PyString_Check(tag)) {
char *p = PyString_AS_STRING(tag);
for (i = 0; i < PyString_GET_SIZE(tag); i++) {
/* helpers */
-#if defined(Py_USING_UNICODE)
LOCAL(int)
checkstring(const char* string, int size)
{
return 0;
}
-#endif
LOCAL(PyObject*)
makestring(const char* string, int size)
/* convert a UTF-8 string to either a 7-bit ascii string or a
Unicode string */
-#if defined(Py_USING_UNICODE)
if (checkstring(string, size))
return PyUnicode_DecodeUTF8(string, size, "strict");
-#endif
return PyString_FromStringAndSize(string, size);
}
}
/* decode universal name */
-#if defined(Py_USING_UNICODE)
/* inline makestring, to avoid duplicating the source string if
it's not an utf-8 string */
p = PyString_AS_STRING(tag);
return NULL;
}
} else
-#endif
value = tag; /* use tag as is */
/* add to names dictionary */
}
}
-#if defined(Py_USING_UNICODE)
static int
expat_unknown_encoding_handler(XMLParserObject *self, const XML_Char *name,
XML_Encoding *info)
return XML_STATUS_OK;
}
-#endif
/* -------------------------------------------------------------------- */
/* constructor and destructor */
self->parser,
(XML_ProcessingInstructionHandler) expat_pi_handler
);
-#if defined(Py_USING_UNICODE)
EXPAT(SetUnknownEncodingHandler)(
self->parser,
(XML_UnknownEncodingHandler) expat_unknown_encoding_handler, NULL
);
-#endif
ALLOC(sizeof(XMLParserObject), "create expatparser");
static PyObject*
PyLocale_strcoll(PyObject* self, PyObject* args)
{
-#if !defined(HAVE_WCSCOLL) || !defined(Py_USING_UNICODE)
+#if !defined(HAVE_WCSCOLL)
char *s1,*s2;
if (!PyArg_ParseTuple(args, "ss:strcoll", &s1, &s2))
/* defining this one enables tracing */
#undef VERBOSE
-#if PY_VERSION_HEX >= 0x01060000
-#if PY_VERSION_HEX < 0x02020000 || defined(Py_USING_UNICODE)
/* defining this enables unicode support (default under 1.6a1 and later) */
#define HAVE_UNICODE
-#endif
-#endif
/* -------------------------------------------------------------------- */
/* optional features */
return Py_None;
}
-#ifdef Py_USING_UNICODE
/* Test the u and u# codes for PyArg_ParseTuple. May leak memory in case
of an error.
return PyCodec_IncrementalDecoder(encoding, errors);
}
-#endif
/* Simple test of _PyLong_NumBits and _PyLong_Sign. */
static PyObject *
{"codec_incrementaldecoder",
(PyCFunction)codec_incrementaldecoder, METH_VARARGS},
#endif
-#ifdef Py_USING_UNICODE
{"test_u_code", (PyCFunction)test_u_code, METH_NOARGS},
-#endif
#ifdef WITH_THREAD
{"_test_thread_state", test_thread_state, METH_VARARGS},
#endif
{
if (PyString_Check(value))
return PyString_AsString(value);
-#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(value)) {
PyObject *v = PyUnicode_AsUTF8String(value);
if (v == NULL)
Py_DECREF(v);
return PyString_AsString(v);
}
-#endif
else {
PyObject *v = PyObject_Str(value);
if (v == NULL)
for (i = 0; i < len; i++)
if (s[i] & 0x80)
break;
-#ifdef Py_USING_UNICODE
if (i == len)
/* It is an ASCII string. */
self->string = PyString_FromStringAndSize(s, len);
self->string = PyString_FromStringAndSize(s, len);
}
}
-#else
- self->string = PyString_FromStringAndSize(s, len);
-#endif
if (!self->string)
return NULL;
}
return self->string;
}
-#ifdef Py_USING_UNICODE
PyDoc_STRVAR(PyTclObject_unicode__doc__, "convert argument to unicode");
static PyObject *
s = Tcl_GetStringFromObj(self->value, &len);
return PyUnicode_DecodeUTF8(s, len, "strict");
}
-#endif
static PyObject *
PyTclObject_repr(PyTclObject *self)
};
static PyMethodDef PyTclObject_methods[] = {
-#ifdef Py_USING_UNICODE
{"__unicode__", (PyCFunction)PyTclObject_unicode, METH_NOARGS,
PyTclObject_unicode__doc__},
-#endif
{0}
};
ckfree(FREECAST argv);
return result;
}
-#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(value)) {
Py_UNICODE *inbuf = PyUnicode_AS_UNICODE(value);
Py_ssize_t size = PyUnicode_GET_SIZE(value);
#endif
}
-#endif
else if(PyTclObject_Check(value)) {
Tcl_Obj *v = ((PyTclObject*)value)->value;
Tcl_IncrRefCount(v);
if (value->typePtr == NULL) {
/* If the result contains any bytes with the top bit set,
it's UTF-8 and we should decode it to Unicode */
-#ifdef Py_USING_UNICODE
int i;
char *s = value->bytes;
int len = value->length;
result = PyString_FromStringAndSize(s, len);
}
}
-#else
- result = PyString_FromStringAndSize(value->bytes, value->length);
-#endif
return result;
}
}
if (value->typePtr == app->StringType) {
-#ifdef Py_USING_UNICODE
#if defined(Py_UNICODE_WIDE) && TCL_UTF_MAX==3
PyObject *result;
int size;
#else
return PyUnicode_FromUnicode(Tcl_GetUnicode(value),
Tcl_GetCharLength(value));
-#endif
-#else
- int size;
- char *c;
- c = Tcl_GetStringFromObj(value, &size);
- return PyString_FromStringAndSize(c, size);
#endif
}
/* If the result contains any bytes with the top bit set,
it's UTF-8 and we should decode it to Unicode */
-#ifdef Py_USING_UNICODE
while (*p != '\0') {
if (*p & 0x80)
break;
res = PyString_FromStringAndSize(s, (int)(p-s));
}
}
-#else
- p = strchr(p, '\0');
- res = PyString_FromStringAndSize(s, (int)(p-s));
-#endif
}
return res;
}
return 0;
}
-#ifdef Py_USING_UNICODE
static PyObject *
u_getitem(arrayobject *ap, Py_ssize_t i)
{
((Py_UNICODE *)ap->ob_item)[i] = p[0];
return 0;
}
-#endif
static PyObject *
h_getitem(arrayobject *ap, Py_ssize_t i)
{'c', sizeof(char), c_getitem, c_setitem},
{'b', sizeof(char), b_getitem, b_setitem},
{'B', sizeof(char), BB_getitem, BB_setitem},
-#ifdef Py_USING_UNICODE
{'u', sizeof(Py_UNICODE), u_getitem, u_setitem},
-#endif
{'h', sizeof(short), h_getitem, h_setitem},
{'H', sizeof(short), HH_getitem, HH_setitem},
{'i', sizeof(int), i_getitem, i_setitem},
-#ifdef Py_USING_UNICODE
static PyObject *
array_fromunicode(arrayobject *self, PyObject *args)
{
array.tostring().decode() to obtain a unicode string from\n\
an array of some other type.");
-#endif /* Py_USING_UNICODE */
static PyObject *
fromlist_doc},
{"fromstring", (PyCFunction)array_fromstring, METH_VARARGS,
fromstring_doc},
-#ifdef Py_USING_UNICODE
{"fromunicode", (PyCFunction)array_fromunicode, METH_VARARGS,
fromunicode_doc},
-#endif
{"index", (PyCFunction)array_index, METH_O,
index_doc},
{"insert", (PyCFunction)array_insert, METH_VARARGS,
tolist_doc},
{"tostring", (PyCFunction)array_tostring, METH_NOARGS,
tostring_doc},
-#ifdef Py_USING_UNICODE
{"tounicode", (PyCFunction)array_tounicode, METH_NOARGS,
tounicode_doc},
-#endif
{"write", (PyCFunction)array_tofile, METH_O,
tofile_doc},
{NULL, NULL} /* sentinel */
if (typecode == 'c')
v = array_tostring(a, NULL);
-#ifdef Py_USING_UNICODE
else if (typecode == 'u')
v = array_tounicode(a, NULL);
-#endif
else
v = array_tolist(a, NULL);
t = PyObject_Repr(v);
return NULL;
}
Py_DECREF(v);
-#ifdef Py_USING_UNICODE
} else if (initial != NULL && PyUnicode_Check(initial)) {
Py_ssize_t n = PyUnicode_GET_DATA_SIZE(initial);
if (n > 0) {
memcpy(item, PyUnicode_AS_DATA(initial), n);
self->allocated = self->ob_size;
}
-#endif
}
if (it != NULL) {
if (array_iter_extend((arrayobject *)a, it) == -1) {
}
-#ifdef Py_USING_UNICODE
/* A copy of PyUnicode_EncodeRawUnicodeEscape() that also translates
backslash and newline characters to \uXXXX escapes. */
static PyObject *
Py_XDECREF(repr);
return -1;
}
-#endif
/* A helper for save_tuple. Push the len elements in tuple t on the stack. */
static int
goto finally;
}
-#ifdef Py_USING_UNICODE
case 'u':
if ((type == &PyUnicode_Type) && (PyString_GET_SIZE(args) < 2)) {
res = save_unicode(self, args, 0);
goto finally;
}
-#endif
}
if (args->ob_refcnt > 1) {
}
break;
-#ifdef Py_USING_UNICODE
case 'u':
if (type == &PyUnicode_Type) {
res = save_unicode(self, args, 1);
goto finally;
}
break;
-#endif
case 't':
if (type == &PyTuple_Type) {
}
-#ifdef Py_USING_UNICODE
static int
load_unicode(Unpicklerobject *self)
{
finally:
return res;
}
-#endif
-#ifdef Py_USING_UNICODE
static int
load_binunicode(Unpicklerobject *self)
{
PDATA_PUSH(self->stack, unicode, -1);
return 0;
}
-#endif
static int
break;
continue;
-#ifdef Py_USING_UNICODE
case UNICODE:
if (load_unicode(self) < 0)
break;
if (load_binunicode(self) < 0)
break;
continue;
-#endif
case EMPTY_TUPLE:
if (load_counted_tuple(self, 0) < 0)
break;
continue;
-#ifdef Py_USING_UNICODE
case UNICODE:
if (load_unicode(self) < 0)
break;
if (load_binunicode(self) < 0)
break;
continue;
-#endif
case EMPTY_TUPLE:
if (load_counted_tuple(self, 0) < 0)
disguised Unix interface). Refer to the library manual and\n\
corresponding Unix manual entries for more information on calls.");
-#ifndef Py_USING_UNICODE
-/* This is used in signatures of functions. */
-#define Py_UNICODE void
-#endif
#if defined(PYOS_OS2)
#define INCL_DOS
return PyString_FromString(buf);
}
-#ifdef Py_USING_UNICODE
PyDoc_STRVAR(posix_getcwdu__doc__,
"getcwdu() -> path\n\n\
Return a unicode string representing the current working directory.");
return PyUnicode_Decode(buf, strlen(buf), Py_FileSystemDefaultEncoding,"strict");
}
#endif
-#endif
#ifdef HAVE_LINK
d = NULL;
break;
}
-#ifdef Py_USING_UNICODE
if (arg_is_unicode) {
PyObject *w;
PyErr_Clear();
}
}
-#endif
if (PyList_Append(d, v) != 0) {
Py_DECREF(v);
Py_DECREF(d);
char buf[MAXPATHLEN];
char *path;
int n;
-#ifdef Py_USING_UNICODE
int arg_is_unicode = 0;
-#endif
if (!PyArg_ParseTuple(args, "et:readlink",
Py_FileSystemDefaultEncoding, &path))
return NULL;
-#ifdef Py_USING_UNICODE
v = PySequence_GetItem(args, 0);
if (v == NULL) return NULL;
arg_is_unicode = 1;
}
Py_DECREF(v);
-#endif
Py_BEGIN_ALLOW_THREADS
n = readlink(path, buf, (int) sizeof buf);
return posix_error_with_filename(path);
v = PyString_FromStringAndSize(buf, n);
-#ifdef Py_USING_UNICODE
if (arg_is_unicode) {
PyObject *w;
PyErr_Clear();
}
}
-#endif
return v;
}
#endif /* HAVE_READLINK */
#endif
#ifdef HAVE_GETCWD
{"getcwd", posix_getcwd, METH_NOARGS, posix_getcwd__doc__},
-#ifdef Py_USING_UNICODE
{"getcwdu", posix_getcwdu, METH_NOARGS, posix_getcwdu__doc__},
#endif
-#endif
#ifdef HAVE_LINK
{"link", posix_link, METH_VARARGS, posix_link__doc__},
#endif /* HAVE_LINK */
#define PyDoc_STRVAR(name,str) PyDoc_VAR(name) = PyDoc_STR(str)
#endif
-#if (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 2)
-/* In Python 2.0 and 2.1, disabling Unicode was not possible. */
-#define Py_USING_UNICODE
-#else
#define FIX_TRACE
-#endif
enum HandlerTypes {
StartElement,
}
-#ifdef Py_USING_UNICODE
/* Convert a string of XML_Chars into a Unicode string.
Returns None if str is a null pointer. */
}
return PyUnicode_DecodeUTF8((const char *)str, len, "strict");
}
-#endif
/* Convert a string of XML_Chars into an 8-bit Python string.
Returns None if str is a null pointer. */
return res;
}
-#ifndef Py_USING_UNICODE
-#define STRING_CONV_FUNC conv_string_to_utf8
-#else
/* Python 2.0 and later versions, when built with Unicode support */
#define STRING_CONV_FUNC (self->returns_unicode \
? conv_string_to_unicode : conv_string_to_utf8)
-#endif
static PyObject*
string_intern(xmlparseobject *self, const char* str)
args = PyTuple_New(1);
if (args == NULL)
return -1;
-#ifdef Py_USING_UNICODE
temp = (self->returns_unicode
? conv_string_len_to_unicode(buffer, len)
: conv_string_len_to_utf8(buffer, len));
-#else
- temp = conv_string_len_to_utf8(buffer, len);
-#endif
if (temp == NULL) {
Py_DECREF(args);
flag_error(self);
string_intern(self, systemId), string_intern(self, publicId),
string_intern(self, notationName)))
-#ifndef Py_USING_UNICODE
-VOID_HANDLER(EntityDecl,
- (void *userData,
- const XML_Char *entityName,
- int is_parameter_entity,
- const XML_Char *value,
- int value_length,
- const XML_Char *base,
- const XML_Char *systemId,
- const XML_Char *publicId,
- const XML_Char *notationName),
- ("NiNNNNN",
- string_intern(self, entityName), is_parameter_entity,
- conv_string_len_to_utf8(value, value_length),
- string_intern(self, base), string_intern(self, systemId),
- string_intern(self, publicId),
- string_intern(self, notationName)))
-#else
VOID_HANDLER(EntityDecl,
(void *userData,
const XML_Char *entityName,
string_intern(self, base), string_intern(self, systemId),
string_intern(self, publicId),
string_intern(self, notationName)))
-#endif
VOID_HANDLER(XmlDecl,
(void *userData,
if (flush_character_buffer(self) < 0)
goto finally;
-#ifdef Py_USING_UNICODE
modelobj = conv_content_model(model,
(self->returns_unicode
? conv_string_to_unicode
: conv_string_to_utf8));
-#else
- modelobj = conv_content_model(model, conv_string_to_utf8);
-#endif
if (modelobj == NULL) {
flag_error(self);
goto finally;
(void *userData),
("()"))
-#ifndef Py_USING_UNICODE
-VOID_HANDLER(Default,
- (void *userData, const XML_Char *s, int len),
- ("(N)", conv_string_len_to_utf8(s,len)))
-
-VOID_HANDLER(DefaultHandlerExpand,
- (void *userData, const XML_Char *s, int len),
- ("(N)", conv_string_len_to_utf8(s,len)))
-#else
VOID_HANDLER(Default,
(void *userData, const XML_Char *s, int len),
("(N)", (self->returns_unicode
("(N)", (self->returns_unicode
? conv_string_len_to_unicode(s,len)
: conv_string_len_to_utf8(s,len))))
-#endif
INT_HANDLER(NotStandalone,
(void *userData),
/* ---------- */
-#ifdef Py_USING_UNICODE
/* pyexpat international encoding support.
Make it as simple as possible.
return result;
}
-#endif
static PyObject *
newxmlparseobject(char *encoding, char *namespace_separator, PyObject *intern)
if (self == NULL)
return NULL;
-#ifdef Py_USING_UNICODE
self->returns_unicode = 1;
-#else
- self->returns_unicode = 0;
-#endif
self->buffer = NULL;
self->buffer_size = CHARACTER_DATA_BUFFER_SIZE;
return NULL;
}
XML_SetUserData(self->itself, (void *)self);
-#ifdef Py_USING_UNICODE
XML_SetUnknownEncodingHandler(self->itself,
(XML_UnknownEncodingHandler) PyUnknownEncodingHandler, NULL);
-#endif
for (i = 0; handler_info[i].name != NULL; i++)
/* do nothing */;
}
if (strcmp(name, "returns_unicode") == 0) {
if (PyObject_IsTrue(v)) {
-#ifndef Py_USING_UNICODE
- PyErr_SetString(PyExc_ValueError,
- "Unicode support not available");
- return -1;
-#else
self->returns_unicode = 1;
-#endif
}
else
self->returns_unicode = 0;
Py_BuildValue("(iii)", info.major,
info.minor, info.micro));
}
-#ifdef Py_USING_UNICODE
init_template_buffer();
-#endif
/* XXX When Expat supports some way of figuring out how it was
compiled, this should check and set native_encoding
appropriately.
*/
return long_from_string(PyString_AS_STRING(o),
PyString_GET_SIZE(o));
-#ifdef Py_USING_UNICODE
if (PyUnicode_Check(o))
/* The above check is done in PyLong_FromUnicode(). */
return PyLong_FromUnicode(PyUnicode_AS_UNICODE(o),
PyUnicode_GET_SIZE(o),
10);
-#endif
if (!PyObject_AsCharBuffer(o, &buffer, &buffer_len))
return long_from_string(buffer, buffer_len);
int sw_error=0;
int sign;
char buffer[256]; /* For errors */
-#ifdef Py_USING_UNICODE
char s_buffer[256];
-#endif
Py_ssize_t len;
if (PyString_Check(v)) {
s = PyString_AS_STRING(v);
len = PyString_GET_SIZE(v);
}
-#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(v)) {
if (PyUnicode_GET_SIZE(v) >= (Py_ssize_t)sizeof(s_buffer)) {
PyErr_SetString(PyExc_ValueError,
s = s_buffer;
len = strlen(s);
}
-#endif
else if (PyObject_AsCharBuffer(v, &s, &len)) {
PyErr_SetString(PyExc_TypeError,
"complex() arg is not a string");
SimpleExtendsException(PyExc_ValueError, UnicodeError,
"Unicode related error.");
-#ifdef Py_USING_UNICODE
static int
get_int(PyObject *attr, Py_ssize_t *value, const char *name)
{
return PyObject_CallFunction(PyExc_UnicodeTranslateError, "u#nns",
object, length, start, end, reason);
}
-#endif
/*
PRE_INIT(KeyError)
PRE_INIT(ValueError)
PRE_INIT(UnicodeError)
-#ifdef Py_USING_UNICODE
PRE_INIT(UnicodeEncodeError)
PRE_INIT(UnicodeDecodeError)
PRE_INIT(UnicodeTranslateError)
-#endif
PRE_INIT(AssertionError)
PRE_INIT(ArithmeticError)
PRE_INIT(FloatingPointError)
POST_INIT(KeyError)
POST_INIT(ValueError)
POST_INIT(UnicodeError)
-#ifdef Py_USING_UNICODE
POST_INIT(UnicodeEncodeError)
POST_INIT(UnicodeDecodeError)
POST_INIT(UnicodeTranslateError)
-#endif
POST_INIT(AssertionError)
POST_INIT(ArithmeticError)
POST_INIT(FloatingPointError)
file_repr(PyFileObject *f)
{
if (PyUnicode_Check(f->f_name)) {
-#ifdef Py_USING_UNICODE
PyObject *ret = NULL;
PyObject *name = PyUnicode_AsUnicodeEscapeString(f->f_name);
const char *name_str = name ? PyString_AsString(name) : "?";
f);
Py_XDECREF(name);
return ret;
-#endif
} else {
return PyString_FromFormat("<%s file '%s', mode '%s' at %p>",
f->f_fp == NULL ? "closed" : "open",
}
}
}
-#ifdef Py_USING_UNICODE
if (n < 0 && result != NULL && PyUnicode_Check(result)) {
Py_UNICODE *s = PyUnicode_AS_UNICODE(result);
Py_ssize_t len = PyUnicode_GET_SIZE(result);
}
}
}
-#endif
return result;
}
}
else if (PyFile_Check(f)) {
FILE *fp = PyFile_AsFile(f);
-#ifdef Py_USING_UNICODE
PyObject *enc = ((PyFileObject*)f)->f_encoding;
int result;
-#endif
if (fp == NULL) {
err_closed();
return -1;
}
-#ifdef Py_USING_UNICODE
if ((flags & Py_PRINT_RAW) &&
PyUnicode_Check(v) && enc != Py_None) {
char *cenc = PyString_AS_STRING(enc);
result = PyObject_Print(value, fp, flags);
Py_DECREF(value);
return result;
-#else
- return PyObject_Print(v, fp, flags);
-#endif
}
writer = PyObject_GetAttrString(f, "write");
if (writer == NULL)
const char *s, *last, *end;
double x;
char buffer[256]; /* for errors */
-#ifdef Py_USING_UNICODE
char s_buffer[256]; /* for objects convertible to a char buffer */
-#endif
Py_ssize_t len;
if (PyString_Check(v)) {
s = PyString_AS_STRING(v);
len = PyString_GET_SIZE(v);
}
-#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(v)) {
if (PyUnicode_GET_SIZE(v) >= (Py_ssize_t)sizeof(s_buffer)) {
PyErr_SetString(PyExc_ValueError,
s = s_buffer;
len = strlen(s);
}
-#endif
else if (PyObject_AsCharBuffer(v, &s, &len)) {
PyErr_SetString(PyExc_TypeError,
"float() argument must be a string or a number");
return PyInt_FromLong(x);
}
-#ifdef Py_USING_UNICODE
PyObject *
PyInt_FromUnicode(Py_UNICODE *s, Py_ssize_t length, int base)
{
PyMem_FREE(buffer);
return result;
}
-#endif
/* Methods */
}
return PyInt_FromString(string, NULL, base);
}
-#ifdef Py_USING_UNICODE
if (PyUnicode_Check(x))
return PyInt_FromUnicode(PyUnicode_AS_UNICODE(x),
PyUnicode_GET_SIZE(x),
base);
-#endif
PyErr_SetString(PyExc_TypeError,
"int() can't convert non-string with explicit base");
return NULL;
return NULL;
}
-#ifdef Py_USING_UNICODE
PyObject *
PyLong_FromUnicode(Py_UNICODE *u, Py_ssize_t length, int base)
{
PyMem_FREE(buffer);
return result;
}
-#endif
/* forward */
static PyLongObject *x_divrem
}
return PyLong_FromString(PyString_AS_STRING(x), NULL, base);
}
-#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(x))
return PyLong_FromUnicode(PyUnicode_AS_UNICODE(x),
PyUnicode_GET_SIZE(x),
base);
-#endif
else {
PyErr_SetString(PyExc_TypeError,
"int() can't convert non-string with explicit base");
res = (*v->ob_type->tp_repr)(v);
if (res == NULL)
return NULL;
-#ifdef Py_USING_UNICODE
if (PyUnicode_Check(res)) {
PyObject* str;
str = PyUnicode_AsEncodedString(res, NULL, NULL);
else
return NULL;
}
-#endif
if (!PyString_Check(res)) {
PyErr_Format(PyExc_TypeError,
"__repr__ returned non-string (type %.200s)",
Py_INCREF(v);
return v;
}
-#ifdef Py_USING_UNICODE
if (PyUnicode_CheckExact(v)) {
Py_INCREF(v);
return v;
}
-#endif
if (v->ob_type->tp_str == NULL)
return PyObject_Repr(v);
if (res == NULL)
return NULL;
type_ok = PyString_Check(res);
-#ifdef Py_USING_UNICODE
type_ok = type_ok || PyUnicode_Check(res);
-#endif
if (!type_ok) {
PyErr_Format(PyExc_TypeError,
"__str__ returned non-string (type %.200s)",
PyObject *res = _PyObject_Str(v);
if (res == NULL)
return NULL;
-#ifdef Py_USING_UNICODE
if (PyUnicode_Check(res)) {
PyObject* str;
str = PyUnicode_AsEncodedString(res, NULL, NULL);
else
return NULL;
}
-#endif
assert(PyString_Check(res));
return res;
}
-#ifdef Py_USING_UNICODE
PyObject *
PyObject_Unicode(PyObject *v)
{
}
return res;
}
-#endif
/* The new comparison philosophy is: we completely separate three-way
PyTypeObject *tp = v->ob_type;
if (!PyString_Check(name)) {
-#ifdef Py_USING_UNICODE
/* The Unicode to string conversion is done here because the
existing tp_getattro slots expect a string object as name
and we wouldn't want to break those. */
return NULL;
}
else
-#endif
{
PyErr_Format(PyExc_TypeError,
"attribute name must be string, not '%.200s'",
int err;
if (!PyString_Check(name)){
-#ifdef Py_USING_UNICODE
/* The Unicode to string conversion is done here because the
existing tp_setattro slots expect a string object as name
and we wouldn't want to break those. */
return -1;
}
else
-#endif
{
PyErr_Format(PyExc_TypeError,
"attribute name must be string, not '%.200s'",
PyObject **dictptr;
if (!PyString_Check(name)){
-#ifdef Py_USING_UNICODE
/* The Unicode to string conversion is done here because the
existing tp_setattro slots expect a string object as name
and we wouldn't want to break those. */
return NULL;
}
else
-#endif
{
PyErr_Format(PyExc_TypeError,
"attribute name must be string, not '%.200s'",
int res = -1;
if (!PyString_Check(name)){
-#ifdef Py_USING_UNICODE
/* The Unicode to string conversion is done here because the
existing tp_setattro slots expect a string object as name
and we wouldn't want to break those. */
return -1;
}
else
-#endif
{
PyErr_Format(PyExc_TypeError,
"attribute name must be string, not '%.200s'",
}
if (encoding == NULL) {
-#ifdef Py_USING_UNICODE
encoding = PyUnicode_GetDefaultEncoding();
-#else
- PyErr_SetString(PyExc_ValueError, "no encoding specified");
- goto onError;
-#endif
}
/* Decode via the codec registry */
if (v == NULL)
goto onError;
-#ifdef Py_USING_UNICODE
/* Convert Unicode to a string using the default encoding */
if (PyUnicode_Check(v)) {
PyObject *temp = v;
if (v == NULL)
goto onError;
}
-#endif
if (!PyString_Check(v)) {
PyErr_Format(PyExc_TypeError,
"decoder did not return a string object (type=%.400s)",
}
if (encoding == NULL) {
-#ifdef Py_USING_UNICODE
encoding = PyUnicode_GetDefaultEncoding();
-#else
- PyErr_SetString(PyExc_ValueError, "no encoding specified");
- goto onError;
-#endif
}
/* Encode via the codec registry */
if (v == NULL)
goto onError;
-#ifdef Py_USING_UNICODE
/* Convert Unicode to a string using the default encoding */
if (PyUnicode_Check(v)) {
PyObject *temp = v;
if (v == NULL)
goto onError;
}
-#endif
if (!PyString_Check(v)) {
PyErr_Format(PyExc_TypeError,
"encoder did not return a string object (type=%.400s)",
while (s < end) {
if (*s != '\\') {
non_esc:
-#ifdef Py_USING_UNICODE
if (recode_encoding && (*s & 0x80)) {
PyObject *u, *w;
char *r;
} else {
*p++ = *s++;
}
-#else
- *p++ = *s++;
-#endif
continue;
}
s++;
errors);
goto failed;
}
-#ifndef Py_USING_UNICODE
- case 'u':
- case 'U':
- case 'N':
- if (unicode) {
- PyErr_SetString(PyExc_ValueError,
- "Unicode escapes not legal "
- "when Unicode disabled");
- goto failed;
- }
-#endif
default:
*p++ = '\\';
s--;
}
if (!PyString_Check(obj)) {
-#ifdef Py_USING_UNICODE
if (PyUnicode_Check(obj)) {
obj = _PyUnicode_AsDefaultEncodedString(obj, NULL);
if (obj == NULL)
return -1;
}
else
-#endif
{
PyErr_Format(PyExc_TypeError,
- "expected string or Unicode object, "
+ "expected str object, "
"%.200s found", obj->ob_type->tp_name);
return -1;
}
register Py_ssize_t size;
register PyStringObject *op;
if (!PyString_Check(bb)) {
-#ifdef Py_USING_UNICODE
if (PyUnicode_Check(bb))
return PyUnicode_Concat((PyObject *)a, bb);
-#endif
if (PyBytes_Check(bb))
return PyBytes_Concat((PyObject *)a, bb);
PyErr_Format(PyExc_TypeError,
string_contains(PyObject *str_obj, PyObject *sub_obj)
{
if (!PyString_CheckExact(sub_obj)) {
-#ifdef Py_USING_UNICODE
if (PyUnicode_Check(sub_obj))
return PyUnicode_Contains(str_obj, sub_obj);
-#endif
if (!PyString_Check(sub_obj)) {
PyErr_Format(PyExc_TypeError,
"'in <string>' requires string as left operand, "
sub = PyString_AS_STRING(subobj);
n = PyString_GET_SIZE(subobj);
}
-#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(subobj))
return PyUnicode_Split((PyObject *)self, subobj, maxsplit);
-#endif
else if (PyObject_AsCharBuffer(subobj, &sub, &n))
return NULL;
sep = PyString_AS_STRING(sep_obj);
sep_len = PyString_GET_SIZE(sep_obj);
}
-#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(sep_obj))
return PyUnicode_Partition((PyObject *) self, sep_obj);
-#endif
else if (PyObject_AsCharBuffer(sep_obj, &sep, &sep_len))
return NULL;
sep = PyString_AS_STRING(sep_obj);
sep_len = PyString_GET_SIZE(sep_obj);
}
-#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(sep_obj))
return PyUnicode_Partition((PyObject *) self, sep_obj);
-#endif
else if (PyObject_AsCharBuffer(sep_obj, &sep, &sep_len))
return NULL;
sub = PyString_AS_STRING(subobj);
n = PyString_GET_SIZE(subobj);
}
-#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(subobj))
return PyUnicode_RSplit((PyObject *)self, subobj, maxsplit);
-#endif
else if (PyObject_AsCharBuffer(subobj, &sub, &n))
return NULL;
const size_t old_sz = sz;
item = PySequence_Fast_GET_ITEM(seq, i);
if (!PyString_Check(item)){
-#ifdef Py_USING_UNICODE
if (PyUnicode_Check(item)) {
/* Defer to Unicode join.
* CAUTION: There's no gurantee that the
Py_DECREF(seq);
return result;
}
-#endif
PyErr_Format(PyExc_TypeError,
"sequence item %zd: expected string,"
" %.80s found",
sub = PyString_AS_STRING(subobj);
sub_len = PyString_GET_SIZE(subobj);
}
-#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(subobj))
return PyUnicode_Find(
(PyObject *)self, subobj, start, end, dir);
-#endif
else if (PyObject_AsCharBuffer(subobj, &sub, &sub_len))
/* XXX - the "expected a character buffer object" is pretty
confusing for a non-expert. remap to something else ? */
if (sep != NULL && sep != Py_None) {
if (PyString_Check(sep))
return do_xstrip(self, striptype, sep);
-#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(sep)) {
PyObject *uniself = PyUnicode_FromObject((PyObject *)self);
PyObject *res;
Py_DECREF(uniself);
return res;
}
-#endif
PyErr_Format(PyExc_TypeError,
-#ifdef Py_USING_UNICODE
- "%s arg must be None, str or unicode",
-#else
"%s arg must be None or str",
-#endif
STRIPNAME(striptype));
return NULL;
}
PyDoc_STRVAR(strip__doc__,
-"S.strip([chars]) -> string or unicode\n\
+"S.strip([chars]) -> str\n\
\n\
Return a copy of the string S with leading and trailing\n\
whitespace removed.\n\
PyDoc_STRVAR(lstrip__doc__,
-"S.lstrip([chars]) -> string or unicode\n\
+"S.lstrip([chars]) -> str\n\
\n\
Return a copy of the string S with leading whitespace removed.\n\
If chars is given and not None, remove characters in chars instead.\n\
PyDoc_STRVAR(rstrip__doc__,
-"S.rstrip([chars]) -> string or unicode\n\
+"S.rstrip([chars]) -> str\n\
\n\
Return a copy of the string S with trailing whitespace removed.\n\
If chars is given and not None, remove characters in chars instead.\n\
sub = PyString_AS_STRING(sub_obj);
sub_len = PyString_GET_SIZE(sub_obj);
}
-#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(sub_obj)) {
Py_ssize_t count;
count = PyUnicode_Count((PyObject *)self, sub_obj, start, end);
else
return PyInt_FromSsize_t(count);
}
-#endif
else if (PyObject_AsCharBuffer(sub_obj, &sub, &sub_len))
return NULL;
table = NULL;
tablen = 256;
}
-#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(tableobj)) {
/* Unicode .translate() does not support the deletechars
parameter; instead a mapping to None will cause characters
}
return PyUnicode_Translate((PyObject *)self, tableobj, NULL);
}
-#endif
else if (PyObject_AsCharBuffer(tableobj, &table, &tablen))
return NULL;
del_table = PyString_AS_STRING(delobj);
dellen = PyString_GET_SIZE(delobj);
}
-#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(delobj)) {
PyErr_SetString(PyExc_TypeError,
"deletions are implemented differently for unicode");
return NULL;
}
-#endif
else if (PyObject_AsCharBuffer(delobj, &del_table, &dellen))
return NULL;
}
from_s = PyString_AS_STRING(from);
from_len = PyString_GET_SIZE(from);
}
-#ifdef Py_USING_UNICODE
if (PyUnicode_Check(from))
return PyUnicode_Replace((PyObject *)self,
from, to, count);
-#endif
else if (PyObject_AsCharBuffer(from, &from_s, &from_len))
return NULL;
to_s = PyString_AS_STRING(to);
to_len = PyString_GET_SIZE(to);
}
-#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(to))
return PyUnicode_Replace((PyObject *)self,
from, to, count);
-#endif
else if (PyObject_AsCharBuffer(to, &to_s, &to_len))
return NULL;
sub = PyString_AS_STRING(substr);
slen = PyString_GET_SIZE(substr);
}
-#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(substr))
return PyUnicode_Tailmatch((PyObject *)self,
substr, start, end, direction);
-#endif
else if (PyObject_AsCharBuffer(substr, &sub, &slen))
return -1;
str = PyString_AS_STRING(self);
PyTypeObject PyString_Type = {
PyObject_HEAD_INIT(&PyType_Type)
0,
- "str8",
+ "str",
sizeof(PyStringObject),
sizeof(char),
string_dealloc, /* tp_dealloc */
Py_ssize_t reslen, rescnt, fmtcnt;
int args_owned = 0;
PyObject *result, *orig_args;
-#ifdef Py_USING_UNICODE
PyObject *v, *w;
-#endif
PyObject *dict = NULL;
if (format == NULL || !PyString_Check(format) || args == NULL) {
PyErr_BadInternalCall();
Py_ssize_t len;
char formatbuf[FORMATBUFLEN];
/* For format{float,int,char}() */
-#ifdef Py_USING_UNICODE
char *fmt_start = fmt;
Py_ssize_t argidx_start = argidx;
-#endif
fmt++;
if (*fmt == '(') {
len = 1;
break;
case 's':
-#ifdef Py_USING_UNICODE
if (PyUnicode_Check(v)) {
fmt = fmt_start;
argidx = argidx_start;
goto unicode;
}
-#endif
temp = _PyObject_Str(v);
-#ifdef Py_USING_UNICODE
if (temp != NULL && PyUnicode_Check(temp)) {
Py_DECREF(temp);
fmt = fmt_start;
argidx = argidx_start;
goto unicode;
}
-#endif
/* Fall through */
case 'r':
if (c == 'r')
fill = '0';
break;
case 'c':
-#ifdef Py_USING_UNICODE
if (PyUnicode_Check(v)) {
fmt = fmt_start;
argidx = argidx_start;
goto unicode;
}
-#endif
pbuf = formatbuf;
len = formatchar(pbuf, sizeof(formatbuf), v);
if (len < 0)
_PyString_Resize(&result, reslen - rescnt);
return result;
-#ifdef Py_USING_UNICODE
unicode:
if (args_owned) {
Py_DECREF(args);
Py_DECREF(v);
Py_DECREF(args);
return w;
-#endif /* Py_USING_UNICODE */
error:
Py_DECREF(result);
return 1;
}
-#ifdef Py_USING_UNICODE
/* Replace Unicode objects in slots. */
static PyObject *
}
return slots;
}
-#endif
/* Forward */
static int
return NULL;
}
-#ifdef Py_USING_UNICODE
tmp = _unicode_to_string(slots, nslots);
if (tmp == NULL)
goto bad_slots;
Py_DECREF(slots);
slots = tmp;
}
-#endif
/* Check for valid slot names and two special cases */
for (i = 0; i < nslots; i++) {
PyObject *tmp = PyTuple_GET_ITEM(slots, i);
/* Define if you want to use the GNU readline library */
/* #define WITH_READLINE 1 */
-/* Define if you want to have a Unicode type. */
-#define Py_USING_UNICODE
-
/* Define as the integral type used for Unicode representation. */
#define PY_UNICODE_TYPE unsigned short
strcmp(cs, "iso-8859-1") == 0) {
tok->encoding = cs;
} else {
-#ifdef Py_USING_UNICODE
r = set_readline(tok, cs);
if (r) {
tok->encoding = cs;
}
else
PyMem_FREE(cs);
-#else
- /* Without Unicode support, we cannot
- process the coding spec. Since there
- won't be any Unicode literals, that
- won't matter. */
- PyMem_FREE(cs);
-#endif
}
} else { /* then, compare cs with BOM */
r = (strcmp(tok->encoding, cs) == 0);
static char *
fp_readl(char *s, int size, struct tok_state *tok)
{
-#ifndef Py_USING_UNICODE
- /* In a non-Unicode built, this should never be called. */
- Py_FatalError("fp_readl should not be called in this build.");
- return NULL; /* Keep compiler happy (not reachable) */
-#else
PyObject* utf8 = NULL;
PyObject* buf = tok->decoding_buffer;
char *str;
Py_DECREF(utf8);
if (utf8len == 0) return NULL; /* EOF */
return s;
-#endif
}
/* Set the readline function for TOK to a StreamReader's
/* Return a UTF-8 encoding Python string object from the
C byte string STR, which is encoded with ENC. */
-#ifdef Py_USING_UNICODE
static PyObject *
translate_into_utf8(const char* str, const char* enc) {
PyObject *utf8;
Py_DECREF(buf);
return utf8;
}
-#endif
/* Decode a byte string STR for use as the buffer of TOK.
Look for encoding declarations inside STR, and record them
return error_ret(tok);
str = tok->str; /* string after BOM if any */
assert(str);
-#ifdef Py_USING_UNICODE
if (tok->enc != NULL) {
utf8 = translate_into_utf8(str, tok->enc);
if (utf8 == NULL)
return error_ret(tok);
str = PyString_AsString(utf8);
}
-#endif
for (s = str;; s++) {
if (*s == '\0') break;
else if (*s == '\n') {
tok->enc = NULL;
if (!check_coding_spec(str, s - str, tok, buf_setreadl))
return error_ret(tok);
-#ifdef Py_USING_UNICODE
if (tok->enc != NULL) {
assert(utf8 == NULL);
utf8 = translate_into_utf8(str, tok->enc);
}
str = PyString_AsString(utf8);
}
-#endif
assert(tok->decoding_buffer == NULL);
tok->decoding_buffer = utf8; /* CAUTION */
return str;
PyMem_FREE(tok);
}
-#if !defined(PGEN) && defined(Py_USING_UNICODE)
+#if !defined(PGEN)
static int
tok_stdin_decode(struct tok_state *tok, char **inp)
{
PyMem_FREE(newtok);
tok->done = E_EOF;
}
-#if !defined(PGEN) && defined(Py_USING_UNICODE)
+#if !defined(PGEN)
else if (tok_stdin_decode(tok, &newtok) != 0)
PyMem_FREE(newtok);
#endif
static PyObject *
decode_utf8(const char **sPtr, const char *end, char* encoding)
{
-#ifndef Py_USING_UNICODE
- Py_FatalError("decode_utf8 should not be called in this build.");
- return NULL;
-#else
PyObject *u, *v;
char *s, *t;
t = s = (char *)*sPtr;
v = PyUnicode_AsEncodedString(u, encoding, NULL);
Py_DECREF(u);
return v;
-#endif
}
static PyObject *
return NULL;
}
}
-#ifdef Py_USING_UNICODE
if (!*bytesmode) {
return decode_unicode(s, len, rawmode, encoding);
}
-#endif
if (*bytesmode) {
/* Disallow non-ascii characters (but not escapes) */
const char *c;
strcmp(encoding, "iso-8859-1") != 0);
if (rawmode || strchr(s, '\\') == NULL) {
if (need_encoding) {
-#ifndef Py_USING_UNICODE
- /* This should not happen - we never see any other
- encoding. */
- Py_FatalError(
- "cannot deal with encodings in this build.");
-#else
PyObject *v, *u = PyUnicode_DecodeUTF8(s, len, NULL);
if (u == NULL)
return NULL;
v = PyUnicode_AsEncodedString(u, encoding, NULL);
Py_DECREF(u);
return v;
-#endif
} else {
return PyString_FromStringAndSize(s, len);
}
if (v == NULL)
goto onError;
}
-#ifdef Py_USING_UNICODE
else {
PyObject *temp = PyUnicode_Concat(v, s);
Py_DECREF(s);
if (v == NULL)
goto onError;
}
-#endif
}
}
return v;
/* Forward */
static PyObject *filterstring(PyObject *, PyObject *);
-#ifdef Py_USING_UNICODE
static PyObject *filterunicode(PyObject *, PyObject *);
-#endif
static PyObject *filtertuple (PyObject *, PyObject *);
static PyObject *
/* Strings and tuples return a result of the same type. */
if (PyString_Check(seq))
return filterstring(func, seq);
-#ifdef Py_USING_UNICODE
if (PyUnicode_Check(seq))
return filterunicode(func, seq);
-#endif
if (PyTuple_Check(seq))
return filtertuple(func, seq);
"or string, return the same type, else return a list.");
-#ifdef Py_USING_UNICODE
static PyObject *
builtin_unichr(PyObject *self, PyObject *args)
{
"chr(i) -> Unicode character\n\
\n\
Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff.");
-#endif
static PyObject *
cf.cf_flags = supplied_flags;
-#ifdef Py_USING_UNICODE
if (PyUnicode_Check(cmd)) {
tmp = PyUnicode_AsUTF8String(cmd);
if (tmp == NULL)
cmd = tmp;
cf.cf_flags |= PyCF_SOURCE_IS_UTF8;
}
-#endif
if (PyObject_AsReadBuffer(cmd, (const void **)&str, &length))
return NULL;
if ((size_t)length != strlen(str)) {
}
cf.cf_flags = 0;
-#ifdef Py_USING_UNICODE
if (PyUnicode_Check(cmd)) {
tmp = PyUnicode_AsUTF8String(cmd);
if (tmp == NULL)
cmd = tmp;
cf.cf_flags |= PyCF_SOURCE_IS_UTF8;
}
-#endif
if (PyString_AsStringAndSize(cmd, &str, NULL)) {
Py_XDECREF(tmp);
return NULL;
char *str;
PyCompilerFlags cf;
cf.cf_flags = 0;
-#ifdef Py_USING_UNICODE
if (PyUnicode_Check(prog)) {
tmp = PyUnicode_AsUTF8String(prog);
if (tmp == NULL)
prog = tmp;
cf.cf_flags |= PyCF_SOURCE_IS_UTF8;
}
-#endif
if (PyString_AsStringAndSize(prog, &str, NULL))
return NULL;
if (PyEval_MergeCompilerFlags(&cf))
if (!PyArg_UnpackTuple(args, "getattr", 2, 3, &v, &name, &dflt))
return NULL;
-#ifdef Py_USING_UNICODE
if (PyUnicode_Check(name)) {
name = _PyUnicode_AsDefaultEncodedString(name, NULL);
if (name == NULL)
return NULL;
}
-#endif
if (!PyString_Check(name)) {
PyErr_SetString(PyExc_TypeError,
if (!PyArg_UnpackTuple(args, "hasattr", 2, 2, &v, &name))
return NULL;
-#ifdef Py_USING_UNICODE
if (PyUnicode_Check(name)) {
name = _PyUnicode_AsDefaultEncodedString(name, NULL);
if (name == NULL)
return NULL;
}
-#endif
if (!PyString_Check(name)) {
PyErr_SetString(PyExc_TypeError,
ord = (long)((unsigned char)*PyString_AS_STRING(obj));
return PyInt_FromLong(ord);
}
-#ifdef Py_USING_UNICODE
}
else if (PyUnicode_Check(obj)) {
size = PyUnicode_GET_SIZE(obj);
ord = (long)*PyUnicode_AS_UNICODE(obj);
return PyInt_FromLong(ord);
}
-#endif
}
else if (PyBytes_Check(obj)) {
/* XXX Hopefully this is temporary */
SETBUILTIN("tuple", &PyTuple_Type);
SETBUILTIN("type", &PyType_Type);
SETBUILTIN("xrange", &PyRange_Type);
-#ifdef Py_USING_UNICODE
SETBUILTIN("unicode", &PyUnicode_Type);
-#endif
debug = PyBool_FromLong(Py_OptimizeFlag == 0);
if (PyDict_SetItemString(dict, "__debug__", debug) < 0) {
Py_XDECREF(debug);
return NULL;
}
-#ifdef Py_USING_UNICODE
/* Helper for filter(): filter a Unicode object through a function */
static PyObject *
Py_DECREF(result);
return NULL;
}
-#endif
}
-#ifdef Py_USING_UNICODE
PyObject *PyCodec_IgnoreErrors(PyObject *exc)
{
Py_ssize_t end;
return NULL;
}
}
-#endif
static PyObject *strict_errors(PyObject *self, PyObject *exc)
{
}
-#ifdef Py_USING_UNICODE
static PyObject *ignore_errors(PyObject *self, PyObject *exc)
{
return PyCodec_IgnoreErrors(exc);
{
return PyCodec_BackslashReplaceErrors(exc);
}
-#endif
static int _PyCodecRegistry_Init(void)
{
METH_O
}
},
-#ifdef Py_USING_UNICODE
{
"ignore",
{
METH_O
}
}
-#endif
};
PyInterpreterState *interp = PyThreadState_GET()->interp;
const char *format = *p_format;
char c = *format++;
-#ifdef Py_USING_UNICODE
PyObject *uarg;
-#endif
switch (c) {
*p = PyString_AS_STRING(arg);
STORE_SIZE(PyString_GET_SIZE(arg));
}
-#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(arg)) {
uarg = UNICODE_DEFAULT_ENCODING(arg);
if (uarg == NULL)
*p = PyString_AS_STRING(uarg);
STORE_SIZE(PyString_GET_SIZE(uarg));
}
-#endif
else { /* any buffer-like object */
char *buf;
Py_ssize_t count = convertbuffer(arg, p, &buf);
if (PyString_Check(arg))
*p = PyString_AS_STRING(arg);
-#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(arg)) {
uarg = UNICODE_DEFAULT_ENCODING(arg);
if (uarg == NULL)
arg, msgbuf, bufsize);
*p = PyString_AS_STRING(uarg);
}
-#endif
else
return converterr("string", arg, msgbuf, bufsize);
if ((Py_ssize_t)strlen(*p) != PyString_Size(arg))
*p = PyString_AS_STRING(arg);
STORE_SIZE(PyString_GET_SIZE(arg));
}
-#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(arg)) {
uarg = UNICODE_DEFAULT_ENCODING(arg);
if (uarg == NULL)
*p = PyString_AS_STRING(uarg);
STORE_SIZE(PyString_GET_SIZE(uarg));
}
-#endif
else { /* any buffer-like object */
char *buf;
Py_ssize_t count = convertbuffer(arg, p, &buf);
*p = 0;
else if (PyString_Check(arg))
*p = PyString_AS_STRING(arg);
-#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(arg)) {
uarg = UNICODE_DEFAULT_ENCODING(arg);
if (uarg == NULL)
arg, msgbuf, bufsize);
*p = PyString_AS_STRING(uarg);
}
-#endif
else
return converterr("string or None",
arg, msgbuf, bufsize);
/* Get 'e' parameter: the encoding name */
encoding = (const char *)va_arg(*p_va, const char *);
-#ifdef Py_USING_UNICODE
if (encoding == NULL)
encoding = PyUnicode_GetDefaultEncoding();
-#endif
/* Get output buffer parameter:
's' (recode all objects via Unicode) or
Py_INCREF(s);
}
else {
-#ifdef Py_USING_UNICODE
PyObject *u;
/* Convert object to Unicode */
"(encoder failed to return a string)",
arg, msgbuf, bufsize);
}
-#else
- return converterr("string<e>", arg, msgbuf, bufsize);
-#endif
}
size = PyString_GET_SIZE(s);
break;
}
-#ifdef Py_USING_UNICODE
case 'u': {/* raw unicode buffer (Py_UNICODE *) */
if (*format == '#') { /* any buffer-like object */
void **p = (void **)va_arg(*p_va, char **);
}
break;
}
-#endif
case 'S': { /* string object */
PyObject **p = va_arg(*p_va, PyObject **);
break;
}
-#ifdef Py_USING_UNICODE
case 'U': { /* Unicode object */
PyObject **p = va_arg(*p_va, PyObject **);
if (PyUnicode_Check(arg))
return converterr("unicode", arg, msgbuf, bufsize);
break;
}
-#endif
case 'O': { /* object */
PyTypeObject *type;
case 's': /* string */
case 'z': /* string or None */
-#ifdef Py_USING_UNICODE
case 'u': /* unicode string */
-#endif
case 't': /* buffer, read-only */
case 'w': /* buffer, read-write */
{
/* object codes */
case 'S': /* string object */
-#ifdef Py_USING_UNICODE
case 'U': /* unicode string object */
-#endif
{
(void) va_arg(*p_va, PyObject **);
break;
PyObject *v = PyList_GetItem(path, i);
if (!v)
return NULL;
-#ifdef Py_USING_UNICODE
if (PyUnicode_Check(v)) {
copy = PyUnicode_Encode(PyUnicode_AS_UNICODE(v),
PyUnicode_GET_SIZE(v), Py_FileSystemDefaultEncoding, NULL);
v = copy;
}
else
-#endif
if (!PyString_Check(v))
continue;
len = PyString_GET_SIZE(v);
w_long((long)n, p);
w_string(PyString_AS_STRING(v), (int)n, p);
}
-#ifdef Py_USING_UNICODE
else if (PyUnicode_Check(v)) {
PyObject *utf8;
utf8 = PyUnicode_AsUTF8String(v);
w_string(PyString_AS_STRING(utf8), (int)n, p);
Py_DECREF(utf8);
}
-#endif
else if (PyTuple_Check(v)) {
w_byte(TYPE_TUPLE, p);
n = PyTuple_Size(v);
Py_INCREF(v);
return v;
-#ifdef Py_USING_UNICODE
case TYPE_UNICODE:
{
char *buffer;
PyMem_DEL(buffer);
return v;
}
-#endif
case TYPE_TUPLE:
n = r_long(p);
return v;
}
-#ifdef Py_USING_UNICODE
static int
_ustrlen(Py_UNICODE *u)
{
while (*v != 0) { i++; v++; }
return i;
}
-#endif
static PyObject *
do_mktuple(const char **p_format, va_list *p_va, int endchar, int n, int flags)
case 'K':
return PyLong_FromUnsignedLongLong((PY_LONG_LONG)va_arg(*p_va, unsigned PY_LONG_LONG));
#endif
-#ifdef Py_USING_UNICODE
case 'u':
{
PyObject *v;
}
return v;
}
-#endif
case 'f':
case 'd':
return PyFloat_FromDouble(
PyThreadState *tstate;
PyObject *bimod, *sysmod;
char *p;
-#if defined(Py_USING_UNICODE) && defined(HAVE_LANGINFO_H) && defined(CODESET)
+#if defined(HAVE_LANGINFO_H) && defined(CODESET)
char *codeset;
char *saved_locale;
PyObject *sys_stream, *sys_isatty;
if (interp->modules_reloading == NULL)
Py_FatalError("Py_Initialize: can't make modules_reloading dictionary");
-#ifdef Py_USING_UNICODE
/* Init Unicode implementation; relies on the codec registry */
_PyUnicode_Init();
-#endif
bimod = _PyBuiltin_Init();
if (bimod == NULL)
if (!warnings_module)
PyErr_Clear();
-#if defined(Py_USING_UNICODE) && defined(HAVE_LANGINFO_H) && defined(CODESET)
+#if defined(HAVE_LANGINFO_H) && defined(CODESET)
/* On Unix, set the file system encoding according to the
user's preference, if the CODESET names a well-known
Python codec, and Py_FileSystemDefaultEncoding isn't
PyLong_Fini();
PyFloat_Fini();
-#ifdef Py_USING_UNICODE
/* Cleanup Unicode implementation */
_PyUnicode_Fini();
-#endif
/* XXX Still allocated:
- various static ad-hoc pointers to interned strings
exit status will be one (i.e., failure)."
);
-#ifdef Py_USING_UNICODE
static PyObject *
sys_getdefaultencoding(PyObject *self)
operating system filenames."
);
-#endif
static PyObject *
{"exc_clear", sys_exc_clear, METH_NOARGS, exc_clear_doc},
{"excepthook", sys_excepthook, METH_VARARGS, excepthook_doc},
{"exit", sys_exit, METH_VARARGS, exit_doc},
-#ifdef Py_USING_UNICODE
{"getdefaultencoding", (PyCFunction)sys_getdefaultencoding,
METH_NOARGS, getdefaultencoding_doc},
-#endif
#ifdef HAVE_DLOPEN
{"getdlopenflags", (PyCFunction)sys_getdlopenflags, METH_NOARGS,
getdlopenflags_doc},
#ifdef DYNAMIC_EXECUTION_PROFILE
{"getdxp", _Py_GetDXProfile, METH_VARARGS},
#endif
-#ifdef Py_USING_UNICODE
{"getfilesystemencoding", (PyCFunction)sys_getfilesystemencoding,
METH_NOARGS, getfilesystemencoding_doc},
-#endif
#ifdef Py_TRACE_REFS
{"getobjects", _Py_GetObjects, METH_VARARGS},
#endif
#ifdef USE_MALLOPT
{"mdebug", sys_mdebug, METH_VARARGS},
#endif
-#ifdef Py_USING_UNICODE
{"setdefaultencoding", sys_setdefaultencoding, METH_VARARGS,
setdefaultencoding_doc},
-#endif
{"setcheckinterval", sys_setcheckinterval, METH_VARARGS,
setcheckinterval_doc},
{"getcheckinterval", sys_getcheckinterval, METH_NOARGS,
PyString_FromString(Py_GetExecPrefix()));
SET_SYS_FROM_STRING("maxint",
PyInt_FromLong(PyInt_GetMax()));
-#ifdef Py_USING_UNICODE
SET_SYS_FROM_STRING("maxunicode",
PyInt_FromLong(PyUnicode_GetMax()));
-#endif
SET_SYS_FROM_STRING("builtin_module_names",
list_builtin_module_names());
{
/* This must be defined on some systems to enable large file support */
#undef _LARGEFILE_SOURCE
-/* Define if you want to have a Unicode type. */
-#define Py_USING_UNICODE 1
-
/* Define as the integral type used for Unicode representation. */
#define PY_UNICODE_TYPE unsigned short