Improve highlighting of some code blocks. (GH-6401)

This commit is contained in:
Serhiy Storchaka 2018-04-08 19:18:04 +03:00 committed by GitHub
parent 9265dd72e5
commit 46936d5a71
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 301 additions and 137 deletions

View file

@ -152,10 +152,10 @@ these functions again each time that the file is replaced.
Example
-------
.. highlight:: sh
Example of a segmentation fault on Linux with and without enabling the fault
handler::
handler:
.. code-block:: shell-session
$ python3 -c "import ctypes; ctypes.string_at(0)"
Segmentation fault

View file

@ -100,9 +100,9 @@ Extending :class:`JSONEncoder`::
['[2.0', ', 1.0', ']']
.. highlight:: bash
Using :mod:`json.tool` from the shell to validate and pretty-print:
Using :mod:`json.tool` from the shell to validate and pretty-print::
.. code-block:: shell-session
$ echo '{"json":"obj"}' | python -m json.tool
{
@ -113,8 +113,6 @@ Using :mod:`json.tool` from the shell to validate and pretty-print::
See :ref:`json-commandline` for detailed documentation.
.. highlight:: python3
.. note::
JSON is a subset of `YAML <http://yaml.org/>`_ 1.2. The JSON produced by
@ -647,8 +645,6 @@ when serializing Python :class:`int` values of extremely large magnitude, or
when serializing instances of "exotic" numerical types such as
:class:`decimal.Decimal`.
.. highlight:: bash
.. _json-commandline:
Command Line Interface
@ -665,7 +661,9 @@ The :mod:`json.tool` module provides a simple command line interface to validate
and pretty-print JSON objects.
If the optional ``infile`` and ``outfile`` arguments are not
specified, :attr:`sys.stdin` and :attr:`sys.stdout` will be used respectively::
specified, :attr:`sys.stdin` and :attr:`sys.stdout` will be used respectively:
.. code-block:: shell-session
$ echo '{"json": "obj"}' | python -m json.tool
{
@ -684,7 +682,9 @@ Command line options
.. cmdoption:: infile
The JSON file to be validated or pretty-printed::
The JSON file to be validated or pretty-printed:
.. code-block:: shell-session
$ python -m json.tool mp_films.json
[

View file

@ -538,7 +538,9 @@ target handler, and the system will resolve to the handler from the
id. If, however, a user defines a ``my.package.MyHandler`` which has
an ``alternate`` handler, the configuration system would not know that
the ``alternate`` referred to a handler. To cater for this, a generic
resolution system allows the user to specify::
resolution system allows the user to specify:
.. code-block:: yaml
handlers:
file:
@ -552,7 +554,9 @@ The literal string ``'cfg://handlers.file'`` will be resolved in an
analogous way to strings with the ``ext://`` prefix, but looking
in the configuration itself rather than the import namespace. The
mechanism allows access by dot or by index, in a similar way to
that provided by ``str.format``. Thus, given the following snippet::
that provided by ``str.format``. Thus, given the following snippet:
.. code-block:: yaml
handlers:
email:

View file

@ -179,7 +179,9 @@ is the module's name in the Python package namespace.
You can specify *stack_info* independently of *exc_info*, e.g. to just show
how you got to a certain point in your code, even when no exceptions were
raised. The stack frames are printed following a header line which says::
raised. The stack frames are printed following a header line which says:
.. code-block:: none
Stack (most recent call last):
@ -198,7 +200,9 @@ is the module's name in the Python package namespace.
logger = logging.getLogger('tcpserver')
logger.warning('Protocol problem: %s', 'connection reset', extra=d)
would print something like ::
would print something like
.. code-block:: none
2006-02-08 22:20:02,165 192.168.0.1 fbloggs Protocol problem: connection reset
@ -939,7 +943,9 @@ functions.
You can specify *stack_info* independently of *exc_info*, e.g. to just show
how you got to a certain point in your code, even when no exceptions were
raised. The stack frames are printed following a header line which says::
raised. The stack frames are printed following a header line which says:
.. code-block:: none
Stack (most recent call last):
@ -957,7 +963,9 @@ functions.
d = {'clientip': '192.168.0.1', 'user': 'fbloggs'}
logging.warning('Protocol problem: %s', 'connection reset', extra=d)
would print something like::
would print something like:
.. code-block:: none
2006-02-08 22:20:02,165 192.168.0.1 fbloggs Protocol problem: connection reset

View file

@ -222,7 +222,7 @@ Module contents
The :mod:`site` module also provides a way to get the user directories from the
command line:
.. code-block:: sh
.. code-block:: shell-session
$ python3 -m site --user-site
/home/user/.local/lib/python3.3/site-packages

View file

@ -25,7 +25,7 @@ Basic Examples
The following example shows how the :ref:`timeit-command-line-interface`
can be used to compare three different expressions:
.. code-block:: sh
.. code-block:: shell-session
$ python3 -m timeit '"-".join(str(n) for n in range(100))'
10000 loops, best of 5: 30.2 usec per loop
@ -264,7 +264,7 @@ Examples
It is possible to provide a setup statement that is executed only once at the beginning:
.. code-block:: sh
.. code-block:: shell-session
$ python -m timeit -s 'text = "sample string"; char = "g"' 'char in text'
5000000 loops, best of 5: 0.0877 usec per loop
@ -293,7 +293,7 @@ The following examples show how to time expressions that contain multiple lines.
Here we compare the cost of using :func:`hasattr` vs. :keyword:`try`/:keyword:`except`
to test for missing and present object attributes:
.. code-block:: sh
.. code-block:: shell-session
$ python -m timeit 'try:' ' str.__bool__' 'except AttributeError:' ' pass'
20000 loops, best of 5: 15.7 usec per loop

View file

@ -218,7 +218,7 @@ will be tokenized to the following output where the first column is the range
of the line/column coordinates where the token is found, the second column is
the name of the token, and the final column is the value of the token (if any)
.. code-block:: sh
.. code-block:: shell-session
$ python -m tokenize hello.py
0,0-0,0: ENCODING 'utf-8'
@ -244,7 +244,7 @@ the name of the token, and the final column is the value of the token (if any)
The exact token type names can be displayed using the :option:`-e` option:
.. code-block:: sh
.. code-block:: shell-session
$ python -m tokenize -e hello.py
0,0-0,0: ENCODING 'utf-8'

View file

@ -27,7 +27,7 @@ can be used to create an executable archive from a directory containing
Python code. When run, the archive will execute the ``main`` function from
the module ``myapp`` in the archive.
.. code-block:: sh
.. code-block:: shell-session
$ python -m zipapp myapp -m "myapp:main"
$ python myapp.pyz
@ -41,7 +41,7 @@ Command-Line Interface
When called as a program from the command line, the following form is used:
.. code-block:: sh
.. code-block:: shell-session
$ python -m zipapp source [options]
@ -189,7 +189,7 @@ Examples
Pack up a directory into an archive, and run it.
.. code-block:: sh
.. code-block:: shell-session
$ python -m zipapp myapp
$ python myapp.pyz
@ -203,7 +203,7 @@ The same can be done using the :func:`create_archive` functon::
To make the application directly executable on POSIX, specify an interpreter
to use.
.. code-block:: sh
.. code-block:: shell-session
$ python -m zipapp myapp -p "/usr/bin/env python"
$ ./myapp.pyz
@ -273,7 +273,7 @@ The steps to create a standalone archive are as follows:
2. Install all of your application's dependencies into the ``myapp`` directory,
using pip:
.. code-block:: sh
.. code-block:: shell-session
$ python -m pip install -r requirements.txt --target myapp
@ -288,7 +288,7 @@ The steps to create a standalone archive are as follows:
4. Package the application using:
.. code-block:: sh
.. code-block:: shell-session
$ python -m zipapp -p "interpreter" myapp