document that various functions that parse from source will interpret things as latin-1 (closes #18870)

This commit is contained in:
Benjamin Peterson 2013-09-01 19:06:35 -04:00
parent 71b2ded05e
commit b44c8619fe
3 changed files with 21 additions and 18 deletions

View File

@ -131,10 +131,10 @@ and classes for traversing abstract syntax trees:
.. function:: literal_eval(node_or_string)
Safely evaluate an expression node or a string containing a Python
expression. The string or node provided may only consist of the following
Python literal structures: strings, numbers, tuples, lists, dicts, booleans,
and ``None``.
Safely evaluate an expression node or a Unicode or *Latin-1* encoded string
containing a Python expression. The string or node provided may only consist
of the following Python literal structures: strings, numbers, tuples, lists,
dicts, booleans, and ``None``.
This can be used for safely evaluating strings containing Python expressions
from untrusted sources without the need to parse the values oneself.

View File

@ -199,8 +199,10 @@ available. They are listed here in alphabetical order.
Compile the *source* into a code or AST object. Code objects can be executed
by an :keyword:`exec` statement or evaluated by a call to :func:`eval`.
*source* can either be a string or an AST object. Refer to the :mod:`ast`
module documentation for information on how to work with AST objects.
*source* can either be a Unicode string, a *Latin-1* encoded string or an
AST object.
Refer to the :mod:`ast` module documentation for information on how to work
with AST objects.
The *filename* argument should give the file from which the code was read;
pass some recognizable value if it wasn't read from a file (``'<string>'`` is
@ -388,9 +390,9 @@ available. They are listed here in alphabetical order.
.. function:: eval(expression[, globals[, locals]])
The arguments are a string and optional globals and locals. If provided,
*globals* must be a dictionary. If provided, *locals* can be any mapping
object.
The arguments are a Unicode or *Latin-1* encoded string and optional
globals and locals. If provided, *globals* must be a dictionary.
If provided, *locals* can be any mapping object.
.. versionchanged:: 2.4
formerly *locals* was required to be a dictionary.

View File

@ -981,15 +981,16 @@ The :keyword:`exec` statement
exec_stmt: "exec" `or_expr` ["in" `expression` ["," `expression`]]
This statement supports dynamic execution of Python code. The first expression
should evaluate to either a string, an open file object, a code object, or a
tuple. If it is a string, the string is parsed as a suite of Python statements
which is then executed (unless a syntax error occurs). [#]_ If it is an open
file, the file is parsed until EOF and executed. If it is a code object, it is
simply executed. For the interpretation of a tuple, see below. In all cases,
the code that's executed is expected to be valid as file input (see section
:ref:`file-input`). Be aware that the :keyword:`return` and :keyword:`yield`
statements may not be used outside of function definitions even within the
context of code passed to the :keyword:`exec` statement.
should evaluate to either a Unicode string, a *Latin-1* encoded string, an open
file object, a code object, or a tuple. If it is a string, the string is parsed
as a suite of Python statements which is then executed (unless a syntax error
occurs). [#]_ If it is an open file, the file is parsed until EOF and executed.
If it is a code object, it is simply executed. For the interpretation of a
tuple, see below. In all cases, the code that's executed is expected to be
valid as file input (see section :ref:`file-input`). Be aware that the
:keyword:`return` and :keyword:`yield` statements may not be used outside of
function definitions even within the context of code passed to the
:keyword:`exec` statement.
In all cases, if the optional parts are omitted, the code is executed in the
current scope. If only the first expression after ``in`` is specified,