From: Martin Panter Date: Tue, 26 Jul 2016 09:18:21 +0000 (+0200) Subject: Issue #26462: Doc: avoid literal_block warnings, fix syntax highlighting. X-Git-Tag: v2.7.13rc1~229 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8f1dd224e002f93b67821a7a55db35152928d6da;p=python Issue #26462: Doc: avoid literal_block warnings, fix syntax highlighting. Patch by Julien Palard. --- diff --git a/Doc/distutils/packageindex.rst b/Doc/distutils/packageindex.rst index 74944953a6..80875845f6 100644 --- a/Doc/distutils/packageindex.rst +++ b/Doc/distutils/packageindex.rst @@ -235,7 +235,9 @@ in the root of the package besides :file:`setup.py`. To prevent registering broken reStructuredText content, you can use the :program:`rst2html` program that is provided by the :mod:`docutils` package and -check the ``long_description`` from the command line:: +check the ``long_description`` from the command line: + +.. code-block:: shell-session $ python setup.py --long-description | rst2html.py > output.html diff --git a/Doc/extending/building.rst b/Doc/extending/building.rst index 656af88131..f32192bd53 100644 --- a/Doc/extending/building.rst +++ b/Doc/extending/building.rst @@ -24,7 +24,9 @@ packages, users don't necessarily need a compiler and distutils to install the extension. A distutils package contains a driver script, :file:`setup.py`. This is a plain -Python file, which, in the most simple case, could look like this:: +Python file, which, in the most simple case, could look like this: + +.. code-block:: python from distutils.core import setup, Extension @@ -64,7 +66,9 @@ file, :file:`demo.c`. In many cases, building an extension is more complex, since additional preprocessor defines and libraries may be needed. This is demonstrated in the -example below. :: +example below. + +.. code-block:: python from distutils.core import setup, Extension @@ -129,4 +133,3 @@ commands can be used to do so. :: python setup.py bdist_wininst python setup.py bdist_rpm python setup.py bdist_dumb - diff --git a/Doc/extending/embedding.rst b/Doc/extending/embedding.rst index 981e1d546e..2330cdbc20 100644 --- a/Doc/extending/embedding.rst +++ b/Doc/extending/embedding.rst @@ -151,7 +151,9 @@ array. If you compile and link this program (let's call the finished executable c = c + b return c -then the result should be:: +then the result should be: + +.. code-block:: shell-session $ call multiply multiply 3 2 Will compute 3 times 2 @@ -274,16 +276,20 @@ available). This script has several options, of which the following will be directly useful to you: * ``pythonX.Y-config --cflags`` will give you the recommended flags when - compiling:: + compiling: + + .. code-block:: shell-session - $ /opt/bin/python2.7-config --cflags - -I/opt/include/python2.7 -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes + $ /opt/bin/python2.7-config --cflags + -I/opt/include/python2.7 -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes * ``pythonX.Y-config --ldflags`` will give you the recommended flags when - linking:: + linking: + + .. code-block:: shell-session - $ /opt/bin/python2.7-config --ldflags - -L/opt/lib/python2.7/config -lpthread -ldl -lutil -lm -lpython2.7 -Xlinker -export-dynamic + $ /opt/bin/python2.7-config --ldflags + -L/opt/lib/python2.7/config -lpthread -ldl -lutil -lm -lpython2.7 -Xlinker -export-dynamic .. note:: To avoid confusion between several Python installations (and especially diff --git a/Doc/extending/extending.rst b/Doc/extending/extending.rst index 36de32ae0a..37abbb7266 100644 --- a/Doc/extending/extending.rst +++ b/Doc/extending/extending.rst @@ -763,7 +763,9 @@ the format string is empty, it returns ``None``; if it contains exactly one format unit, it returns whatever object is described by that format unit. To force it to return a tuple of size 0 or one, parenthesize the format string. -Examples (to the left the call, to the right the resulting Python value):: +Examples (to the left the call, to the right the resulting Python value): + +.. code-block:: none Py_BuildValue("") None Py_BuildValue("i", 123) 123 diff --git a/Doc/extending/newtypes.rst b/Doc/extending/newtypes.rst index de1849c4a4..a642912b19 100644 --- a/Doc/extending/newtypes.rst +++ b/Doc/extending/newtypes.rst @@ -223,7 +223,9 @@ That's it! All that remains is to build it; put the above code in a file called setup(name="noddy", version="1.0", ext_modules=[Extension("noddy", ["noddy.c"])]) -in a file called :file:`setup.py`; then typing :: +in a file called :file:`setup.py`; then typing + +.. code-block:: shell-session $ python setup.py build @@ -1580,4 +1582,3 @@ might be something like the following:: .. [#] Even in the third version, we aren't guaranteed to avoid cycles. Instances of string subclasses are allowed and string subclasses could allow cycles even if normal strings don't. - diff --git a/Doc/faq/extending.rst b/Doc/faq/extending.rst index e78da55bf0..c3806457b0 100644 --- a/Doc/faq/extending.rst +++ b/Doc/faq/extending.rst @@ -156,6 +156,8 @@ The easiest way to do this is to use the StringIO class in the standard library. Sample code and use for catching stdout: +.. code-block:: pycon + >>> class StdoutCatcher: ... def __init__(self): ... self.data = '' @@ -219,11 +221,15 @@ How do I debug an extension? When using GDB with dynamically loaded extensions, you can't set a breakpoint in your extension until your extension is loaded. -In your ``.gdbinit`` file (or interactively), add the command:: +In your ``.gdbinit`` file (or interactively), add the command: + +.. code-block:: none br _PyImport_LoadDynamicModule -Then, when you run GDB:: +Then, when you run GDB: + +.. code-block:: shell-session $ gdb /local/bin/python gdb) run myscript.py @@ -469,6 +475,8 @@ parameter specifications for :c:func:`PyArg_ParseTuple`. You can check the size of the Unicode character a Python interpreter is using by checking the value of sys.maxunicode: +.. code-block:: pycon + >>> import sys >>> if sys.maxunicode > 65535: ... print 'UCS4 build' diff --git a/Doc/howto/logging-cookbook.rst b/Doc/howto/logging-cookbook.rst index 074c396712..b7f0fa5878 100644 --- a/Doc/howto/logging-cookbook.rst +++ b/Doc/howto/logging-cookbook.rst @@ -998,7 +998,9 @@ script, ``chowntest.py``:: logger = logging.getLogger('mylogger') logger.debug('A debug message') -To run this, you will probably need to run as ``root``:: +To run this, you will probably need to run as ``root``: + +.. code-block:: shell-session $ sudo python3.3 chowntest.py $ cat chowntest.log @@ -1500,7 +1502,9 @@ via ``stderr`` and once via ``stdout``). After the ``with`` statement's completion, the status is as it was before so message #6 appears (like message #1) whereas message #7 doesn't (just like message #2). -If we run the resulting script, the result is as follows:: +If we run the resulting script, the result is as follows: + +.. code-block:: shell-session $ python logctx.py 1. This should appear just once on stderr. @@ -1510,12 +1514,16 @@ If we run the resulting script, the result is as follows:: 6. This should appear just once on stderr. If we run it again, but pipe ``stderr`` to ``/dev/null``, we see the following, -which is the only message written to ``stdout``:: +which is the only message written to ``stdout``: + +.. code-block:: shell-session $ python logctx.py 2>/dev/null 5. This should appear twice - once on stderr and once on stdout. -Once again, but piping ``stdout`` to ``/dev/null``, we get:: +Once again, but piping ``stdout`` to ``/dev/null``, we get: + +.. code-block:: shell-session $ python logctx.py >/dev/null 1. This should appear just once on stderr. diff --git a/Doc/howto/logging.rst b/Doc/howto/logging.rst index 5b431f0ae0..6b17b088cd 100644 --- a/Doc/howto/logging.rst +++ b/Doc/howto/logging.rst @@ -106,7 +106,9 @@ A very simple example is:: logging.warning('Watch out!') # will print a message to the console logging.info('I told you so') # will not print anything -If you type these lines into a script and run it, you'll see:: +If you type these lines into a script and run it, you'll see: + +.. code-block:: none WARNING:root:Watch out! @@ -230,7 +232,9 @@ append the variable data as arguments. For example:: import logging logging.warning('%s before you %s', 'Look', 'leap!') -will display:: +will display: + +.. code-block:: none WARNING:root:Look before you leap! @@ -585,7 +589,9 @@ logger, a console handler, and a simple formatter using Python code:: logger.error('error message') logger.critical('critical message') -Running this module from the command line produces the following output:: +Running this module from the command line produces the following output: + +.. code-block:: shell-session $ python simple_logging_module.py 2005-03-19 15:10:26,618 - simple_example - DEBUG - debug message @@ -644,7 +650,9 @@ Here is the logging.conf file:: format=%(asctime)s - %(name)s - %(levelname)s - %(message)s datefmt= -The output is nearly identical to that of the non-config-file-based example:: +The output is nearly identical to that of the non-config-file-based example: + +.. code-block:: shell-session $ python simple_logging_config.py 2005-03-19 15:38:55,977 - simpleExample - DEBUG - debug message @@ -1041,4 +1049,3 @@ take up any memory. Useful handlers included with the logging module. :ref:`A logging cookbook ` - diff --git a/Doc/howto/regex.rst b/Doc/howto/regex.rst index 2c95fb425c..0d0e9f5609 100644 --- a/Doc/howto/regex.rst +++ b/Doc/howto/regex.rst @@ -79,7 +79,9 @@ of the RE by repeating them or changing their meaning. Much of this document is devoted to discussing various metacharacters and what they do. Here's a complete list of the metacharacters; their meanings will be discussed -in the rest of this HOWTO. :: +in the rest of this HOWTO. + +.. code-block:: none . ^ $ * + ? { } [ ] \ | ( ) diff --git a/Doc/howto/unicode.rst b/Doc/howto/unicode.rst index afd89c7a37..b94e5b5636 100644 --- a/Doc/howto/unicode.rst +++ b/Doc/howto/unicode.rst @@ -619,7 +619,9 @@ default filesystem encoding is UTF-8, running the following program:: print os.listdir('.') print os.listdir(u'.') -will produce the following output:: +will produce the following output: + +.. code-block:: shell-session amk:~$ python t.py ['.svn', 'filename\xe4\x94\x80abc', ...] diff --git a/Doc/library/2to3.rst b/Doc/library/2to3.rst index 9f59ddad86..8496676056 100644 --- a/Doc/library/2to3.rst +++ b/Doc/library/2to3.rst @@ -33,14 +33,18 @@ Here is a sample Python 2.x source file, :file:`example.py`:: name = raw_input() greet(name) -It can be converted to Python 3.x code via 2to3 on the command line:: +It can be converted to Python 3.x code via 2to3 on the command line: + +.. code-block:: shell-session $ 2to3 example.py A diff against the original source file is printed. 2to3 can also write the needed modifications right back to the source file. (A backup of the original file is made unless :option:`-n` is also given.) Writing the changes back is -enabled with the :option:`-w` flag:: +enabled with the :option:`-w` flag: + +.. code-block:: shell-session $ 2to3 -w example.py @@ -57,17 +61,23 @@ Comments and exact indentation are preserved throughout the translation process. By default, 2to3 runs a set of :ref:`predefined fixers <2to3-fixers>`. The :option:`-l` flag lists all available fixers. An explicit set of fixers to run can be given with :option:`-f`. Likewise the :option:`!-x` explicitly disables a -fixer. The following example runs only the ``imports`` and ``has_key`` fixers:: +fixer. The following example runs only the ``imports`` and ``has_key`` fixers: + +.. code-block:: shell-session $ 2to3 -f imports -f has_key example.py -This command runs every fixer except the ``apply`` fixer:: +This command runs every fixer except the ``apply`` fixer: + +.. code-block:: shell-session $ 2to3 -x apply example.py Some fixers are *explicit*, meaning they aren't run by default and must be listed on the command line to be run. Here, in addition to the default fixers, -the ``idioms`` fixer is run:: +the ``idioms`` fixer is run: + +.. code-block:: shell-session $ 2to3 -f all -f idioms example.py @@ -113,7 +123,9 @@ This option implies the :option:`-w` flag as it would not make sense otherwise. The :option:`--add-suffix` option specifies a string to append to all output filenames. The :option:`-n` flag is required when specifying this as backups -are not necessary when writing to different filenames. Example:: +are not necessary when writing to different filenames. Example: + +.. code-block:: shell-session $ 2to3 -n -W --add-suffix=3 example.py @@ -122,7 +134,9 @@ Will cause a converted file named ``example.py3`` to be written. .. versionadded:: 2.7.3 The :option:`--add-suffix` option was added. -To translate an entire project from one directory tree to another use:: +To translate an entire project from one directory tree to another use: + +.. code-block:: shell-session $ 2to3 --output-dir=python3-version/mycode -W -n python2-version/mycode diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index 1dfebc2040..bdc699f6b9 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -44,7 +44,9 @@ produces either the sum or the max:: print args.accumulate(args.integers) Assuming the Python code above is saved into a file called ``prog.py``, it can -be run at the command line and provides useful help messages:: +be run at the command line and provides useful help messages: + +.. code-block:: shell-session $ python prog.py -h usage: prog.py [-h] [--sum] N [N ...] @@ -59,7 +61,9 @@ be run at the command line and provides useful help messages:: --sum sum the integers (default: find the max) When run with the appropriate arguments, it prints either the sum or the max of -the command-line integers:: +the command-line integers: + +.. code-block:: shell-session $ python prog.py 1 2 3 4 4 @@ -67,7 +71,9 @@ the command-line integers:: $ python prog.py 1 2 3 4 --sum 10 -If invalid arguments are passed in, it will issue an error:: +If invalid arguments are passed in, it will issue an error: + +.. code-block:: shell-session $ python prog.py a b c usage: prog.py [-h] [--sum] N [N ...] @@ -187,7 +193,9 @@ invoked on the command line. For example, consider a file named args = parser.parse_args() The help for this program will display ``myprogram.py`` as the program name -(regardless of where the program was invoked from):: +(regardless of where the program was invoked from): + +.. code-block:: shell-session $ python myprogram.py --help usage: myprogram.py [-h] [--foo FOO] @@ -550,7 +558,9 @@ the parser's help message. For example, consider a file named args = parser.parse_args() If ``-h`` or ``--help`` is supplied at the command line, the ArgumentParser -help will be printed:: +help will be printed: + +.. code-block:: shell-session $ python myprogram.py --help usage: myprogram.py [-h] [--foo FOO] diff --git a/Doc/library/ast.rst b/Doc/library/ast.rst index cf0c32e463..6d5855b52b 100644 --- a/Doc/library/ast.rst +++ b/Doc/library/ast.rst @@ -113,6 +113,7 @@ Subversion revision number of the file shown below. The abstract grammar is currently defined as follows: .. literalinclude:: ../../Parser/Python.asdl + :language: none :mod:`ast` Helpers diff --git a/Doc/library/cgi.rst b/Doc/library/cgi.rst index da15e003b8..1bfdb39067 100644 --- a/Doc/library/cgi.rst +++ b/Doc/library/cgi.rst @@ -450,7 +450,9 @@ installing a copy of this module file (:file:`cgi.py`) as a CGI script. When invoked as a script, the file will dump its environment and the contents of the form in HTML form. Give it the right mode etc, and send it a request. If it's installed in the standard :file:`cgi-bin` directory, it should be possible to -send it a request by entering a URL into your browser of the form:: +send it a request by entering a URL into your browser of the form: + +.. code-block:: none http://yourhostname/cgi-bin/cgi.py?name=Joe+Blow&addr=At+Home @@ -542,4 +544,3 @@ Common problems and solutions field values should be supplied in, but knowing whether a request was received from a conforming browser, or even from a browser at all, is tedious and error-prone. - diff --git a/Doc/library/doctest.rst b/Doc/library/doctest.rst index 45581239fb..43be33ef9e 100644 --- a/Doc/library/doctest.rst +++ b/Doc/library/doctest.rst @@ -91,14 +91,18 @@ Here's a complete but small example module:: doctest.testmod() If you run :file:`example.py` directly from the command line, :mod:`doctest` -works its magic:: +works its magic: + +.. code-block:: shell-session $ python example.py $ There's no output! That's normal, and it means all the examples worked. Pass ``-v`` to the script, and :mod:`doctest` prints a detailed log of what -it's trying, and prints a summary at the end:: +it's trying, and prints a summary at the end: + +.. code-block:: shell-session $ python example.py -v Trying: @@ -117,7 +121,9 @@ it's trying, and prints a summary at the end:: [1, 1, 2, 6, 24, 120] ok -And so on, eventually ending with:: +And so on, eventually ending with: + +.. code-block:: none Trying: factorial(1e100) @@ -205,7 +211,9 @@ file. This can be done with the :func:`testfile` function:: That short script executes and verifies any interactive Python examples contained in the file :file:`example.txt`. The file content is treated as if it were a single giant docstring; the file doesn't need to contain a Python -program! For example, perhaps :file:`example.txt` contains this:: +program! For example, perhaps :file:`example.txt` contains this: + +.. code-block:: none The ``example`` module ====================== diff --git a/Doc/library/htmlparser.rst b/Doc/library/htmlparser.rst index e73ce07745..6740b43367 100644 --- a/Doc/library/htmlparser.rst +++ b/Doc/library/htmlparser.rst @@ -78,7 +78,9 @@ as they are encountered:: parser.feed('Test' '

Parse me!

') -The output will then be:: +The output will then be: + +.. code-block:: none Encountered a start tag: html Encountered a start tag: head diff --git a/Doc/library/idle.rst b/Doc/library/idle.rst index 84805ff21d..729ca6e89c 100644 --- a/Doc/library/idle.rst +++ b/Doc/library/idle.rst @@ -520,7 +520,7 @@ functions to be used from IDLE's Python shell. Command line usage ^^^^^^^^^^^^^^^^^^ -:: +.. code-block:: none idle.py [-c command] [-d] [-e] [-h] [-i] [-r file] [-s] [-t title] [-] [arg] ... diff --git a/Doc/library/logging.config.rst b/Doc/library/logging.config.rst index 5460c3ad45..23333ed688 100644 --- a/Doc/library/logging.config.rst +++ b/Doc/library/logging.config.rst @@ -209,7 +209,9 @@ otherwise, the context is used to determine what to instantiate. handler. All *other* keys are passed through as keyword arguments to the - handler's constructor. For example, given the snippet:: + handler's constructor. For example, given the snippet: + + .. code-block:: yaml handlers: console: @@ -318,7 +320,9 @@ it unambiguously, and then using the id in the source object's configuration to indicate that a connection exists between the source and the destination object with that id. -So, for example, consider the following YAML snippet:: +So, for example, consider the following YAML snippet: + +.. code-block:: yaml formatters: brief: @@ -375,7 +379,9 @@ to provide a 'factory' - a callable which is called with a configuration dictionary and which returns the instantiated object. This is signalled by an absolute import path to the factory being made available under the special key ``'()'``. Here's a concrete -example:: +example: + +.. code-block:: yaml formatters: brief: @@ -592,7 +598,9 @@ configuration must be specified in a section called ``[logger_root]``. :func:`dictConfig`, so it's worth considering transitioning to this newer API when it's convenient to do so. -Examples of these sections in the file are given below. :: +Examples of these sections in the file are given below. + +.. code-block:: ini [loggers] keys=root,log02,log03,log04,log05,log06,log07 @@ -604,7 +612,9 @@ Examples of these sections in the file are given below. :: keys=form01,form02,form03,form04,form05,form06,form07,form08,form09 The root logger must specify a level and a list of handlers. An example of a -root logger section is given below. :: +root logger section is given below. + +.. code-block:: ini [logger_root] level=NOTSET @@ -621,7 +631,9 @@ appear in the ``[handlers]`` section. These names must appear in the file. For loggers other than the root logger, some additional information is required. -This is illustrated by the following example. :: +This is illustrated by the following example. + +.. code-block:: ini [logger_parser] level=DEBUG @@ -639,7 +651,8 @@ indicate that messages are **not** propagated to handlers up the hierarchy. The say the name used by the application to get the logger. Sections which specify handler configuration are exemplified by the following. -:: + +.. code-block:: ini [handler_hand01] class=StreamHandler @@ -663,7 +676,9 @@ a corresponding section in the configuration file. The ``args`` entry, when :func:`eval`\ uated in the context of the ``logging`` package's namespace, is the list of arguments to the constructor for the handler class. Refer to the constructors for the relevant handlers, or to the examples -below, to see how typical entries are constructed. :: +below, to see how typical entries are constructed. + +.. code-block:: ini [handler_hand02] class=FileHandler @@ -714,7 +729,9 @@ below, to see how typical entries are constructed. :: formatter=form09 args=('localhost:9022', '/log', 'GET') -Sections which specify formatter configuration are typified by the following. :: +Sections which specify formatter configuration are typified by the following. + +.. code-block:: ini [formatter_form01] format=F1 %(asctime)s %(levelname)s %(message)s @@ -750,5 +767,3 @@ condensed format. Module :mod:`logging.handlers` Useful handlers included with the logging module. - - diff --git a/Doc/library/optparse.rst b/Doc/library/optparse.rst index c1ed15b0b6..54664622b5 100644 --- a/Doc/library/optparse.rst +++ b/Doc/library/optparse.rst @@ -680,7 +680,9 @@ automatically adds a ``--version`` option to your parser. If it encounters this option on the command line, it expands your ``version`` string (by replacing ``%prog``), prints it to stdout, and exits. -For example, if your script is called ``/usr/bin/foo``:: +For example, if your script is called ``/usr/bin/foo``: + +.. code-block:: shell-session $ /usr/bin/foo --version foo 1.0 @@ -730,14 +732,18 @@ program's usage message and an error message to standard error and exits with error status 2. Consider the first example above, where the user passes ``4x`` to an option -that takes an integer:: +that takes an integer: + +.. code-block:: shell-session $ /usr/bin/foo -n 4x Usage: foo [options] foo: error: option -n: invalid integer value: '4x' -Or, where the user fails to pass a value at all:: +Or, where the user fails to pass a value at all: + +.. code-block:: shell-session $ /usr/bin/foo -n Usage: foo [options] diff --git a/Doc/library/pyexpat.rst b/Doc/library/pyexpat.rst index bb0da9dc16..ffa042b7bc 100644 --- a/Doc/library/pyexpat.rst +++ b/Doc/library/pyexpat.rst @@ -87,7 +87,9 @@ The :mod:`xml.parsers.expat` module contains two functions: separator. For example, if *namespace_separator* is set to a space character (``' '``) and - the following document is parsed:: + the following document is parsed: + + .. code-block:: xml >> make_archive(archive_name, 'gztar', root_dir) '/Users/tarek/myarchive.tar.gz' -The resulting archive contains:: +The resulting archive contains: + +.. code-block:: shell-session $ tar -tzvf /Users/tarek/myarchive.tar.gz drwx------ tarek/staff 0 2010-02-01 16:23:40 ./ diff --git a/Doc/library/socketserver.rst b/Doc/library/socketserver.rst index a7c3e3e969..a81214e906 100644 --- a/Doc/library/socketserver.rst +++ b/Doc/library/socketserver.rst @@ -481,7 +481,9 @@ This is the client side:: The output of the example should look something like this: -Server:: +Server: + +.. code-block:: shell-session $ python TCPServer.py 127.0.0.1 wrote: @@ -489,7 +491,9 @@ Server:: 127.0.0.1 wrote: python is nice -Client:: +Client: + +.. code-block:: shell-session $ python TCPClient.py hello world with TCP Sent: hello world with TCP @@ -604,7 +608,9 @@ An example for the :class:`ThreadingMixIn` class:: server.server_close() -The output of the example should look something like this:: +The output of the example should look something like this: + +.. code-block:: shell-session $ python ThreadedTCPServer.py Server loop running in thread: Thread-1 diff --git a/Doc/library/subprocess.rst b/Doc/library/subprocess.rst index 86a42aed96..1bb3ac10cd 100644 --- a/Doc/library/subprocess.rst +++ b/Doc/library/subprocess.rst @@ -706,20 +706,23 @@ been imported from the :mod:`subprocess` module. Replacing /bin/sh shell backquote ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -:: +.. code-block:: bash output=`mycmd myarg` - # becomes - output = check_output(["mycmd", "myarg"]) +becomes:: + + output = check_output(["mycmd", "myarg"]) Replacing shell pipeline ^^^^^^^^^^^^^^^^^^^^^^^^ -:: +.. code-block:: bash output=`dmesg | grep hda` - # becomes + +becomes:: + p1 = Popen(["dmesg"], stdout=PIPE) p2 = Popen(["grep", "hda"], stdin=p1.stdout, stdout=PIPE) p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits. @@ -729,10 +732,14 @@ The p1.stdout.close() call after starting the p2 is important in order for p1 to receive a SIGPIPE if p2 exits before p1. Alternatively, for trusted input, the shell's own pipeline support may still -be used directly:: +be used directly: + +.. code-block:: bash output=`dmesg | grep hda` - # becomes + +becomes:: + output=check_output("dmesg | grep hda", shell=True) diff --git a/Doc/library/zipimport.rst b/Doc/library/zipimport.rst index 91305f6d52..e43f2a6a9b 100644 --- a/Doc/library/zipimport.rst +++ b/Doc/library/zipimport.rst @@ -149,7 +149,9 @@ Examples -------- Here is an example that imports a module from a ZIP archive - note that the -:mod:`zipimport` module is not explicitly used. :: +:mod:`zipimport` module is not explicitly used. + +.. code-block:: shell-session $ unzip -l example.zip Archive: example.zip diff --git a/Doc/reference/lexical_analysis.rst b/Doc/reference/lexical_analysis.rst index 94b003c5c4..9f69ef7c8d 100644 --- a/Doc/reference/lexical_analysis.rst +++ b/Doc/reference/lexical_analysis.rst @@ -715,7 +715,10 @@ Operators .. index:: single: operators -The following tokens are operators:: +The following tokens are operators: + +.. code-block:: none + + - * ** / // % << >> & | ^ ~ @@ -732,7 +735,9 @@ Delimiters .. index:: single: delimiters -The following tokens serve as delimiters in the grammar:: +The following tokens serve as delimiters in the grammar: + +.. code-block:: none ( ) [ ] { } @ , : . ` = ; @@ -745,14 +750,18 @@ of the list, the augmented assignment operators, serve lexically as delimiters, but also perform an operation. The following printing ASCII characters have special meaning as part of other -tokens or are otherwise significant to the lexical analyzer:: +tokens or are otherwise significant to the lexical analyzer: + +.. code-block:: none ' " # \ .. index:: single: ASCII@ASCII The following printing ASCII characters are not used in Python. Their -occurrence outside string literals and comments is an unconditional error:: +occurrence outside string literals and comments is an unconditional error: + +.. code-block:: none $ ? diff --git a/Doc/tutorial/controlflow.rst b/Doc/tutorial/controlflow.rst index 2af60d035e..e1ac89f5e2 100644 --- a/Doc/tutorial/controlflow.rst +++ b/Doc/tutorial/controlflow.rst @@ -473,7 +473,9 @@ It could be called like this:: client="John Cleese", sketch="Cheese Shop Sketch") -and of course it would print:: +and of course it would print: + +.. code-block:: none -- Do you have any Limburger ? -- I'm sorry, we're all out of Limburger diff --git a/Doc/tutorial/interpreter.rst b/Doc/tutorial/interpreter.rst index 5f375048f0..50e50c7701 100644 --- a/Doc/tutorial/interpreter.rst +++ b/Doc/tutorial/interpreter.rst @@ -93,7 +93,9 @@ mode*. In this mode it prompts for the next command with the *primary prompt*, usually three greater-than signs (``>>>``); for continuation lines it prompts with the *secondary prompt*, by default three dots (``...``). The interpreter prints a welcome message stating its version number and a copyright notice -before printing the first prompt:: +before printing the first prompt: + +.. code-block:: shell-session python Python 2.7 (#1, Feb 28 2010, 00:02:06) diff --git a/Doc/tutorial/modules.rst b/Doc/tutorial/modules.rst index 7b6fd9cfbe..0ef07a3c78 100644 --- a/Doc/tutorial/modules.rst +++ b/Doc/tutorial/modules.rst @@ -135,7 +135,9 @@ the end of your module:: you can make the file usable as a script as well as an importable module, because the code that parses the command line only runs if the module is -executed as the "main" file:: +executed as the "main" file: + +.. code-block:: shell-session $ python fibo.py 50 1 1 2 3 5 8 13 21 34 diff --git a/Doc/whatsnew/2.3.rst b/Doc/whatsnew/2.3.rst index 1d63663d68..9e52200e44 100644 --- a/Doc/whatsnew/2.3.rst +++ b/Doc/whatsnew/2.3.rst @@ -291,7 +291,9 @@ PEP 273: Importing Modules from ZIP Archives The new :mod:`zipimport` module adds support for importing modules from a ZIP- format archive. You don't need to import the module explicitly; it will be automatically imported if a ZIP archive's filename is added to ``sys.path``. -For example:: +For example: + +.. code-block:: shell-session amk@nyman:~/src/python$ unzip -l /tmp/example.zip Archive: /tmp/example.zip @@ -1761,7 +1763,9 @@ This returns an object containing all of the option values, and a list of strings containing the remaining arguments. Invoking the script with the various arguments now works as you'd expect it to. -Note that the length argument is automatically converted to an integer. :: +Note that the length argument is automatically converted to an integer. + +.. code-block:: shell-session $ ./python opt.py -i data arg1 @@ -1771,7 +1775,9 @@ Note that the length argument is automatically converted to an integer. :: [] $ -The help message is automatically generated for you:: +The help message is automatically generated for you: + +.. code-block:: shell-session $ ./python opt.py --help usage: opt.py [options] @@ -2078,4 +2084,3 @@ Michael Hudson, Chris Lambert, Detlef Lannert, Martin von Löwis, Andrew MacIntyre, Lalo Martins, Chad Netzer, Gustavo Niemeyer, Neal Norwitz, Hans Nowak, Chris Reedy, Francesco Ricciardi, Vinay Sajip, Neil Schemenauer, Roman Suzi, Jason Tishler, Just van Rossum. - diff --git a/Doc/whatsnew/2.4.rst b/Doc/whatsnew/2.4.rst index 5555e7dd47..6081000e53 100644 --- a/Doc/whatsnew/2.4.rst +++ b/Doc/whatsnew/2.4.rst @@ -1425,7 +1425,9 @@ specifying the :const:`doctest.REPORT_UDIFF` (unified diffs), print word Running the above function's tests with :const:`doctest.REPORT_UDIFF` specified, -you get the following output:: +you get the following output: + +.. code-block:: none ********************************************************************** File "t.py", line 15, in g diff --git a/Doc/whatsnew/2.7.rst b/Doc/whatsnew/2.7.rst index c391389f03..cd97a3caa9 100644 --- a/Doc/whatsnew/2.7.rst +++ b/Doc/whatsnew/2.7.rst @@ -2266,7 +2266,9 @@ There is an existing data type already used for this, written in pure Python could cause a segmentation fault by taking a :c:type:`PyCObject` from module A and somehow substituting it for the :c:type:`PyCObject` in module B. Capsules know their own name, -and getting the pointer requires providing the name:: +and getting the pointer requires providing the name: + +.. code-block:: c void *vtable; @@ -2705,4 +2707,3 @@ The author would like to thank the following people for offering suggestions, corrections and assistance with various drafts of this article: Nick Coghlan, Philip Jenvey, Ryan Lovett, R. David Murray, Hugh Secker-Walker. -