diff --git a/howto/logging-cookbook.po b/howto/logging-cookbook.po index 750a9b4553..324806f061 100644 --- a/howto/logging-cookbook.po +++ b/howto/logging-cookbook.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.10\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-10-26 16:47+0000\n" +"POT-Creation-Date: 2021-11-30 00:09+0000\n" "PO-Revision-Date: 2018-05-23 14:36+0000\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" @@ -271,11 +271,25 @@ msgid "" "use your alternative serialization." msgstr "" +#: ../../howto/logging-cookbook.rst:545 +msgid "Running a logging socket listener in production" +msgstr "" + #: ../../howto/logging-cookbook.rst:547 +msgid "" +"To run a logging listener in production, you may need to use a process-" +"management tool such as `Supervisor `_. `Here " +"`_ is a " +"Gist which provides the bare-bones files to run the above functionality " +"using Supervisor: you will need to change the `/path/to/` parts in the Gist " +"to reflect the actual paths you want to use." +msgstr "" + +#: ../../howto/logging-cookbook.rst:558 msgid "Adding contextual information to your logging output" msgstr "" -#: ../../howto/logging-cookbook.rst:549 +#: ../../howto/logging-cookbook.rst:560 msgid "" "Sometimes you want logging output to contain contextual information in " "addition to the parameters passed to the logging call. For example, in a " @@ -291,11 +305,11 @@ msgid "" "`Logger` instances becomes effectively unbounded." msgstr "" -#: ../../howto/logging-cookbook.rst:564 +#: ../../howto/logging-cookbook.rst:575 msgid "Using LoggerAdapters to impart contextual information" msgstr "" -#: ../../howto/logging-cookbook.rst:566 +#: ../../howto/logging-cookbook.rst:577 msgid "" "An easy way in which you can pass contextual information to be output along " "with logging event information is to use the :class:`LoggerAdapter` class. " @@ -306,7 +320,7 @@ msgid "" "types of instances interchangeably." msgstr "" -#: ../../howto/logging-cookbook.rst:574 +#: ../../howto/logging-cookbook.rst:585 msgid "" "When you create an instance of :class:`LoggerAdapter`, you pass it a :class:" "`Logger` instance and a dict-like object which contains your contextual " @@ -317,7 +331,7 @@ msgid "" "of :class:`LoggerAdapter`::" msgstr "" -#: ../../howto/logging-cookbook.rst:590 +#: ../../howto/logging-cookbook.rst:601 msgid "" "The :meth:`~LoggerAdapter.process` method of :class:`LoggerAdapter` is where " "the contextual information is added to the logging output. It's passed the " @@ -330,7 +344,7 @@ msgid "" "be silently overwritten." msgstr "" -#: ../../howto/logging-cookbook.rst:599 +#: ../../howto/logging-cookbook.rst:610 msgid "" "The advantage of using 'extra' is that the values in the dict-like object " "are merged into the :class:`LogRecord` instance's __dict__, allowing you to " @@ -341,21 +355,21 @@ msgid "" "`~LoggerAdapter.process` to do what you need. Here is a simple example::" msgstr "" -#: ../../howto/logging-cookbook.rst:615 +#: ../../howto/logging-cookbook.rst:626 msgid "which you can use like this::" msgstr "" -#: ../../howto/logging-cookbook.rst:620 +#: ../../howto/logging-cookbook.rst:631 msgid "" "Then any events that you log to the adapter will have the value of " "``some_conn_id`` prepended to the log messages." msgstr "" -#: ../../howto/logging-cookbook.rst:624 +#: ../../howto/logging-cookbook.rst:635 msgid "Using objects other than dicts to pass contextual information" msgstr "" -#: ../../howto/logging-cookbook.rst:626 +#: ../../howto/logging-cookbook.rst:637 msgid "" "You don't need to pass an actual dict to a :class:`LoggerAdapter` - you " "could pass an instance of a class which implements ``__getitem__`` and " @@ -364,11 +378,11 @@ msgid "" "would be constant)." msgstr "" -#: ../../howto/logging-cookbook.rst:635 +#: ../../howto/logging-cookbook.rst:646 msgid "Using Filters to impart contextual information" msgstr "" -#: ../../howto/logging-cookbook.rst:637 +#: ../../howto/logging-cookbook.rst:648 msgid "" "You can also add contextual information to log output using a user-defined :" "class:`Filter`. ``Filter`` instances are allowed to modify the " @@ -377,7 +391,7 @@ msgid "" "class:`Formatter`." msgstr "" -#: ../../howto/logging-cookbook.rst:642 +#: ../../howto/logging-cookbook.rst:653 msgid "" "For example in a web application, the request being processed (or at least, " "the interesting parts of it) can be stored in a threadlocal (:class:" @@ -389,15 +403,15 @@ msgid "" "an example script::" msgstr "" -#: ../../howto/logging-cookbook.rst:688 +#: ../../howto/logging-cookbook.rst:699 msgid "which, when run, produces something like:" msgstr "" -#: ../../howto/logging-cookbook.rst:709 +#: ../../howto/logging-cookbook.rst:720 msgid "Logging to a single file from multiple processes" msgstr "" -#: ../../howto/logging-cookbook.rst:711 +#: ../../howto/logging-cookbook.rst:722 msgid "" "Although logging is thread-safe, and logging to a single file from multiple " "threads in a single process *is* supported, logging to a single file from " @@ -413,7 +427,7 @@ msgid "" "you to adapt in your own applications." msgstr "" -#: ../../howto/logging-cookbook.rst:724 +#: ../../howto/logging-cookbook.rst:735 msgid "" "You could also write your own handler which uses the :class:" "`~multiprocessing.Lock` class from the :mod:`multiprocessing` module to " @@ -424,7 +438,7 @@ msgid "" "platforms (see https://bugs.python.org/issue3770)." msgstr "" -#: ../../howto/logging-cookbook.rst:734 +#: ../../howto/logging-cookbook.rst:745 msgid "" "Alternatively, you can use a ``Queue`` and a :class:`QueueHandler` to send " "all logging events to one of the processes in your multi-process " @@ -439,13 +453,13 @@ msgid "" "requirements::" msgstr "" -#: ../../howto/logging-cookbook.rst:850 +#: ../../howto/logging-cookbook.rst:861 msgid "" "A variant of the above script keeps the logging in the main process, in a " "separate thread::" msgstr "" -#: ../../howto/logging-cookbook.rst:945 +#: ../../howto/logging-cookbook.rst:956 msgid "" "This variant shows how you can e.g. apply configuration for particular " "loggers - e.g. the ``foo`` logger has a special handler which stores all " @@ -455,34 +469,50 @@ msgid "" "appropriate destinations." msgstr "" -#: ../../howto/logging-cookbook.rst:952 +#: ../../howto/logging-cookbook.rst:963 msgid "Using concurrent.futures.ProcessPoolExecutor" msgstr "" -#: ../../howto/logging-cookbook.rst:954 +#: ../../howto/logging-cookbook.rst:965 msgid "" "If you want to use :class:`concurrent.futures.ProcessPoolExecutor` to start " "your worker processes, you need to create the queue slightly differently. " "Instead of" msgstr "" -#: ../../howto/logging-cookbook.rst:962 +#: ../../howto/logging-cookbook.rst:973 msgid "you should use" msgstr "" -#: ../../howto/logging-cookbook.rst:968 +#: ../../howto/logging-cookbook.rst:979 msgid "and you can then replace the worker creation from this::" msgstr "" -#: ../../howto/logging-cookbook.rst:979 +#: ../../howto/logging-cookbook.rst:990 msgid "to this (remembering to first import :mod:`concurrent.futures`)::" msgstr "" -#: ../../howto/logging-cookbook.rst:987 +#: ../../howto/logging-cookbook.rst:997 +msgid "Deploying Web applications using Gunicorn and uWSGI" +msgstr "" + +#: ../../howto/logging-cookbook.rst:999 +msgid "" +"When deploying Web applications using `Gunicorn `_ or " +"`uWSGI `_ (or similar), " +"multiple worker processes are created to handle client requests. In such " +"environments, avoid creating file-based handlers directly in your web " +"application. Instead, use a :class:`SocketHandler` to log from the web " +"application to a listener in a separate process. This can be set up using a " +"process management tool such as Supervisor - see `Running a logging socket " +"listener in production`_ for more details." +msgstr "" + +#: ../../howto/logging-cookbook.rst:1009 msgid "Using file rotation" msgstr "" -#: ../../howto/logging-cookbook.rst:992 +#: ../../howto/logging-cookbook.rst:1014 msgid "" "Sometimes you want to let a log file grow to a certain size, then open a new " "file and log to that. You may want to keep a certain number of these files, " @@ -492,13 +522,13 @@ msgid "" "RotatingFileHandler`::" msgstr "" -#: ../../howto/logging-cookbook.rst:1024 +#: ../../howto/logging-cookbook.rst:1046 msgid "" "The result should be 6 separate files, each with part of the log history for " "the application:" msgstr "" -#: ../../howto/logging-cookbook.rst:1036 +#: ../../howto/logging-cookbook.rst:1058 msgid "" "The most current file is always :file:`logging_rotatingfile_example.out`, " "and each time it reaches the size limit it is renamed with the suffix " @@ -506,17 +536,17 @@ msgid "" "(``.1`` becomes ``.2``, etc.) and the ``.6`` file is erased." msgstr "" -#: ../../howto/logging-cookbook.rst:1041 +#: ../../howto/logging-cookbook.rst:1063 msgid "" "Obviously this example sets the log length much too small as an extreme " "example. You would want to set *maxBytes* to an appropriate value." msgstr "" -#: ../../howto/logging-cookbook.rst:1047 +#: ../../howto/logging-cookbook.rst:1069 msgid "Use of alternative formatting styles" msgstr "" -#: ../../howto/logging-cookbook.rst:1049 +#: ../../howto/logging-cookbook.rst:1071 msgid "" "When logging was added to the Python standard library, the only way of " "formatting messages with variable content was to use the %-formatting " @@ -525,7 +555,7 @@ msgid "" "Python 2.6)." msgstr "" -#: ../../howto/logging-cookbook.rst:1055 +#: ../../howto/logging-cookbook.rst:1077 msgid "" "Logging (as of 3.2) provides improved support for these two additional " "formatting styles. The :class:`Formatter` class been enhanced to take an " @@ -538,14 +568,14 @@ msgid "" "session to show the possibilities:" msgstr "" -#: ../../howto/logging-cookbook.rst:1089 +#: ../../howto/logging-cookbook.rst:1111 msgid "" "Note that the formatting of logging messages for final output to logs is " "completely independent of how an individual logging message is constructed. " "That can still use %-formatting, as shown here::" msgstr "" -#: ../../howto/logging-cookbook.rst:1097 +#: ../../howto/logging-cookbook.rst:1119 msgid "" "Logging calls (``logger.debug()``, ``logger.info()`` etc.) only take " "positional parameters for the actual logging message itself, with keyword " @@ -561,7 +591,7 @@ msgid "" "strings." msgstr "" -#: ../../howto/logging-cookbook.rst:1110 +#: ../../howto/logging-cookbook.rst:1132 msgid "" "There is, however, a way that you can use {}- and $- formatting to construct " "your individual log messages. Recall that for a message you can use an " @@ -570,7 +600,7 @@ msgid "" "the following two classes::" msgstr "" -#: ../../howto/logging-cookbook.rst:1134 +#: ../../howto/logging-cookbook.rst:1156 msgid "" "Either of these can be used in place of a format string, to allow {}- or $-" "formatting to be used to build the actual \"message\" part which appears in " @@ -581,21 +611,21 @@ msgid "" "used as a synonym/alias for :func:`gettext.gettext` or its brethren)." msgstr "" -#: ../../howto/logging-cookbook.rst:1142 +#: ../../howto/logging-cookbook.rst:1164 msgid "" "The above classes are not included in Python, though they're easy enough to " "copy and paste into your own code. They can be used as follows (assuming " "that they're declared in a module called ``wherever``):" msgstr "" -#: ../../howto/logging-cookbook.rst:1164 +#: ../../howto/logging-cookbook.rst:1186 msgid "" "While the above examples use ``print()`` to show how the formatting works, " "you would of course use ``logger.debug()`` or similar to actually log using " "this approach." msgstr "" -#: ../../howto/logging-cookbook.rst:1168 +#: ../../howto/logging-cookbook.rst:1190 msgid "" "One thing to note is that you pay no significant performance penalty with " "this approach: the actual formatting happens not when you make the logging " @@ -606,23 +636,23 @@ msgid "" "sugar for a constructor call to one of the XXXMessage classes." msgstr "" -#: ../../howto/logging-cookbook.rst:1176 +#: ../../howto/logging-cookbook.rst:1198 msgid "" "If you prefer, you can use a :class:`LoggerAdapter` to achieve a similar " "effect to the above, as in the following example::" msgstr "" -#: ../../howto/logging-cookbook.rst:1207 +#: ../../howto/logging-cookbook.rst:1229 msgid "" "The above script should log the message ``Hello, world!`` when run with " "Python 3.2 or later." msgstr "" -#: ../../howto/logging-cookbook.rst:1216 +#: ../../howto/logging-cookbook.rst:1238 msgid "Customizing ``LogRecord``" msgstr "" -#: ../../howto/logging-cookbook.rst:1218 +#: ../../howto/logging-cookbook.rst:1240 msgid "" "Every logging event is represented by a :class:`LogRecord` instance. When an " "event is logged and not filtered out by a logger's level, a :class:" @@ -633,13 +663,13 @@ msgid "" "was done:" msgstr "" -#: ../../howto/logging-cookbook.rst:1225 +#: ../../howto/logging-cookbook.rst:1247 msgid "" ":meth:`Logger.makeRecord`, which is called in the normal process of logging " "an event. This invoked :class:`LogRecord` directly to create an instance." msgstr "" -#: ../../howto/logging-cookbook.rst:1228 +#: ../../howto/logging-cookbook.rst:1250 msgid "" ":func:`makeLogRecord`, which is called with a dictionary containing " "attributes to be added to the LogRecord. This is typically invoked when a " @@ -648,27 +678,27 @@ msgid "" "`~handlers.HTTPHandler`)." msgstr "" -#: ../../howto/logging-cookbook.rst:1234 +#: ../../howto/logging-cookbook.rst:1256 msgid "" "This has usually meant that if you need to do anything special with a :class:" "`LogRecord`, you've had to do one of the following." msgstr "" -#: ../../howto/logging-cookbook.rst:1237 +#: ../../howto/logging-cookbook.rst:1259 msgid "" "Create your own :class:`Logger` subclass, which overrides :meth:`Logger." "makeRecord`, and set it using :func:`~logging.setLoggerClass` before any " "loggers that you care about are instantiated." msgstr "" -#: ../../howto/logging-cookbook.rst:1240 +#: ../../howto/logging-cookbook.rst:1262 msgid "" "Add a :class:`Filter` to a logger or handler, which does the necessary " "special manipulation you need when its :meth:`~Filter.filter` method is " "called." msgstr "" -#: ../../howto/logging-cookbook.rst:1244 +#: ../../howto/logging-cookbook.rst:1266 msgid "" "The first approach would be a little unwieldy in the scenario where (say) " "several different libraries wanted to do different things. Each would " @@ -676,7 +706,7 @@ msgid "" "last would win." msgstr "" -#: ../../howto/logging-cookbook.rst:1249 +#: ../../howto/logging-cookbook.rst:1271 msgid "" "The second approach works reasonably well for many cases, but does not allow " "you to e.g. use a specialized subclass of :class:`LogRecord`. Library " @@ -685,7 +715,7 @@ msgid "" "would do simply by adding new packages or modules and doing ::" msgstr "" -#: ../../howto/logging-cookbook.rst:1257 +#: ../../howto/logging-cookbook.rst:1279 msgid "" "at module level). It's probably one too many things to think about. " "Developers could also add the filter to a :class:`~logging.NullHandler` " @@ -695,7 +725,7 @@ msgid "" "developer." msgstr "" -#: ../../howto/logging-cookbook.rst:1263 +#: ../../howto/logging-cookbook.rst:1285 msgid "" "In Python 3.2 and later, :class:`~logging.LogRecord` creation is done " "through a factory, which you can specify. The factory is just a callable you " @@ -705,7 +735,7 @@ msgid "" "`LogRecord` is the default setting for the factory." msgstr "" -#: ../../howto/logging-cookbook.rst:1270 +#: ../../howto/logging-cookbook.rst:1292 msgid "" "This approach allows a custom factory to control all aspects of LogRecord " "creation. For example, you could return a subclass, or just add some " @@ -713,7 +743,7 @@ msgid "" "this::" msgstr "" -#: ../../howto/logging-cookbook.rst:1283 +#: ../../howto/logging-cookbook.rst:1305 msgid "" "This pattern allows different libraries to chain factories together, and as " "long as they don't overwrite each other's attributes or unintentionally " @@ -723,70 +753,70 @@ msgid "" "used when the use of a :class:`Filter` does not provide the desired result." msgstr "" -#: ../../howto/logging-cookbook.rst:1294 +#: ../../howto/logging-cookbook.rst:1316 msgid "Subclassing QueueHandler - a ZeroMQ example" msgstr "" -#: ../../howto/logging-cookbook.rst:1296 +#: ../../howto/logging-cookbook.rst:1318 msgid "" "You can use a :class:`QueueHandler` subclass to send messages to other kinds " "of queues, for example a ZeroMQ 'publish' socket. In the example below,the " "socket is created separately and passed to the handler (as its 'queue')::" msgstr "" -#: ../../howto/logging-cookbook.rst:1315 +#: ../../howto/logging-cookbook.rst:1337 msgid "" "Of course there are other ways of organizing this, for example passing in " "the data needed by the handler to create the socket::" msgstr "" -#: ../../howto/logging-cookbook.rst:1333 +#: ../../howto/logging-cookbook.rst:1355 msgid "Subclassing QueueListener - a ZeroMQ example" msgstr "" -#: ../../howto/logging-cookbook.rst:1335 +#: ../../howto/logging-cookbook.rst:1357 msgid "" "You can also subclass :class:`QueueListener` to get messages from other " "kinds of queues, for example a ZeroMQ 'subscribe' socket. Here's an example::" msgstr "" -#: ../../howto/logging-cookbook.rst:1354 +#: ../../howto/logging-cookbook.rst:1376 msgid "Module :mod:`logging`" msgstr ":mod:`logging` 模組" -#: ../../howto/logging-cookbook.rst:1354 +#: ../../howto/logging-cookbook.rst:1376 msgid "API reference for the logging module." msgstr "" -#: ../../howto/logging-cookbook.rst:1357 +#: ../../howto/logging-cookbook.rst:1379 msgid "Module :mod:`logging.config`" msgstr ":mod:`logging.config` 模組" -#: ../../howto/logging-cookbook.rst:1357 +#: ../../howto/logging-cookbook.rst:1379 msgid "Configuration API for the logging module." msgstr "" -#: ../../howto/logging-cookbook.rst:1360 +#: ../../howto/logging-cookbook.rst:1382 msgid "Module :mod:`logging.handlers`" msgstr ":mod:`logging.handlers` 模組" -#: ../../howto/logging-cookbook.rst:1360 +#: ../../howto/logging-cookbook.rst:1382 msgid "Useful handlers included with the logging module." msgstr "" -#: ../../howto/logging-cookbook.rst:1362 +#: ../../howto/logging-cookbook.rst:1384 msgid ":ref:`A basic logging tutorial `" msgstr "" -#: ../../howto/logging-cookbook.rst:1364 +#: ../../howto/logging-cookbook.rst:1386 msgid ":ref:`A more advanced logging tutorial `" msgstr "" -#: ../../howto/logging-cookbook.rst:1368 +#: ../../howto/logging-cookbook.rst:1390 msgid "An example dictionary-based configuration" msgstr "" -#: ../../howto/logging-cookbook.rst:1370 +#: ../../howto/logging-cookbook.rst:1392 msgid "" "Below is an example of a logging configuration dictionary - it's taken from " "the `documentation on the Django project `_ of the Django documentation." msgstr "" -#: ../../howto/logging-cookbook.rst:1433 +#: ../../howto/logging-cookbook.rst:1455 msgid "Using a rotator and namer to customize log rotation processing" msgstr "" -#: ../../howto/logging-cookbook.rst:1435 +#: ../../howto/logging-cookbook.rst:1457 msgid "" "An example of how you can define a namer and rotator is given in the " "following snippet, which shows zlib-based compression of the log file::" msgstr "" -#: ../../howto/logging-cookbook.rst:1453 +#: ../../howto/logging-cookbook.rst:1475 msgid "" "These are not \"true\" .gz files, as they are bare compressed data, with no " "\"container\" such as you’d find in an actual gzip file. This snippet is " "just for illustration purposes." msgstr "" -#: ../../howto/logging-cookbook.rst:1458 +#: ../../howto/logging-cookbook.rst:1480 msgid "A more elaborate multiprocessing example" msgstr "" -#: ../../howto/logging-cookbook.rst:1460 +#: ../../howto/logging-cookbook.rst:1482 msgid "" "The following working example shows how logging can be used with " "multiprocessing using configuration files. The configurations are fairly " @@ -830,7 +860,7 @@ msgid "" "in a real multiprocessing scenario." msgstr "" -#: ../../howto/logging-cookbook.rst:1465 +#: ../../howto/logging-cookbook.rst:1487 msgid "" "In the example, the main process spawns a listener process and some worker " "processes. Each of the main process, the listener and the workers have three " @@ -843,17 +873,17 @@ msgid "" "own scenario." msgstr "" -#: ../../howto/logging-cookbook.rst:1475 +#: ../../howto/logging-cookbook.rst:1497 msgid "" "Here's the script - the docstrings and the comments hopefully explain how it " "works::" msgstr "" -#: ../../howto/logging-cookbook.rst:1687 +#: ../../howto/logging-cookbook.rst:1709 msgid "Inserting a BOM into messages sent to a SysLogHandler" msgstr "" -#: ../../howto/logging-cookbook.rst:1689 +#: ../../howto/logging-cookbook.rst:1711 msgid "" ":rfc:`5424` requires that a Unicode message be sent to a syslog daemon as a " "set of bytes which have the following structure: an optional pure-ASCII " @@ -862,7 +892,7 @@ msgid "" "<5424#section-6>`.)" msgstr "" -#: ../../howto/logging-cookbook.rst:1695 +#: ../../howto/logging-cookbook.rst:1717 msgid "" "In Python 3.1, code was added to :class:`~logging.handlers.SysLogHandler` to " "insert a BOM into the message, but unfortunately, it was implemented " @@ -870,7 +900,7 @@ msgid "" "hence not allowing any pure-ASCII component to appear before it." msgstr "" -#: ../../howto/logging-cookbook.rst:1701 +#: ../../howto/logging-cookbook.rst:1723 msgid "" "As this behaviour is broken, the incorrect BOM insertion code is being " "removed from Python 3.2.4 and later. However, it is not being replaced, and " @@ -879,33 +909,33 @@ msgid "" "encoded using UTF-8, then you need to do the following:" msgstr "" -#: ../../howto/logging-cookbook.rst:1707 +#: ../../howto/logging-cookbook.rst:1729 msgid "" "Attach a :class:`~logging.Formatter` instance to your :class:`~logging." "handlers.SysLogHandler` instance, with a format string such as::" msgstr "" -#: ../../howto/logging-cookbook.rst:1713 +#: ../../howto/logging-cookbook.rst:1735 msgid "" "The Unicode code point U+FEFF, when encoded using UTF-8, will be encoded as " "a UTF-8 BOM -- the byte-string ``b'\\xef\\xbb\\xbf'``." msgstr "" -#: ../../howto/logging-cookbook.rst:1716 +#: ../../howto/logging-cookbook.rst:1738 msgid "" "Replace the ASCII section with whatever placeholders you like, but make sure " "that the data that appears in there after substitution is always ASCII (that " "way, it will remain unchanged after UTF-8 encoding)." msgstr "" -#: ../../howto/logging-cookbook.rst:1720 +#: ../../howto/logging-cookbook.rst:1742 msgid "" "Replace the Unicode section with whatever placeholders you like; if the data " "which appears there after substitution contains characters outside the ASCII " "range, that's fine -- it will be encoded using UTF-8." msgstr "" -#: ../../howto/logging-cookbook.rst:1724 +#: ../../howto/logging-cookbook.rst:1746 msgid "" "The formatted message *will* be encoded using UTF-8 encoding by " "``SysLogHandler``. If you follow the above rules, you should be able to " @@ -914,11 +944,11 @@ msgid "" "daemon may complain." msgstr "" -#: ../../howto/logging-cookbook.rst:1731 +#: ../../howto/logging-cookbook.rst:1753 msgid "Implementing structured logging" msgstr "" -#: ../../howto/logging-cookbook.rst:1733 +#: ../../howto/logging-cookbook.rst:1755 msgid "" "Although most logging messages are intended for reading by humans, and thus " "not readily machine-parseable, there might be circumstances where you want " @@ -930,31 +960,31 @@ msgid "" "machine-parseable manner::" msgstr "" -#: ../../howto/logging-cookbook.rst:1757 +#: ../../howto/logging-cookbook.rst:1779 msgid "If the above script is run, it prints:" msgstr "" -#: ../../howto/logging-cookbook.rst:1763 ../../howto/logging-cookbook.rst:1812 +#: ../../howto/logging-cookbook.rst:1785 ../../howto/logging-cookbook.rst:1834 msgid "" "Note that the order of items might be different according to the version of " "Python used." msgstr "" -#: ../../howto/logging-cookbook.rst:1766 +#: ../../howto/logging-cookbook.rst:1788 msgid "" "If you need more specialised processing, you can use a custom JSON encoder, " "as in the following complete example::" msgstr "" -#: ../../howto/logging-cookbook.rst:1806 +#: ../../howto/logging-cookbook.rst:1828 msgid "When the above script is run, it prints:" msgstr "" -#: ../../howto/logging-cookbook.rst:1821 +#: ../../howto/logging-cookbook.rst:1843 msgid "Customizing handlers with :func:`dictConfig`" msgstr "" -#: ../../howto/logging-cookbook.rst:1823 +#: ../../howto/logging-cookbook.rst:1845 msgid "" "There are times when you want to customize logging handlers in particular " "ways, and if you use :func:`dictConfig` you may be able to do this without " @@ -964,24 +994,24 @@ msgid "" "customize handler creation using a plain function such as::" msgstr "" -#: ../../howto/logging-cookbook.rst:1837 +#: ../../howto/logging-cookbook.rst:1859 msgid "" "You can then specify, in a logging configuration passed to :func:" "`dictConfig`, that a logging handler be created by calling this function::" msgstr "" -#: ../../howto/logging-cookbook.rst:1870 +#: ../../howto/logging-cookbook.rst:1892 msgid "" "In this example I am setting the ownership using the ``pulse`` user and " "group, just for the purposes of illustration. Putting it together into a " "working script, ``chowntest.py``::" msgstr "" -#: ../../howto/logging-cookbook.rst:1917 +#: ../../howto/logging-cookbook.rst:1939 msgid "To run this, you will probably need to run as ``root``:" msgstr "" -#: ../../howto/logging-cookbook.rst:1927 +#: ../../howto/logging-cookbook.rst:1949 msgid "" "Note that this example uses Python 3.3 because that's where :func:`shutil." "chown` makes an appearance. This approach should work with any Python " @@ -990,17 +1020,17 @@ msgid "" "change using e.g. :func:`os.chown`." msgstr "" -#: ../../howto/logging-cookbook.rst:1933 +#: ../../howto/logging-cookbook.rst:1955 msgid "" "In practice, the handler-creating function may be in a utility module " "somewhere in your project. Instead of the line in the configuration::" msgstr "" -#: ../../howto/logging-cookbook.rst:1938 +#: ../../howto/logging-cookbook.rst:1960 msgid "you could use e.g.::" msgstr "" -#: ../../howto/logging-cookbook.rst:1942 +#: ../../howto/logging-cookbook.rst:1964 msgid "" "where ``project.util`` can be replaced with the actual name of the package " "where the function resides. In the above working script, using ``'ext://" @@ -1008,25 +1038,25 @@ msgid "" "resolved by :func:`dictConfig` from the ``ext://`` specification." msgstr "" -#: ../../howto/logging-cookbook.rst:1947 +#: ../../howto/logging-cookbook.rst:1969 msgid "" "This example hopefully also points the way to how you could implement other " "types of file change - e.g. setting specific POSIX permission bits - in the " "same way, using :func:`os.chmod`." msgstr "" -#: ../../howto/logging-cookbook.rst:1951 +#: ../../howto/logging-cookbook.rst:1973 msgid "" "Of course, the approach could also be extended to types of handler other " "than a :class:`~logging.FileHandler` - for example, one of the rotating file " "handlers, or a different type of handler altogether." msgstr "" -#: ../../howto/logging-cookbook.rst:1961 +#: ../../howto/logging-cookbook.rst:1983 msgid "Using particular formatting styles throughout your application" msgstr "" -#: ../../howto/logging-cookbook.rst:1963 +#: ../../howto/logging-cookbook.rst:1985 msgid "" "In Python 3.2, the :class:`~logging.Formatter` gained a ``style`` keyword " "parameter which, while defaulting to ``%`` for backward compatibility, " @@ -1037,7 +1067,7 @@ msgid "" "is constructed." msgstr "" -#: ../../howto/logging-cookbook.rst:1970 +#: ../../howto/logging-cookbook.rst:1992 msgid "" "Logging calls (:meth:`~Logger.debug`, :meth:`~Logger.info` etc.) only take " "positional parameters for the actual logging message itself, with keyword " @@ -1052,7 +1082,7 @@ msgid "" "calls which are out there in existing code will be using %-format strings." msgstr "" -#: ../../howto/logging-cookbook.rst:1982 +#: ../../howto/logging-cookbook.rst:2004 msgid "" "There have been suggestions to associate format styles with specific " "loggers, but that approach also runs into backward compatibility problems " @@ -1060,7 +1090,7 @@ msgid "" "formatting." msgstr "" -#: ../../howto/logging-cookbook.rst:1986 +#: ../../howto/logging-cookbook.rst:2008 msgid "" "For logging to work interoperably between any third-party libraries and your " "code, decisions about formatting need to be made at the level of the " @@ -1068,11 +1098,11 @@ msgid "" "formatting styles can be accommodated." msgstr "" -#: ../../howto/logging-cookbook.rst:1993 +#: ../../howto/logging-cookbook.rst:2015 msgid "Using LogRecord factories" msgstr "" -#: ../../howto/logging-cookbook.rst:1995 +#: ../../howto/logging-cookbook.rst:2017 msgid "" "In Python 3.2, along with the :class:`~logging.Formatter` changes mentioned " "above, the logging package gained the ability to allow users to set their " @@ -1087,17 +1117,17 @@ msgid "" "implementation does." msgstr "" -#: ../../howto/logging-cookbook.rst:2006 +#: ../../howto/logging-cookbook.rst:2028 msgid "" "Refer to the reference documentation on :func:`setLogRecordFactory` and :" "class:`LogRecord` for more information." msgstr "" -#: ../../howto/logging-cookbook.rst:2011 +#: ../../howto/logging-cookbook.rst:2033 msgid "Using custom message objects" msgstr "" -#: ../../howto/logging-cookbook.rst:2013 +#: ../../howto/logging-cookbook.rst:2035 msgid "" "There is another, perhaps simpler way that you can use {}- and $- formatting " "to construct your individual log messages. You may recall (from :ref:" @@ -1107,7 +1137,7 @@ msgid "" "following two classes::" msgstr "" -#: ../../howto/logging-cookbook.rst:2038 +#: ../../howto/logging-cookbook.rst:2060 msgid "" "Either of these can be used in place of a format string, to allow {}- or $-" "formatting to be used to build the actual \"message\" part which appears in " @@ -1118,17 +1148,17 @@ msgid "" "using ``_`` for localization)." msgstr "" -#: ../../howto/logging-cookbook.rst:2046 +#: ../../howto/logging-cookbook.rst:2068 msgid "" "Examples of this approach are given below. Firstly, formatting with :meth:" "`str.format`::" msgstr "" -#: ../../howto/logging-cookbook.rst:2060 +#: ../../howto/logging-cookbook.rst:2082 msgid "Secondly, formatting with :class:`string.Template`::" msgstr "" -#: ../../howto/logging-cookbook.rst:2067 +#: ../../howto/logging-cookbook.rst:2089 msgid "" "One thing to note is that you pay no significant performance penalty with " "this approach: the actual formatting happens not when you make the logging " @@ -1140,11 +1170,11 @@ msgid "" "above." msgstr "" -#: ../../howto/logging-cookbook.rst:2081 +#: ../../howto/logging-cookbook.rst:2103 msgid "Configuring filters with :func:`dictConfig`" msgstr "" -#: ../../howto/logging-cookbook.rst:2083 +#: ../../howto/logging-cookbook.rst:2105 msgid "" "You *can* configure filters using :func:`~logging.config.dictConfig`, though " "it might not be obvious at first glance how to do it (hence this recipe). " @@ -1159,22 +1189,22 @@ msgid "" "complete example::" msgstr "" -#: ../../howto/logging-cookbook.rst:2136 +#: ../../howto/logging-cookbook.rst:2158 msgid "" "This example shows how you can pass configuration data to the callable which " "constructs the instance, in the form of keyword parameters. When run, the " "above script will print:" msgstr "" -#: ../../howto/logging-cookbook.rst:2144 +#: ../../howto/logging-cookbook.rst:2166 msgid "which shows that the filter is working as configured." msgstr "" -#: ../../howto/logging-cookbook.rst:2146 +#: ../../howto/logging-cookbook.rst:2168 msgid "A couple of extra points to note:" msgstr "" -#: ../../howto/logging-cookbook.rst:2148 +#: ../../howto/logging-cookbook.rst:2170 msgid "" "If you can't refer to the callable directly in the configuration (e.g. if it " "lives in a different module, and you can't import it directly where the " @@ -1184,7 +1214,7 @@ msgid "" "the above example." msgstr "" -#: ../../howto/logging-cookbook.rst:2155 +#: ../../howto/logging-cookbook.rst:2177 msgid "" "As well as for filters, this technique can also be used to configure custom " "handlers and formatters. See :ref:`logging-config-dict-userdef` for more " @@ -1193,11 +1223,11 @@ msgid "" "above." msgstr "" -#: ../../howto/logging-cookbook.rst:2164 +#: ../../howto/logging-cookbook.rst:2186 msgid "Customized exception formatting" msgstr "" -#: ../../howto/logging-cookbook.rst:2166 +#: ../../howto/logging-cookbook.rst:2188 msgid "" "There might be times when you want to do customized exception formatting - " "for argument's sake, let's say you want exactly one line per logged event, " @@ -1205,22 +1235,22 @@ msgid "" "formatter class, as shown in the following example::" msgstr "" -#: ../../howto/logging-cookbook.rst:2207 +#: ../../howto/logging-cookbook.rst:2229 msgid "When run, this produces a file with exactly two lines:" msgstr "" -#: ../../howto/logging-cookbook.rst:2214 +#: ../../howto/logging-cookbook.rst:2236 msgid "" "While the above treatment is simplistic, it points the way to how exception " "information can be formatted to your liking. The :mod:`traceback` module may " "be helpful for more specialized needs." msgstr "" -#: ../../howto/logging-cookbook.rst:2221 +#: ../../howto/logging-cookbook.rst:2243 msgid "Speaking logging messages" msgstr "" -#: ../../howto/logging-cookbook.rst:2223 +#: ../../howto/logging-cookbook.rst:2245 msgid "" "There might be situations when it is desirable to have logging messages " "rendered in an audible rather than a visible format. This is easy to do if " @@ -1237,24 +1267,24 @@ msgid "" "approach, which assumes that the ``espeak`` TTS package is available::" msgstr "" -#: ../../howto/logging-cookbook.rst:2265 +#: ../../howto/logging-cookbook.rst:2287 msgid "" "When run, this script should say \"Hello\" and then \"Goodbye\" in a female " "voice." msgstr "" -#: ../../howto/logging-cookbook.rst:2267 +#: ../../howto/logging-cookbook.rst:2289 msgid "" "The above approach can, of course, be adapted to other TTS systems and even " "other systems altogether which can process messages via external programs " "run from a command line." msgstr "" -#: ../../howto/logging-cookbook.rst:2275 +#: ../../howto/logging-cookbook.rst:2297 msgid "Buffering logging messages and outputting them conditionally" msgstr "" -#: ../../howto/logging-cookbook.rst:2277 +#: ../../howto/logging-cookbook.rst:2299 msgid "" "There might be situations where you want to log messages in a temporary area " "and only output them if a certain condition occurs. For example, you may " @@ -1264,7 +1294,7 @@ msgid "" "debug information to be output as well as the error." msgstr "" -#: ../../howto/logging-cookbook.rst:2284 +#: ../../howto/logging-cookbook.rst:2306 msgid "" "Here is an example which shows how you could do this using a decorator for " "your functions where you want logging to behave this way. It makes use of " @@ -1277,7 +1307,7 @@ msgid "" "subclass of ``MemoryHandler`` if you want custom flushing behavior." msgstr "" -#: ../../howto/logging-cookbook.rst:2294 +#: ../../howto/logging-cookbook.rst:2316 msgid "" "The example script has a simple function, ``foo``, which just cycles through " "all the logging levels, writing to ``sys.stderr`` to say what level it's " @@ -1286,7 +1316,7 @@ msgid "" "levels - otherwise, it only logs at DEBUG, INFO and WARNING levels." msgstr "" -#: ../../howto/logging-cookbook.rst:2300 +#: ../../howto/logging-cookbook.rst:2322 msgid "" "The script just arranges to decorate ``foo`` with a decorator which will do " "the conditional logging that's required. The decorator takes a logger as a " @@ -1298,36 +1328,36 @@ msgid "" "respectively." msgstr "" -#: ../../howto/logging-cookbook.rst:2308 +#: ../../howto/logging-cookbook.rst:2330 msgid "Here's the script::" msgstr "" -#: ../../howto/logging-cookbook.rst:2371 +#: ../../howto/logging-cookbook.rst:2393 msgid "When this script is run, the following output should be observed:" msgstr "" -#: ../../howto/logging-cookbook.rst:2401 +#: ../../howto/logging-cookbook.rst:2423 msgid "" "As you can see, actual logging output only occurs when an event is logged " "whose severity is ERROR or greater, but in that case, any previous events at " "lower severities are also logged." msgstr "" -#: ../../howto/logging-cookbook.rst:2405 +#: ../../howto/logging-cookbook.rst:2427 msgid "You can of course use the conventional means of decoration::" msgstr "" -#: ../../howto/logging-cookbook.rst:2415 +#: ../../howto/logging-cookbook.rst:2437 msgid "Formatting times using UTC (GMT) via configuration" msgstr "" -#: ../../howto/logging-cookbook.rst:2417 +#: ../../howto/logging-cookbook.rst:2439 msgid "" "Sometimes you want to format times using UTC, which can be done using a " "class such as `UTCFormatter`, shown below::" msgstr "" -#: ../../howto/logging-cookbook.rst:2426 +#: ../../howto/logging-cookbook.rst:2448 msgid "" "and you can then use the ``UTCFormatter`` in your code instead of :class:" "`~logging.Formatter`. If you want to do that via configuration, you can use " @@ -1335,21 +1365,21 @@ msgid "" "the following complete example::" msgstr "" -#: ../../howto/logging-cookbook.rst:2469 +#: ../../howto/logging-cookbook.rst:2491 msgid "When this script is run, it should print something like:" msgstr "" -#: ../../howto/logging-cookbook.rst:2476 +#: ../../howto/logging-cookbook.rst:2498 msgid "" "showing how the time is formatted both as local time and UTC, one for each " "handler." msgstr "" -#: ../../howto/logging-cookbook.rst:2483 +#: ../../howto/logging-cookbook.rst:2505 msgid "Using a context manager for selective logging" msgstr "" -#: ../../howto/logging-cookbook.rst:2485 +#: ../../howto/logging-cookbook.rst:2507 msgid "" "There are times when it would be useful to temporarily change the logging " "configuration and revert it back after doing something. For this, a context " @@ -1359,7 +1389,7 @@ msgid "" "scope of the context manager::" msgstr "" -#: ../../howto/logging-cookbook.rst:2518 +#: ../../howto/logging-cookbook.rst:2540 msgid "" "If you specify a level value, the logger's level is set to that value in the " "scope of the with block covered by the context manager. If you specify a " @@ -1368,13 +1398,13 @@ msgid "" "block exit - you could do this if you don't need the handler any more." msgstr "" -#: ../../howto/logging-cookbook.rst:2524 +#: ../../howto/logging-cookbook.rst:2546 msgid "" "To illustrate how it works, we can add the following block of code to the " "above::" msgstr "" -#: ../../howto/logging-cookbook.rst:2542 +#: ../../howto/logging-cookbook.rst:2564 msgid "" "We initially set the logger's level to ``INFO``, so message #1 appears and " "message #2 doesn't. We then change the level to ``DEBUG`` temporarily in the " @@ -1387,56 +1417,56 @@ msgid "" "(like message #1) whereas message #7 doesn't (just like message #2)." msgstr "" -#: ../../howto/logging-cookbook.rst:2552 +#: ../../howto/logging-cookbook.rst:2574 msgid "If we run the resulting script, the result is as follows:" msgstr "" -#: ../../howto/logging-cookbook.rst:2563 +#: ../../howto/logging-cookbook.rst:2585 msgid "" "If we run it again, but pipe ``stderr`` to ``/dev/null``, we see the " "following, which is the only message written to ``stdout``:" msgstr "" -#: ../../howto/logging-cookbook.rst:2571 +#: ../../howto/logging-cookbook.rst:2593 msgid "Once again, but piping ``stdout`` to ``/dev/null``, we get:" msgstr "" -#: ../../howto/logging-cookbook.rst:2581 +#: ../../howto/logging-cookbook.rst:2603 msgid "" "In this case, the message #5 printed to ``stdout`` doesn't appear, as " "expected." msgstr "" -#: ../../howto/logging-cookbook.rst:2583 +#: ../../howto/logging-cookbook.rst:2605 msgid "" "Of course, the approach described here can be generalised, for example to " "attach logging filters temporarily. Note that the above code works in Python " "2 as well as Python 3." msgstr "" -#: ../../howto/logging-cookbook.rst:2591 +#: ../../howto/logging-cookbook.rst:2613 msgid "A CLI application starter template" msgstr "" -#: ../../howto/logging-cookbook.rst:2593 +#: ../../howto/logging-cookbook.rst:2615 msgid "Here's an example which shows how you can:" msgstr "" -#: ../../howto/logging-cookbook.rst:2595 +#: ../../howto/logging-cookbook.rst:2617 msgid "Use a logging level based on command-line arguments" msgstr "" -#: ../../howto/logging-cookbook.rst:2596 +#: ../../howto/logging-cookbook.rst:2618 msgid "" "Dispatch to multiple subcommands in separate files, all logging at the same " "level in a consistent way" msgstr "" -#: ../../howto/logging-cookbook.rst:2598 +#: ../../howto/logging-cookbook.rst:2620 msgid "Make use of simple, minimal configuration" msgstr "" -#: ../../howto/logging-cookbook.rst:2600 +#: ../../howto/logging-cookbook.rst:2622 msgid "" "Suppose we have a command-line application whose job is to stop, start or " "restart some services. This could be organised for the purposes of " @@ -1447,53 +1477,53 @@ msgid "" "``logging.INFO``. Here's one way that ``app.py`` could be written::" msgstr "" -#: ../../howto/logging-cookbook.rst:2649 +#: ../../howto/logging-cookbook.rst:2671 msgid "" "And the ``start``, ``stop`` and ``restart`` commands can be implemented in " "separate modules, like so for starting::" msgstr "" -#: ../../howto/logging-cookbook.rst:2662 +#: ../../howto/logging-cookbook.rst:2684 msgid "and thus for stopping::" msgstr "" -#: ../../howto/logging-cookbook.rst:2683 +#: ../../howto/logging-cookbook.rst:2705 msgid "and similarly for restarting::" msgstr "" -#: ../../howto/logging-cookbook.rst:2704 +#: ../../howto/logging-cookbook.rst:2726 msgid "" "If we run this application with the default log level, we get output like " "this:" msgstr "" -#: ../../howto/logging-cookbook.rst:2717 +#: ../../howto/logging-cookbook.rst:2739 msgid "" "The first word is the logging level, and the second word is the module or " "package name of the place where the event was logged." msgstr "" -#: ../../howto/logging-cookbook.rst:2720 +#: ../../howto/logging-cookbook.rst:2742 msgid "" "If we change the logging level, then we can change the information sent to " "the log. For example, if we want more information:" msgstr "" -#: ../../howto/logging-cookbook.rst:2737 +#: ../../howto/logging-cookbook.rst:2759 msgid "And if we want less:" msgstr "" -#: ../../howto/logging-cookbook.rst:2745 +#: ../../howto/logging-cookbook.rst:2767 msgid "" "In this case, the commands don't print anything to the console, since " "nothing at ``WARNING`` level or above is logged by them." msgstr "" -#: ../../howto/logging-cookbook.rst:2751 +#: ../../howto/logging-cookbook.rst:2773 msgid "A Qt GUI for logging" msgstr "" -#: ../../howto/logging-cookbook.rst:2753 +#: ../../howto/logging-cookbook.rst:2775 msgid "" "A question that comes up from time to time is about how to log to a GUI " "application. The `Qt `_ framework is a popular cross-" @@ -1501,7 +1531,7 @@ msgid "" "project/PySide2/>`_ or `PyQt5 `_ libraries." msgstr "" -#: ../../howto/logging-cookbook.rst:2759 +#: ../../howto/logging-cookbook.rst:2781 msgid "" "The following example shows how to log to a Qt GUI. This introduces a simple " "``QtHandler`` class which takes a callable, which should be a slot in the " @@ -1511,14 +1541,14 @@ msgid "" "logging messages at random levels with random short delays in between)." msgstr "" -#: ../../howto/logging-cookbook.rst:2766 +#: ../../howto/logging-cookbook.rst:2788 msgid "" "The worker thread is implemented using Qt's ``QThread`` class rather than " "the :mod:`threading` module, as there are circumstances where one has to use " "``QThread``, which offers better integration with other ``Qt`` components." msgstr "" -#: ../../howto/logging-cookbook.rst:2770 +#: ../../howto/logging-cookbook.rst:2792 msgid "" "The code should work with recent releases of either ``PySide2`` or " "``PyQt5``. You should be able to adapt the approach to earlier versions of " @@ -1526,11 +1556,11 @@ msgid "" "information." msgstr "" -#: ../../howto/logging-cookbook.rst:2987 +#: ../../howto/logging-cookbook.rst:3009 msgid "Patterns to avoid" msgstr "" -#: ../../howto/logging-cookbook.rst:2989 +#: ../../howto/logging-cookbook.rst:3011 msgid "" "Although the preceding sections have described ways of doing things you " "might need to do or deal with, it is worth mentioning some usage patterns " @@ -1538,11 +1568,11 @@ msgid "" "The following sections are in no particular order." msgstr "" -#: ../../howto/logging-cookbook.rst:2996 +#: ../../howto/logging-cookbook.rst:3018 msgid "Opening the same log file multiple times" msgstr "" -#: ../../howto/logging-cookbook.rst:2998 +#: ../../howto/logging-cookbook.rst:3020 msgid "" "On Windows, you will generally not be able to open the same file multiple " "times as this will lead to a \"file is in use by another process\" error. " @@ -1550,32 +1580,32 @@ msgid "" "file multiple times. This could be done accidentally, for example by:" msgstr "" -#: ../../howto/logging-cookbook.rst:3003 +#: ../../howto/logging-cookbook.rst:3025 msgid "" "Adding a file handler more than once which references the same file (e.g. by " "a copy/paste/forget-to-change error)." msgstr "" -#: ../../howto/logging-cookbook.rst:3006 +#: ../../howto/logging-cookbook.rst:3028 msgid "" "Opening two files that look different, as they have different names, but are " "the same because one is a symbolic link to the other." msgstr "" -#: ../../howto/logging-cookbook.rst:3009 +#: ../../howto/logging-cookbook.rst:3031 msgid "" "Forking a process, following which both parent and child have a reference to " "the same file. This might be through use of the :mod:`multiprocessing` " "module, for example." msgstr "" -#: ../../howto/logging-cookbook.rst:3013 +#: ../../howto/logging-cookbook.rst:3035 msgid "" "Opening a file multiple times might *appear* to work most of the time, but " "can lead to a number of problems in practice:" msgstr "" -#: ../../howto/logging-cookbook.rst:3016 +#: ../../howto/logging-cookbook.rst:3038 msgid "" "Logging output can be garbled because multiple threads or processes try to " "write to the same file. Although logging guards against concurrent use of " @@ -1584,7 +1614,7 @@ msgid "" "different handler instances which happen to point to the same file." msgstr "" -#: ../../howto/logging-cookbook.rst:3022 +#: ../../howto/logging-cookbook.rst:3044 msgid "" "An attempt to delete a file (e.g. during file rotation) silently fails, " "because there is another reference pointing to it. This can lead to " @@ -1592,17 +1622,17 @@ msgid "" "places, or are lost altogether." msgstr "" -#: ../../howto/logging-cookbook.rst:3027 +#: ../../howto/logging-cookbook.rst:3049 msgid "" "Use the techniques outlined in :ref:`multiple-processes` to circumvent such " "issues." msgstr "" -#: ../../howto/logging-cookbook.rst:3031 +#: ../../howto/logging-cookbook.rst:3053 msgid "Using loggers as attributes in a class or passing them as parameters" msgstr "" -#: ../../howto/logging-cookbook.rst:3033 +#: ../../howto/logging-cookbook.rst:3055 msgid "" "While there might be unusual cases where you'll need to do this, in general " "there is no point because loggers are singletons. Code can always access a " @@ -1613,12 +1643,12 @@ msgid "" "module (and not the class) is the unit of software decomposition." msgstr "" -#: ../../howto/logging-cookbook.rst:3043 +#: ../../howto/logging-cookbook.rst:3065 msgid "" "Adding handlers other than :class:`NullHandler` to a logger in a library" msgstr "" -#: ../../howto/logging-cookbook.rst:3045 +#: ../../howto/logging-cookbook.rst:3067 msgid "" "Configuring logging by adding handlers, formatters and filters is the " "responsibility of the application developer, not the library developer. If " @@ -1626,11 +1656,11 @@ msgid "" "your loggers other than a :class:`~logging.NullHandler` instance." msgstr "" -#: ../../howto/logging-cookbook.rst:3052 +#: ../../howto/logging-cookbook.rst:3074 msgid "Creating a lot of loggers" msgstr "" -#: ../../howto/logging-cookbook.rst:3054 +#: ../../howto/logging-cookbook.rst:3076 msgid "" "Loggers are singletons that are never freed during a script execution, and " "so creating lots of loggers will use up memory which can't then be freed. " diff --git a/library/asyncio-eventloop.po b/library/asyncio-eventloop.po index 47b809f937..8c3a65f793 100644 --- a/library/asyncio-eventloop.po +++ b/library/asyncio-eventloop.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.10\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-10-26 16:47+0000\n" +"POT-Creation-Date: 2021-11-25 00:09+0000\n" "PO-Revision-Date: 2018-05-23 14:38+0000\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" @@ -27,8 +27,8 @@ msgid "" "**Source code:** :source:`Lib/asyncio/events.py`, :source:`Lib/asyncio/" "base_events.py`" msgstr "" -"**原始碼:**\\ :source:`Lib/asyncio/events.py`\\ 、\\ " -":source:`Lib/asyncio/base_events.py`" +"**原始碼:**\\ :source:`Lib/asyncio/events.py`\\ 、\\ :source:`Lib/asyncio/" +"base_events.py`" #: ../../library/asyncio-eventloop.rst:14 msgid "Preface" @@ -250,8 +250,8 @@ msgid "" msgstr "" #: ../../library/asyncio-eventloop.rst:171 -#: ../../library/asyncio-eventloop.rst:1083 -#: ../../library/asyncio-eventloop.rst:1468 +#: ../../library/asyncio-eventloop.rst:1088 +#: ../../library/asyncio-eventloop.rst:1473 msgid "Example::" msgstr "" "範例:\n" @@ -489,8 +489,8 @@ msgid "The socket type will be :py:data:`~socket.SOCK_STREAM`." msgstr "" #: ../../library/asyncio-eventloop.rst:383 -#: ../../library/asyncio-eventloop.rst:999 -#: ../../library/asyncio-eventloop.rst:1015 +#: ../../library/asyncio-eventloop.rst:1004 +#: ../../library/asyncio-eventloop.rst:1020 msgid "" "*protocol_factory* must be a callable returning an :ref:`asyncio protocol " "` implementation." @@ -607,7 +607,7 @@ msgid "" msgstr "" #: ../../library/asyncio-eventloop.rst:455 -#: ../../library/asyncio-eventloop.rst:808 +#: ../../library/asyncio-eventloop.rst:813 msgid "" "*ssl_handshake_timeout* is (for a TLS connection) the time in seconds to " "wait for the TLS handshake to complete before aborting the connection. " @@ -635,19 +635,19 @@ msgstr "更多資訊請見:\\ https://tools.ietf.org/html/rfc6555" #: ../../library/asyncio-eventloop.rst:476 #: ../../library/asyncio-eventloop.rst:593 -#: ../../library/asyncio-eventloop.rst:746 +#: ../../library/asyncio-eventloop.rst:751 msgid "The *ssl_handshake_timeout* parameter." msgstr "*ssl_handshake_timeout* 參數。" #: ../../library/asyncio-eventloop.rst:480 -#: ../../library/asyncio-eventloop.rst:676 +#: ../../library/asyncio-eventloop.rst:681 msgid "" "The socket option :py:data:`~socket.TCP_NODELAY` is set by default for all " "TCP connections." msgstr "" #: ../../library/asyncio-eventloop.rst:485 -#: ../../library/asyncio-eventloop.rst:681 +#: ../../library/asyncio-eventloop.rst:686 msgid "Added support for SSL/TLS in :class:`ProactorEventLoop`." msgstr "" @@ -697,7 +697,7 @@ msgstr "" #: ../../library/asyncio-eventloop.rst:522 #: ../../library/asyncio-eventloop.rst:618 -#: ../../library/asyncio-eventloop.rst:729 +#: ../../library/asyncio-eventloop.rst:734 msgid "" "*protocol_factory* must be a callable returning a :ref:`protocol ` implementation." @@ -799,8 +799,8 @@ msgid "" msgstr "" #: ../../library/asyncio-eventloop.rst:590 -#: ../../library/asyncio-eventloop.rst:710 -#: ../../library/asyncio-eventloop.rst:1066 +#: ../../library/asyncio-eventloop.rst:715 +#: ../../library/asyncio-eventloop.rst:1071 msgid ":ref:`Availability `: Unix." msgstr ":ref:`適用 `:Unix。" @@ -853,55 +853,63 @@ msgstr "" #: ../../library/asyncio-eventloop.rst:634 msgid "" +"The *port* parameter can be set to specify which port the server should " +"listen on. If ``0`` or ``None`` (the default), a random unused port will be " +"selected (note that if *host* resolves to multiple network interfaces, a " +"different random port will be selected for each interface)." +msgstr "" + +#: ../../library/asyncio-eventloop.rst:639 +msgid "" "*family* can be set to either :data:`socket.AF_INET` or :data:`~socket." "AF_INET6` to force the socket to use IPv4 or IPv6. If not set, the *family* " "will be determined from host name (defaults to :data:`~socket.AF_UNSPEC`)." msgstr "" -#: ../../library/asyncio-eventloop.rst:639 +#: ../../library/asyncio-eventloop.rst:644 msgid "*flags* is a bitmask for :meth:`getaddrinfo`." msgstr "" -#: ../../library/asyncio-eventloop.rst:641 +#: ../../library/asyncio-eventloop.rst:646 msgid "" "*sock* can optionally be specified in order to use a preexisting socket " "object. If specified, *host* and *port* must not be specified." msgstr "" -#: ../../library/asyncio-eventloop.rst:644 +#: ../../library/asyncio-eventloop.rst:649 msgid "" "*backlog* is the maximum number of queued connections passed to :meth:" "`~socket.socket.listen` (defaults to 100)." msgstr "" -#: ../../library/asyncio-eventloop.rst:647 +#: ../../library/asyncio-eventloop.rst:652 msgid "" "*ssl* can be set to an :class:`~ssl.SSLContext` instance to enable TLS over " "the accepted connections." msgstr "" -#: ../../library/asyncio-eventloop.rst:650 +#: ../../library/asyncio-eventloop.rst:655 msgid "" "*reuse_address* tells the kernel to reuse a local socket in ``TIME_WAIT`` " "state, without waiting for its natural timeout to expire. If not specified " "will automatically be set to ``True`` on Unix." msgstr "" -#: ../../library/asyncio-eventloop.rst:655 +#: ../../library/asyncio-eventloop.rst:660 msgid "" "*reuse_port* tells the kernel to allow this endpoint to be bound to the same " "port as other existing endpoints are bound to, so long as they all set this " "flag when being created. This option is not supported on Windows." msgstr "" -#: ../../library/asyncio-eventloop.rst:660 +#: ../../library/asyncio-eventloop.rst:665 msgid "" "*ssl_handshake_timeout* is (for a TLS server) the time in seconds to wait " "for the TLS handshake to complete before aborting the connection. ``60.0`` " "seconds if ``None`` (default)." msgstr "" -#: ../../library/asyncio-eventloop.rst:664 +#: ../../library/asyncio-eventloop.rst:669 msgid "" "*start_serving* set to ``True`` (the default) causes the created server to " "start accepting connections immediately. When set to ``False``, the user " @@ -909,105 +917,105 @@ msgid "" "to make the server to start accepting connections." msgstr "" -#: ../../library/asyncio-eventloop.rst:672 +#: ../../library/asyncio-eventloop.rst:677 msgid "Added *ssl_handshake_timeout* and *start_serving* parameters." msgstr "" -#: ../../library/asyncio-eventloop.rst:685 +#: ../../library/asyncio-eventloop.rst:690 msgid "The *host* parameter can be a sequence of strings." msgstr "" -#: ../../library/asyncio-eventloop.rst:689 +#: ../../library/asyncio-eventloop.rst:694 msgid "" "The :func:`start_server` function is a higher-level alternative API that " "returns a pair of :class:`StreamReader` and :class:`StreamWriter` that can " "be used in an async/await code." msgstr "" -#: ../../library/asyncio-eventloop.rst:698 +#: ../../library/asyncio-eventloop.rst:703 msgid "" "Similar to :meth:`loop.create_server` but works with the :py:data:`~socket." "AF_UNIX` socket family." msgstr "" -#: ../../library/asyncio-eventloop.rst:701 +#: ../../library/asyncio-eventloop.rst:706 msgid "" "*path* is the name of a Unix domain socket, and is required, unless a *sock* " "argument is provided. Abstract Unix sockets, :class:`str`, :class:`bytes`, " "and :class:`~pathlib.Path` paths are supported." msgstr "" -#: ../../library/asyncio-eventloop.rst:706 +#: ../../library/asyncio-eventloop.rst:711 msgid "" "See the documentation of the :meth:`loop.create_server` method for " "information about arguments to this method." msgstr "" -#: ../../library/asyncio-eventloop.rst:713 +#: ../../library/asyncio-eventloop.rst:718 msgid "The *ssl_handshake_timeout* and *start_serving* parameters." msgstr "" -#: ../../library/asyncio-eventloop.rst:717 +#: ../../library/asyncio-eventloop.rst:722 msgid "The *path* parameter can now be a :class:`~pathlib.Path` object." msgstr "" -#: ../../library/asyncio-eventloop.rst:722 +#: ../../library/asyncio-eventloop.rst:727 msgid "Wrap an already accepted connection into a transport/protocol pair." msgstr "" -#: ../../library/asyncio-eventloop.rst:724 +#: ../../library/asyncio-eventloop.rst:729 msgid "" "This method can be used by servers that accept connections outside of " "asyncio but that use asyncio to handle them." msgstr "" -#: ../../library/asyncio-eventloop.rst:727 -#: ../../library/asyncio-eventloop.rst:794 +#: ../../library/asyncio-eventloop.rst:732 +#: ../../library/asyncio-eventloop.rst:799 msgid "Parameters:" msgstr "參數:" -#: ../../library/asyncio-eventloop.rst:732 +#: ../../library/asyncio-eventloop.rst:737 msgid "" "*sock* is a preexisting socket object returned from :meth:`socket.accept " "`." msgstr "" -#: ../../library/asyncio-eventloop.rst:735 +#: ../../library/asyncio-eventloop.rst:740 msgid "" "*ssl* can be set to an :class:`~ssl.SSLContext` to enable SSL over the " "accepted connections." msgstr "" -#: ../../library/asyncio-eventloop.rst:738 +#: ../../library/asyncio-eventloop.rst:743 msgid "" "*ssl_handshake_timeout* is (for an SSL connection) the time in seconds to " "wait for the SSL handshake to complete before aborting the connection. " "``60.0`` seconds if ``None`` (default)." msgstr "" -#: ../../library/asyncio-eventloop.rst:742 +#: ../../library/asyncio-eventloop.rst:747 msgid "Returns a ``(transport, protocol)`` pair." msgstr "" -#: ../../library/asyncio-eventloop.rst:752 +#: ../../library/asyncio-eventloop.rst:757 msgid "Transferring files" msgstr "" -#: ../../library/asyncio-eventloop.rst:757 +#: ../../library/asyncio-eventloop.rst:762 msgid "" "Send a *file* over a *transport*. Return the total number of bytes sent." msgstr "" -#: ../../library/asyncio-eventloop.rst:760 +#: ../../library/asyncio-eventloop.rst:765 msgid "The method uses high-performance :meth:`os.sendfile` if available." msgstr "" -#: ../../library/asyncio-eventloop.rst:762 +#: ../../library/asyncio-eventloop.rst:767 msgid "*file* must be a regular file object opened in binary mode." msgstr "" -#: ../../library/asyncio-eventloop.rst:764 -#: ../../library/asyncio-eventloop.rst:954 +#: ../../library/asyncio-eventloop.rst:769 +#: ../../library/asyncio-eventloop.rst:959 msgid "" "*offset* tells from where to start reading the file. If specified, *count* " "is the total number of bytes to transmit as opposed to sending the file " @@ -1016,98 +1024,98 @@ msgid "" "obtain the actual number of bytes sent." msgstr "" -#: ../../library/asyncio-eventloop.rst:771 +#: ../../library/asyncio-eventloop.rst:776 msgid "" "*fallback* set to ``True`` makes asyncio to manually read and send the file " "when the platform does not support the sendfile system call (e.g. Windows or " "SSL socket on Unix)." msgstr "" -#: ../../library/asyncio-eventloop.rst:775 +#: ../../library/asyncio-eventloop.rst:780 msgid "" "Raise :exc:`SendfileNotAvailableError` if the system does not support the " "*sendfile* syscall and *fallback* is ``False``." msgstr "" -#: ../../library/asyncio-eventloop.rst:782 +#: ../../library/asyncio-eventloop.rst:787 msgid "TLS Upgrade" msgstr "" -#: ../../library/asyncio-eventloop.rst:788 +#: ../../library/asyncio-eventloop.rst:793 msgid "Upgrade an existing transport-based connection to TLS." msgstr "" -#: ../../library/asyncio-eventloop.rst:790 +#: ../../library/asyncio-eventloop.rst:795 msgid "" "Return a new transport instance, that the *protocol* must start using " "immediately after the *await*. The *transport* instance passed to the " "*start_tls* method should never be used again." msgstr "" -#: ../../library/asyncio-eventloop.rst:796 +#: ../../library/asyncio-eventloop.rst:801 msgid "" "*transport* and *protocol* instances that methods like :meth:`~loop." "create_server` and :meth:`~loop.create_connection` return." msgstr "" -#: ../../library/asyncio-eventloop.rst:800 +#: ../../library/asyncio-eventloop.rst:805 msgid "*sslcontext*: a configured instance of :class:`~ssl.SSLContext`." msgstr "" -#: ../../library/asyncio-eventloop.rst:802 +#: ../../library/asyncio-eventloop.rst:807 msgid "" "*server_side* pass ``True`` when a server-side connection is being upgraded " "(like the one created by :meth:`~loop.create_server`)." msgstr "" -#: ../../library/asyncio-eventloop.rst:805 +#: ../../library/asyncio-eventloop.rst:810 msgid "" "*server_hostname*: sets or overrides the host name that the target server's " "certificate will be matched against." msgstr "" -#: ../../library/asyncio-eventloop.rst:816 +#: ../../library/asyncio-eventloop.rst:821 msgid "Watching file descriptors" msgstr "" -#: ../../library/asyncio-eventloop.rst:820 +#: ../../library/asyncio-eventloop.rst:825 msgid "" "Start monitoring the *fd* file descriptor for read availability and invoke " "*callback* with the specified arguments once *fd* is available for reading." msgstr "" -#: ../../library/asyncio-eventloop.rst:826 +#: ../../library/asyncio-eventloop.rst:831 msgid "Stop monitoring the *fd* file descriptor for read availability." msgstr "" -#: ../../library/asyncio-eventloop.rst:830 +#: ../../library/asyncio-eventloop.rst:835 msgid "" "Start monitoring the *fd* file descriptor for write availability and invoke " "*callback* with the specified arguments once *fd* is available for writing." msgstr "" -#: ../../library/asyncio-eventloop.rst:834 -#: ../../library/asyncio-eventloop.rst:1053 +#: ../../library/asyncio-eventloop.rst:839 +#: ../../library/asyncio-eventloop.rst:1058 msgid "" "Use :func:`functools.partial` :ref:`to pass keyword arguments ` to *callback*." msgstr "" -#: ../../library/asyncio-eventloop.rst:839 +#: ../../library/asyncio-eventloop.rst:844 msgid "Stop monitoring the *fd* file descriptor for write availability." msgstr "" -#: ../../library/asyncio-eventloop.rst:841 +#: ../../library/asyncio-eventloop.rst:846 msgid "" "See also :ref:`Platform Support ` section for some " "limitations of these methods." msgstr "" -#: ../../library/asyncio-eventloop.rst:846 +#: ../../library/asyncio-eventloop.rst:851 msgid "Working with socket objects directly" msgstr "" -#: ../../library/asyncio-eventloop.rst:848 +#: ../../library/asyncio-eventloop.rst:853 msgid "" "In general, protocol implementations that use transport-based APIs such as :" "meth:`loop.create_connection` and :meth:`loop.create_server` are faster than " @@ -1116,49 +1124,49 @@ msgid "" "socket` objects directly is more convenient." msgstr "" -#: ../../library/asyncio-eventloop.rst:857 +#: ../../library/asyncio-eventloop.rst:862 msgid "" "Receive up to *nbytes* from *sock*. Asynchronous version of :meth:`socket." "recv() `." msgstr "" -#: ../../library/asyncio-eventloop.rst:860 +#: ../../library/asyncio-eventloop.rst:865 msgid "Return the received data as a bytes object." msgstr "" -#: ../../library/asyncio-eventloop.rst:862 -#: ../../library/asyncio-eventloop.rst:876 -#: ../../library/asyncio-eventloop.rst:891 -#: ../../library/asyncio-eventloop.rst:904 -#: ../../library/asyncio-eventloop.rst:930 -#: ../../library/asyncio-eventloop.rst:968 +#: ../../library/asyncio-eventloop.rst:867 +#: ../../library/asyncio-eventloop.rst:881 +#: ../../library/asyncio-eventloop.rst:896 +#: ../../library/asyncio-eventloop.rst:909 +#: ../../library/asyncio-eventloop.rst:935 +#: ../../library/asyncio-eventloop.rst:973 msgid "*sock* must be a non-blocking socket." msgstr "" -#: ../../library/asyncio-eventloop.rst:864 +#: ../../library/asyncio-eventloop.rst:869 msgid "" "Even though this method was always documented as a coroutine method, " "releases before Python 3.7 returned a :class:`Future`. Since Python 3.7 this " "is an ``async def`` method." msgstr "" -#: ../../library/asyncio-eventloop.rst:871 +#: ../../library/asyncio-eventloop.rst:876 msgid "" "Receive data from *sock* into the *buf* buffer. Modeled after the blocking :" "meth:`socket.recv_into() ` method." msgstr "" -#: ../../library/asyncio-eventloop.rst:874 +#: ../../library/asyncio-eventloop.rst:879 msgid "Return the number of bytes written to the buffer." msgstr "" -#: ../../library/asyncio-eventloop.rst:882 +#: ../../library/asyncio-eventloop.rst:887 msgid "" "Send *data* to the *sock* socket. Asynchronous version of :meth:`socket." "sendall() `." msgstr "" -#: ../../library/asyncio-eventloop.rst:885 +#: ../../library/asyncio-eventloop.rst:890 msgid "" "This method continues to send to the socket until either all data in *data* " "has been sent or an error occurs. ``None`` is returned on success. On " @@ -1167,23 +1175,23 @@ msgid "" "the connection." msgstr "" -#: ../../library/asyncio-eventloop.rst:893 +#: ../../library/asyncio-eventloop.rst:898 msgid "" "Even though the method was always documented as a coroutine method, before " "Python 3.7 it returned an :class:`Future`. Since Python 3.7, this is an " "``async def`` method." msgstr "" -#: ../../library/asyncio-eventloop.rst:900 +#: ../../library/asyncio-eventloop.rst:905 msgid "Connect *sock* to a remote socket at *address*." msgstr "" -#: ../../library/asyncio-eventloop.rst:902 +#: ../../library/asyncio-eventloop.rst:907 msgid "" "Asynchronous version of :meth:`socket.connect() `." msgstr "" -#: ../../library/asyncio-eventloop.rst:906 +#: ../../library/asyncio-eventloop.rst:911 msgid "" "``address`` no longer needs to be resolved. ``sock_connect`` will try to " "check if the *address* is already resolved by calling :func:`socket." @@ -1191,19 +1199,19 @@ msgid "" "*address*." msgstr "" -#: ../../library/asyncio-eventloop.rst:915 +#: ../../library/asyncio-eventloop.rst:920 msgid "" ":meth:`loop.create_connection` and :func:`asyncio.open_connection() " "`." msgstr "" -#: ../../library/asyncio-eventloop.rst:921 +#: ../../library/asyncio-eventloop.rst:926 msgid "" "Accept a connection. Modeled after the blocking :meth:`socket.accept() " "` method." msgstr "" -#: ../../library/asyncio-eventloop.rst:924 +#: ../../library/asyncio-eventloop.rst:929 msgid "" "The socket must be bound to an address and listening for connections. The " "return value is a pair ``(conn, address)`` where *conn* is a *new* socket " @@ -1211,64 +1219,64 @@ msgid "" "the address bound to the socket on the other end of the connection." msgstr "" -#: ../../library/asyncio-eventloop.rst:932 +#: ../../library/asyncio-eventloop.rst:937 msgid "" "Even though the method was always documented as a coroutine method, before " "Python 3.7 it returned a :class:`Future`. Since Python 3.7, this is an " "``async def`` method." msgstr "" -#: ../../library/asyncio-eventloop.rst:939 +#: ../../library/asyncio-eventloop.rst:944 msgid ":meth:`loop.create_server` and :func:`start_server`." msgstr ":meth:`loop.create_server` 和 :func:`start_server`\\ 。" -#: ../../library/asyncio-eventloop.rst:944 +#: ../../library/asyncio-eventloop.rst:949 msgid "" "Send a file using high-performance :mod:`os.sendfile` if possible. Return " "the total number of bytes sent." msgstr "" -#: ../../library/asyncio-eventloop.rst:947 +#: ../../library/asyncio-eventloop.rst:952 msgid "" "Asynchronous version of :meth:`socket.sendfile() `." msgstr "" -#: ../../library/asyncio-eventloop.rst:949 +#: ../../library/asyncio-eventloop.rst:954 msgid "" "*sock* must be a non-blocking :const:`socket.SOCK_STREAM` :class:`~socket." "socket`." msgstr "" -#: ../../library/asyncio-eventloop.rst:952 +#: ../../library/asyncio-eventloop.rst:957 msgid "*file* must be a regular file object open in binary mode." msgstr "" -#: ../../library/asyncio-eventloop.rst:961 +#: ../../library/asyncio-eventloop.rst:966 msgid "" "*fallback*, when set to ``True``, makes asyncio manually read and send the " "file when the platform does not support the sendfile syscall (e.g. Windows " "or SSL socket on Unix)." msgstr "" -#: ../../library/asyncio-eventloop.rst:965 +#: ../../library/asyncio-eventloop.rst:970 msgid "" "Raise :exc:`SendfileNotAvailableError` if the system does not support " "*sendfile* syscall and *fallback* is ``False``." msgstr "" -#: ../../library/asyncio-eventloop.rst:974 +#: ../../library/asyncio-eventloop.rst:979 msgid "DNS" msgstr "" -#: ../../library/asyncio-eventloop.rst:979 +#: ../../library/asyncio-eventloop.rst:984 msgid "Asynchronous version of :meth:`socket.getaddrinfo`." msgstr "" -#: ../../library/asyncio-eventloop.rst:983 +#: ../../library/asyncio-eventloop.rst:988 msgid "Asynchronous version of :meth:`socket.getnameinfo`." msgstr "" -#: ../../library/asyncio-eventloop.rst:985 +#: ../../library/asyncio-eventloop.rst:990 msgid "" "Both *getaddrinfo* and *getnameinfo* methods were always documented to " "return a coroutine, but prior to Python 3.7 they were, in fact, returning :" @@ -1276,67 +1284,67 @@ msgid "" "coroutines." msgstr "" -#: ../../library/asyncio-eventloop.rst:993 +#: ../../library/asyncio-eventloop.rst:998 msgid "Working with pipes" msgstr "" -#: ../../library/asyncio-eventloop.rst:997 +#: ../../library/asyncio-eventloop.rst:1002 msgid "Register the read end of *pipe* in the event loop." msgstr "" -#: ../../library/asyncio-eventloop.rst:1002 +#: ../../library/asyncio-eventloop.rst:1007 msgid "*pipe* is a :term:`file-like object `." msgstr "" -#: ../../library/asyncio-eventloop.rst:1004 +#: ../../library/asyncio-eventloop.rst:1009 msgid "" "Return pair ``(transport, protocol)``, where *transport* supports the :class:" "`ReadTransport` interface and *protocol* is an object instantiated by the " "*protocol_factory*." msgstr "" -#: ../../library/asyncio-eventloop.rst:1008 -#: ../../library/asyncio-eventloop.rst:1024 +#: ../../library/asyncio-eventloop.rst:1013 +#: ../../library/asyncio-eventloop.rst:1029 msgid "" "With :class:`SelectorEventLoop` event loop, the *pipe* is set to non-" "blocking mode." msgstr "" -#: ../../library/asyncio-eventloop.rst:1013 +#: ../../library/asyncio-eventloop.rst:1018 msgid "Register the write end of *pipe* in the event loop." msgstr "" -#: ../../library/asyncio-eventloop.rst:1018 +#: ../../library/asyncio-eventloop.rst:1023 msgid "*pipe* is :term:`file-like object `." msgstr "" -#: ../../library/asyncio-eventloop.rst:1020 +#: ../../library/asyncio-eventloop.rst:1025 msgid "" "Return pair ``(transport, protocol)``, where *transport* supports :class:" "`WriteTransport` interface and *protocol* is an object instantiated by the " "*protocol_factory*." msgstr "" -#: ../../library/asyncio-eventloop.rst:1029 +#: ../../library/asyncio-eventloop.rst:1034 msgid "" ":class:`SelectorEventLoop` does not support the above methods on Windows. " "Use :class:`ProactorEventLoop` instead for Windows." msgstr "" -#: ../../library/asyncio-eventloop.rst:1034 +#: ../../library/asyncio-eventloop.rst:1039 msgid "" "The :meth:`loop.subprocess_exec` and :meth:`loop.subprocess_shell` methods." msgstr "" -#: ../../library/asyncio-eventloop.rst:1039 +#: ../../library/asyncio-eventloop.rst:1044 msgid "Unix signals" msgstr "" -#: ../../library/asyncio-eventloop.rst:1043 +#: ../../library/asyncio-eventloop.rst:1048 msgid "Set *callback* as the handler for the *signum* signal." msgstr "" -#: ../../library/asyncio-eventloop.rst:1045 +#: ../../library/asyncio-eventloop.rst:1050 msgid "" "The callback will be invoked by *loop*, along with other queued callbacks " "and runnable coroutines of that event loop. Unlike signal handlers " @@ -1344,56 +1352,56 @@ msgid "" "function is allowed to interact with the event loop." msgstr "" -#: ../../library/asyncio-eventloop.rst:1050 +#: ../../library/asyncio-eventloop.rst:1055 msgid "" "Raise :exc:`ValueError` if the signal number is invalid or uncatchable. " "Raise :exc:`RuntimeError` if there is a problem setting up the handler." msgstr "" -#: ../../library/asyncio-eventloop.rst:1056 +#: ../../library/asyncio-eventloop.rst:1061 msgid "" "Like :func:`signal.signal`, this function must be invoked in the main thread." msgstr "" -#: ../../library/asyncio-eventloop.rst:1061 +#: ../../library/asyncio-eventloop.rst:1066 msgid "Remove the handler for the *sig* signal." msgstr "" -#: ../../library/asyncio-eventloop.rst:1063 +#: ../../library/asyncio-eventloop.rst:1068 msgid "" "Return ``True`` if the signal handler was removed, or ``False`` if no " "handler was set for the given signal." msgstr "" -#: ../../library/asyncio-eventloop.rst:1070 +#: ../../library/asyncio-eventloop.rst:1075 msgid "The :mod:`signal` module." msgstr "" -#: ../../library/asyncio-eventloop.rst:1074 +#: ../../library/asyncio-eventloop.rst:1079 msgid "Executing code in thread or process pools" msgstr "" -#: ../../library/asyncio-eventloop.rst:1078 +#: ../../library/asyncio-eventloop.rst:1083 msgid "Arrange for *func* to be called in the specified executor." msgstr "" -#: ../../library/asyncio-eventloop.rst:1080 +#: ../../library/asyncio-eventloop.rst:1085 msgid "" "The *executor* argument should be an :class:`concurrent.futures.Executor` " "instance. The default executor is used if *executor* is ``None``." msgstr "" -#: ../../library/asyncio-eventloop.rst:1124 +#: ../../library/asyncio-eventloop.rst:1129 msgid "This method returns a :class:`asyncio.Future` object." msgstr "" -#: ../../library/asyncio-eventloop.rst:1126 +#: ../../library/asyncio-eventloop.rst:1131 msgid "" "Use :func:`functools.partial` :ref:`to pass keyword arguments ` to *func*." msgstr "" -#: ../../library/asyncio-eventloop.rst:1129 +#: ../../library/asyncio-eventloop.rst:1134 msgid "" ":meth:`loop.run_in_executor` no longer configures the ``max_workers`` of the " "thread pool executor it creates, instead leaving it up to the thread pool " @@ -1401,38 +1409,38 @@ msgid "" "default." msgstr "" -#: ../../library/asyncio-eventloop.rst:1138 +#: ../../library/asyncio-eventloop.rst:1143 msgid "" "Set *executor* as the default executor used by :meth:`run_in_executor`. " "*executor* should be an instance of :class:`~concurrent.futures." "ThreadPoolExecutor`." msgstr "" -#: ../../library/asyncio-eventloop.rst:1142 +#: ../../library/asyncio-eventloop.rst:1147 msgid "" "Using an executor that is not an instance of :class:`~concurrent.futures." "ThreadPoolExecutor` is deprecated and will trigger an error in Python 3.9." msgstr "" -#: ../../library/asyncio-eventloop.rst:1147 +#: ../../library/asyncio-eventloop.rst:1152 msgid "" "*executor* must be an instance of :class:`concurrent.futures." "ThreadPoolExecutor`." msgstr "" -#: ../../library/asyncio-eventloop.rst:1152 +#: ../../library/asyncio-eventloop.rst:1157 msgid "Error Handling API" msgstr "" -#: ../../library/asyncio-eventloop.rst:1154 +#: ../../library/asyncio-eventloop.rst:1159 msgid "Allows customizing how exceptions are handled in the event loop." msgstr "" -#: ../../library/asyncio-eventloop.rst:1158 +#: ../../library/asyncio-eventloop.rst:1163 msgid "Set *handler* as the new event loop exception handler." msgstr "" -#: ../../library/asyncio-eventloop.rst:1160 +#: ../../library/asyncio-eventloop.rst:1165 msgid "" "If *handler* is ``None``, the default exception handler will be set. " "Otherwise, *handler* must be a callable with the signature matching ``(loop, " @@ -1441,158 +1449,158 @@ msgid "" "(see :meth:`call_exception_handler` documentation for details about context)." msgstr "" -#: ../../library/asyncio-eventloop.rst:1170 +#: ../../library/asyncio-eventloop.rst:1175 msgid "" "Return the current exception handler, or ``None`` if no custom exception " "handler was set." msgstr "" -#: ../../library/asyncio-eventloop.rst:1177 +#: ../../library/asyncio-eventloop.rst:1182 msgid "Default exception handler." msgstr "" -#: ../../library/asyncio-eventloop.rst:1179 +#: ../../library/asyncio-eventloop.rst:1184 msgid "" "This is called when an exception occurs and no exception handler is set. " "This can be called by a custom exception handler that wants to defer to the " "default handler behavior." msgstr "" -#: ../../library/asyncio-eventloop.rst:1183 +#: ../../library/asyncio-eventloop.rst:1188 msgid "" "*context* parameter has the same meaning as in :meth:" "`call_exception_handler`." msgstr "" -#: ../../library/asyncio-eventloop.rst:1188 +#: ../../library/asyncio-eventloop.rst:1193 msgid "Call the current event loop exception handler." msgstr "" -#: ../../library/asyncio-eventloop.rst:1190 +#: ../../library/asyncio-eventloop.rst:1195 msgid "" "*context* is a ``dict`` object containing the following keys (new keys may " "be introduced in future Python versions):" msgstr "" -#: ../../library/asyncio-eventloop.rst:1193 +#: ../../library/asyncio-eventloop.rst:1198 msgid "'message': Error message;" msgstr "" -#: ../../library/asyncio-eventloop.rst:1194 +#: ../../library/asyncio-eventloop.rst:1199 msgid "'exception' (optional): Exception object;" msgstr "" -#: ../../library/asyncio-eventloop.rst:1195 +#: ../../library/asyncio-eventloop.rst:1200 msgid "'future' (optional): :class:`asyncio.Future` instance;" msgstr "" -#: ../../library/asyncio-eventloop.rst:1196 +#: ../../library/asyncio-eventloop.rst:1201 msgid "'task' (optional): :class:`asyncio.Task` instance;" msgstr "" -#: ../../library/asyncio-eventloop.rst:1197 +#: ../../library/asyncio-eventloop.rst:1202 msgid "'handle' (optional): :class:`asyncio.Handle` instance;" msgstr "" -#: ../../library/asyncio-eventloop.rst:1198 +#: ../../library/asyncio-eventloop.rst:1203 msgid "'protocol' (optional): :ref:`Protocol ` instance;" msgstr "" -#: ../../library/asyncio-eventloop.rst:1199 +#: ../../library/asyncio-eventloop.rst:1204 msgid "'transport' (optional): :ref:`Transport ` instance;" msgstr "" -#: ../../library/asyncio-eventloop.rst:1200 +#: ../../library/asyncio-eventloop.rst:1205 msgid "'socket' (optional): :class:`socket.socket` instance;" msgstr "" -#: ../../library/asyncio-eventloop.rst:1202 +#: ../../library/asyncio-eventloop.rst:1207 msgid "'asyncgen' (optional): Asynchronous generator that caused" msgstr "" -#: ../../library/asyncio-eventloop.rst:1202 +#: ../../library/asyncio-eventloop.rst:1207 msgid "the exception." msgstr "" -#: ../../library/asyncio-eventloop.rst:1206 +#: ../../library/asyncio-eventloop.rst:1211 msgid "" "This method should not be overloaded in subclassed event loops. For custom " "exception handling, use the :meth:`set_exception_handler()` method." msgstr "" -#: ../../library/asyncio-eventloop.rst:1211 +#: ../../library/asyncio-eventloop.rst:1216 msgid "Enabling debug mode" msgstr "" -#: ../../library/asyncio-eventloop.rst:1215 +#: ../../library/asyncio-eventloop.rst:1220 msgid "Get the debug mode (:class:`bool`) of the event loop." msgstr "" -#: ../../library/asyncio-eventloop.rst:1217 +#: ../../library/asyncio-eventloop.rst:1222 msgid "" "The default value is ``True`` if the environment variable :envvar:" "`PYTHONASYNCIODEBUG` is set to a non-empty string, ``False`` otherwise." msgstr "" -#: ../../library/asyncio-eventloop.rst:1223 +#: ../../library/asyncio-eventloop.rst:1228 msgid "Set the debug mode of the event loop." msgstr "" -#: ../../library/asyncio-eventloop.rst:1227 +#: ../../library/asyncio-eventloop.rst:1232 msgid "" "The new :ref:`Python Development Mode ` can now also be used to " "enable the debug mode." msgstr "" -#: ../../library/asyncio-eventloop.rst:1232 +#: ../../library/asyncio-eventloop.rst:1237 msgid "The :ref:`debug mode of asyncio `." msgstr "" -#: ../../library/asyncio-eventloop.rst:1236 +#: ../../library/asyncio-eventloop.rst:1241 msgid "Running Subprocesses" msgstr "" -#: ../../library/asyncio-eventloop.rst:1238 +#: ../../library/asyncio-eventloop.rst:1243 msgid "" "Methods described in this subsections are low-level. In regular async/await " "code consider using the high-level :func:`asyncio.create_subprocess_shell` " "and :func:`asyncio.create_subprocess_exec` convenience functions instead." msgstr "" -#: ../../library/asyncio-eventloop.rst:1245 +#: ../../library/asyncio-eventloop.rst:1250 msgid "" "The default asyncio event loop on **Windows** does not support subprocesses. " "See :ref:`Subprocess Support on Windows ` for " "details." msgstr "" -#: ../../library/asyncio-eventloop.rst:1253 +#: ../../library/asyncio-eventloop.rst:1258 msgid "" "Create a subprocess from one or more string arguments specified by *args*." msgstr "" -#: ../../library/asyncio-eventloop.rst:1256 +#: ../../library/asyncio-eventloop.rst:1261 msgid "*args* must be a list of strings represented by:" msgstr "" -#: ../../library/asyncio-eventloop.rst:1258 +#: ../../library/asyncio-eventloop.rst:1263 msgid ":class:`str`;" msgstr ":class:`str`\\ ;" -#: ../../library/asyncio-eventloop.rst:1259 +#: ../../library/asyncio-eventloop.rst:1264 msgid "" "or :class:`bytes`, encoded to the :ref:`filesystem encoding `." msgstr "" -#: ../../library/asyncio-eventloop.rst:1262 +#: ../../library/asyncio-eventloop.rst:1267 msgid "" "The first string specifies the program executable, and the remaining strings " "specify the arguments. Together, string arguments form the ``argv`` of the " "program." msgstr "" -#: ../../library/asyncio-eventloop.rst:1266 +#: ../../library/asyncio-eventloop.rst:1271 msgid "" "This is similar to the standard library :class:`subprocess.Popen` class " "called with ``shell=False`` and the list of strings passed as the first " @@ -1600,136 +1608,136 @@ msgid "" "which is list of strings, *subprocess_exec* takes multiple string arguments." msgstr "" -#: ../../library/asyncio-eventloop.rst:1272 +#: ../../library/asyncio-eventloop.rst:1277 msgid "" "The *protocol_factory* must be a callable returning a subclass of the :class:" "`asyncio.SubprocessProtocol` class." msgstr "" -#: ../../library/asyncio-eventloop.rst:1275 +#: ../../library/asyncio-eventloop.rst:1280 msgid "Other parameters:" msgstr "其他參數:" -#: ../../library/asyncio-eventloop.rst:1277 +#: ../../library/asyncio-eventloop.rst:1282 msgid "*stdin* can be any of these:" msgstr "" -#: ../../library/asyncio-eventloop.rst:1279 +#: ../../library/asyncio-eventloop.rst:1284 msgid "" "a file-like object representing a pipe to be connected to the subprocess's " "standard input stream using :meth:`~loop.connect_write_pipe`" msgstr "" -#: ../../library/asyncio-eventloop.rst:1282 -#: ../../library/asyncio-eventloop.rst:1294 -#: ../../library/asyncio-eventloop.rst:1306 +#: ../../library/asyncio-eventloop.rst:1287 +#: ../../library/asyncio-eventloop.rst:1299 +#: ../../library/asyncio-eventloop.rst:1311 msgid "" "the :const:`subprocess.PIPE` constant (default) which will create a new pipe " "and connect it," msgstr "" -#: ../../library/asyncio-eventloop.rst:1284 -#: ../../library/asyncio-eventloop.rst:1296 -#: ../../library/asyncio-eventloop.rst:1308 +#: ../../library/asyncio-eventloop.rst:1289 +#: ../../library/asyncio-eventloop.rst:1301 +#: ../../library/asyncio-eventloop.rst:1313 msgid "" "the value ``None`` which will make the subprocess inherit the file " "descriptor from this process" msgstr "" -#: ../../library/asyncio-eventloop.rst:1286 -#: ../../library/asyncio-eventloop.rst:1298 -#: ../../library/asyncio-eventloop.rst:1310 +#: ../../library/asyncio-eventloop.rst:1291 +#: ../../library/asyncio-eventloop.rst:1303 +#: ../../library/asyncio-eventloop.rst:1315 msgid "" "the :const:`subprocess.DEVNULL` constant which indicates that the special :" "data:`os.devnull` file will be used" msgstr "" -#: ../../library/asyncio-eventloop.rst:1289 +#: ../../library/asyncio-eventloop.rst:1294 msgid "*stdout* can be any of these:" msgstr "" -#: ../../library/asyncio-eventloop.rst:1291 +#: ../../library/asyncio-eventloop.rst:1296 msgid "" "a file-like object representing a pipe to be connected to the subprocess's " "standard output stream using :meth:`~loop.connect_write_pipe`" msgstr "" -#: ../../library/asyncio-eventloop.rst:1301 +#: ../../library/asyncio-eventloop.rst:1306 msgid "*stderr* can be any of these:" msgstr "" -#: ../../library/asyncio-eventloop.rst:1303 +#: ../../library/asyncio-eventloop.rst:1308 msgid "" "a file-like object representing a pipe to be connected to the subprocess's " "standard error stream using :meth:`~loop.connect_write_pipe`" msgstr "" -#: ../../library/asyncio-eventloop.rst:1312 +#: ../../library/asyncio-eventloop.rst:1317 msgid "" "the :const:`subprocess.STDOUT` constant which will connect the standard " "error stream to the process' standard output stream" msgstr "" -#: ../../library/asyncio-eventloop.rst:1315 +#: ../../library/asyncio-eventloop.rst:1320 msgid "" "All other keyword arguments are passed to :class:`subprocess.Popen` without " "interpretation, except for *bufsize*, *universal_newlines*, *shell*, *text*, " "*encoding* and *errors*, which should not be specified at all." msgstr "" -#: ../../library/asyncio-eventloop.rst:1320 +#: ../../library/asyncio-eventloop.rst:1325 msgid "" "The ``asyncio`` subprocess API does not support decoding the streams as " "text. :func:`bytes.decode` can be used to convert the bytes returned from " "the stream to text." msgstr "" -#: ../../library/asyncio-eventloop.rst:1324 +#: ../../library/asyncio-eventloop.rst:1329 msgid "" "See the constructor of the :class:`subprocess.Popen` class for documentation " "on other arguments." msgstr "" -#: ../../library/asyncio-eventloop.rst:1327 +#: ../../library/asyncio-eventloop.rst:1332 msgid "" "Returns a pair of ``(transport, protocol)``, where *transport* conforms to " "the :class:`asyncio.SubprocessTransport` base class and *protocol* is an " "object instantiated by the *protocol_factory*." msgstr "" -#: ../../library/asyncio-eventloop.rst:1335 +#: ../../library/asyncio-eventloop.rst:1340 msgid "" "Create a subprocess from *cmd*, which can be a :class:`str` or a :class:" "`bytes` string encoded to the :ref:`filesystem encoding `, using the platform's \"shell\" syntax." msgstr "" -#: ../../library/asyncio-eventloop.rst:1340 +#: ../../library/asyncio-eventloop.rst:1345 msgid "" "This is similar to the standard library :class:`subprocess.Popen` class " "called with ``shell=True``." msgstr "" -#: ../../library/asyncio-eventloop.rst:1343 +#: ../../library/asyncio-eventloop.rst:1348 msgid "" "The *protocol_factory* must be a callable returning a subclass of the :class:" "`SubprocessProtocol` class." msgstr "" -#: ../../library/asyncio-eventloop.rst:1346 +#: ../../library/asyncio-eventloop.rst:1351 msgid "" "See :meth:`~loop.subprocess_exec` for more details about the remaining " "arguments." msgstr "" -#: ../../library/asyncio-eventloop.rst:1349 +#: ../../library/asyncio-eventloop.rst:1354 msgid "" "Returns a pair of ``(transport, protocol)``, where *transport* conforms to " "the :class:`SubprocessTransport` base class and *protocol* is an object " "instantiated by the *protocol_factory*." msgstr "" -#: ../../library/asyncio-eventloop.rst:1354 +#: ../../library/asyncio-eventloop.rst:1359 msgid "" "It is the application's responsibility to ensure that all whitespace and " "special characters are quoted appropriately to avoid `shell injection " @@ -1739,105 +1747,105 @@ msgid "" "used to construct shell commands." msgstr "" -#: ../../library/asyncio-eventloop.rst:1363 +#: ../../library/asyncio-eventloop.rst:1368 msgid "Callback Handles" msgstr "" -#: ../../library/asyncio-eventloop.rst:1367 +#: ../../library/asyncio-eventloop.rst:1372 msgid "" "A callback wrapper object returned by :meth:`loop.call_soon`, :meth:`loop." "call_soon_threadsafe`." msgstr "" -#: ../../library/asyncio-eventloop.rst:1372 +#: ../../library/asyncio-eventloop.rst:1377 msgid "" "Cancel the callback. If the callback has already been canceled or executed, " "this method has no effect." msgstr "" -#: ../../library/asyncio-eventloop.rst:1377 +#: ../../library/asyncio-eventloop.rst:1382 msgid "Return ``True`` if the callback was cancelled." msgstr "" -#: ../../library/asyncio-eventloop.rst:1383 +#: ../../library/asyncio-eventloop.rst:1388 msgid "" "A callback wrapper object returned by :meth:`loop.call_later`, and :meth:" "`loop.call_at`." msgstr "" -#: ../../library/asyncio-eventloop.rst:1386 +#: ../../library/asyncio-eventloop.rst:1391 msgid "This class is a subclass of :class:`Handle`." msgstr "" -#: ../../library/asyncio-eventloop.rst:1390 +#: ../../library/asyncio-eventloop.rst:1395 msgid "Return a scheduled callback time as :class:`float` seconds." msgstr "" -#: ../../library/asyncio-eventloop.rst:1392 +#: ../../library/asyncio-eventloop.rst:1397 msgid "" "The time is an absolute timestamp, using the same time reference as :meth:" "`loop.time`." msgstr "" -#: ../../library/asyncio-eventloop.rst:1399 +#: ../../library/asyncio-eventloop.rst:1404 msgid "Server Objects" msgstr "" -#: ../../library/asyncio-eventloop.rst:1401 +#: ../../library/asyncio-eventloop.rst:1406 msgid "" "Server objects are created by :meth:`loop.create_server`, :meth:`loop." "create_unix_server`, :func:`start_server`, and :func:`start_unix_server` " "functions." msgstr "" -#: ../../library/asyncio-eventloop.rst:1405 +#: ../../library/asyncio-eventloop.rst:1410 msgid "Do not instantiate the class directly." msgstr "" -#: ../../library/asyncio-eventloop.rst:1409 +#: ../../library/asyncio-eventloop.rst:1414 msgid "" "*Server* objects are asynchronous context managers. When used in an ``async " "with`` statement, it's guaranteed that the Server object is closed and not " "accepting new connections when the ``async with`` statement is completed::" msgstr "" -#: ../../library/asyncio-eventloop.rst:1422 +#: ../../library/asyncio-eventloop.rst:1427 msgid "Server object is an asynchronous context manager since Python 3.7." msgstr "" -#: ../../library/asyncio-eventloop.rst:1427 +#: ../../library/asyncio-eventloop.rst:1432 msgid "" "Stop serving: close listening sockets and set the :attr:`sockets` attribute " "to ``None``." msgstr "" -#: ../../library/asyncio-eventloop.rst:1430 +#: ../../library/asyncio-eventloop.rst:1435 msgid "" "The sockets that represent existing incoming client connections are left " "open." msgstr "" -#: ../../library/asyncio-eventloop.rst:1433 +#: ../../library/asyncio-eventloop.rst:1438 msgid "" "The server is closed asynchronously, use the :meth:`wait_closed` coroutine " "to wait until the server is closed." msgstr "" -#: ../../library/asyncio-eventloop.rst:1438 +#: ../../library/asyncio-eventloop.rst:1443 msgid "Return the event loop associated with the server object." msgstr "" -#: ../../library/asyncio-eventloop.rst:1444 +#: ../../library/asyncio-eventloop.rst:1449 msgid "Start accepting connections." msgstr "" -#: ../../library/asyncio-eventloop.rst:1446 +#: ../../library/asyncio-eventloop.rst:1451 msgid "" "This method is idempotent, so it can be called when the server is already " "being serving." msgstr "" -#: ../../library/asyncio-eventloop.rst:1449 +#: ../../library/asyncio-eventloop.rst:1454 msgid "" "The *start_serving* keyword-only parameter to :meth:`loop.create_server` " "and :meth:`asyncio.start_server` allows creating a Server object that is not " @@ -1846,97 +1854,97 @@ msgid "" "accepting connections." msgstr "" -#: ../../library/asyncio-eventloop.rst:1460 +#: ../../library/asyncio-eventloop.rst:1465 msgid "" "Start accepting connections until the coroutine is cancelled. Cancellation " "of ``serve_forever`` task causes the server to be closed." msgstr "" -#: ../../library/asyncio-eventloop.rst:1464 +#: ../../library/asyncio-eventloop.rst:1469 msgid "" "This method can be called if the server is already accepting connections. " "Only one ``serve_forever`` task can exist per one *Server* object." msgstr "" -#: ../../library/asyncio-eventloop.rst:1486 +#: ../../library/asyncio-eventloop.rst:1491 msgid "Return ``True`` if the server is accepting new connections." msgstr "" -#: ../../library/asyncio-eventloop.rst:1492 +#: ../../library/asyncio-eventloop.rst:1497 msgid "Wait until the :meth:`close` method completes." msgstr "" -#: ../../library/asyncio-eventloop.rst:1496 +#: ../../library/asyncio-eventloop.rst:1501 msgid "List of :class:`socket.socket` objects the server is listening on." msgstr "" -#: ../../library/asyncio-eventloop.rst:1498 +#: ../../library/asyncio-eventloop.rst:1503 msgid "" "Prior to Python 3.7 ``Server.sockets`` used to return an internal list of " "server sockets directly. In 3.7 a copy of that list is returned." msgstr "" -#: ../../library/asyncio-eventloop.rst:1507 +#: ../../library/asyncio-eventloop.rst:1512 msgid "Event Loop Implementations" msgstr "" -#: ../../library/asyncio-eventloop.rst:1509 +#: ../../library/asyncio-eventloop.rst:1514 msgid "" "asyncio ships with two different event loop implementations: :class:" "`SelectorEventLoop` and :class:`ProactorEventLoop`." msgstr "" -#: ../../library/asyncio-eventloop.rst:1512 +#: ../../library/asyncio-eventloop.rst:1517 msgid "" "By default asyncio is configured to use :class:`SelectorEventLoop` on Unix " "and :class:`ProactorEventLoop` on Windows." msgstr "" -#: ../../library/asyncio-eventloop.rst:1518 +#: ../../library/asyncio-eventloop.rst:1523 msgid "An event loop based on the :mod:`selectors` module." msgstr "" -#: ../../library/asyncio-eventloop.rst:1520 +#: ../../library/asyncio-eventloop.rst:1525 msgid "" "Uses the most efficient *selector* available for the given platform. It is " "also possible to manually configure the exact selector implementation to be " "used::" msgstr "" -#: ../../library/asyncio-eventloop.rst:1532 +#: ../../library/asyncio-eventloop.rst:1537 msgid ":ref:`Availability `: Unix, Windows." msgstr ":ref:`適用 `:Unix、Windows。" -#: ../../library/asyncio-eventloop.rst:1537 +#: ../../library/asyncio-eventloop.rst:1542 msgid "An event loop for Windows that uses \"I/O Completion Ports\" (IOCP)." msgstr "" -#: ../../library/asyncio-eventloop.rst:1540 +#: ../../library/asyncio-eventloop.rst:1545 msgid ":ref:`Availability `: Windows." msgstr ":ref:`適用 `:Windows。" -#: ../../library/asyncio-eventloop.rst:1543 +#: ../../library/asyncio-eventloop.rst:1548 msgid "" "`MSDN documentation on I/O Completion Ports `_." msgstr "" -#: ../../library/asyncio-eventloop.rst:1549 +#: ../../library/asyncio-eventloop.rst:1554 msgid "Abstract base class for asyncio-compliant event loops." msgstr "" -#: ../../library/asyncio-eventloop.rst:1551 +#: ../../library/asyncio-eventloop.rst:1556 msgid "" "The :ref:`Event Loop Methods ` section lists all methods " "that an alternative implementation of ``AbstractEventLoop`` should have " "defined." msgstr "" -#: ../../library/asyncio-eventloop.rst:1557 +#: ../../library/asyncio-eventloop.rst:1562 msgid "Examples" msgstr "範例" -#: ../../library/asyncio-eventloop.rst:1559 +#: ../../library/asyncio-eventloop.rst:1564 msgid "" "Note that all examples in this section **purposefully** show how to use the " "low-level event loop APIs, such as :meth:`loop.run_forever` and :meth:`loop." @@ -1944,70 +1952,70 @@ msgid "" "consider using the high-level functions like :func:`asyncio.run`." msgstr "" -#: ../../library/asyncio-eventloop.rst:1569 +#: ../../library/asyncio-eventloop.rst:1574 msgid "Hello World with call_soon()" msgstr "" -#: ../../library/asyncio-eventloop.rst:1571 +#: ../../library/asyncio-eventloop.rst:1576 msgid "" "An example using the :meth:`loop.call_soon` method to schedule a callback. " "The callback displays ``\"Hello World\"`` and then stops the event loop::" msgstr "" -#: ../../library/asyncio-eventloop.rst:1595 +#: ../../library/asyncio-eventloop.rst:1600 msgid "" "A similar :ref:`Hello World ` example created with a coroutine " "and the :func:`run` function." msgstr "" -#: ../../library/asyncio-eventloop.rst:1602 +#: ../../library/asyncio-eventloop.rst:1607 msgid "Display the current date with call_later()" msgstr "" -#: ../../library/asyncio-eventloop.rst:1604 +#: ../../library/asyncio-eventloop.rst:1609 msgid "" "An example of a callback displaying the current date every second. The " "callback uses the :meth:`loop.call_later` method to reschedule itself after " "5 seconds, and then stops the event loop::" msgstr "" -#: ../../library/asyncio-eventloop.rst:1632 +#: ../../library/asyncio-eventloop.rst:1637 msgid "" "A similar :ref:`current date ` example created with a " "coroutine and the :func:`run` function." msgstr "" -#: ../../library/asyncio-eventloop.rst:1639 +#: ../../library/asyncio-eventloop.rst:1644 msgid "Watch a file descriptor for read events" msgstr "" -#: ../../library/asyncio-eventloop.rst:1641 +#: ../../library/asyncio-eventloop.rst:1646 msgid "" "Wait until a file descriptor received some data using the :meth:`loop." "add_reader` method and then close the event loop::" msgstr "" -#: ../../library/asyncio-eventloop.rst:1679 +#: ../../library/asyncio-eventloop.rst:1684 msgid "" "A similar :ref:`example ` using " "transports, protocols, and the :meth:`loop.create_connection` method." msgstr "" -#: ../../library/asyncio-eventloop.rst:1683 +#: ../../library/asyncio-eventloop.rst:1688 msgid "" "Another similar :ref:`example ` " "using the high-level :func:`asyncio.open_connection` function and streams." msgstr "" -#: ../../library/asyncio-eventloop.rst:1691 +#: ../../library/asyncio-eventloop.rst:1696 msgid "Set signal handlers for SIGINT and SIGTERM" msgstr "" -#: ../../library/asyncio-eventloop.rst:1693 +#: ../../library/asyncio-eventloop.rst:1698 msgid "(This ``signals`` example only works on Unix.)" msgstr "" -#: ../../library/asyncio-eventloop.rst:1695 +#: ../../library/asyncio-eventloop.rst:1700 msgid "" "Register handlers for signals :py:data:`SIGINT` and :py:data:`SIGTERM` using " "the :meth:`loop.add_signal_handler` method::" diff --git a/library/contextlib.po b/library/contextlib.po index 79c1bd27b9..cb68cfe730 100644 --- a/library/contextlib.po +++ b/library/contextlib.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.10\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-10-26 16:47+0000\n" +"POT-Creation-Date: 2021-11-25 17:41+0000\n" "PO-Revision-Date: 2018-05-23 14:41+0000\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" @@ -147,7 +147,7 @@ msgid "" "as decorators or with :keyword:`async with` statements::" msgstr "" -#: ../../library/contextlib.rst:145 +#: ../../library/contextlib.rst:147 msgid "" "When used as a decorator, a new generator instance is implicitly created on " "each function call. This allows the otherwise \"one-shot\" context managers " @@ -155,42 +155,42 @@ msgid "" "managers support multiple invocations in order to be used as decorators." msgstr "" -#: ../../library/contextlib.rst:150 +#: ../../library/contextlib.rst:152 msgid "" "Async context managers created with :func:`asynccontextmanager` can be used " "as decorators." msgstr "" -#: ../../library/contextlib.rst:157 +#: ../../library/contextlib.rst:159 msgid "" "Return a context manager that closes *thing* upon completion of the block. " "This is basically equivalent to::" msgstr "" -#: ../../library/contextlib.rst:169 +#: ../../library/contextlib.rst:171 msgid "And lets you write code like this::" msgstr "" -#: ../../library/contextlib.rst:178 +#: ../../library/contextlib.rst:180 msgid "" "without needing to explicitly close ``page``. Even if an error occurs, " "``page.close()`` will be called when the :keyword:`with` block is exited." msgstr "" -#: ../../library/contextlib.rst:184 +#: ../../library/contextlib.rst:186 msgid "" "Return an async context manager that calls the ``aclose()`` method of " "*thing* upon completion of the block. This is basically equivalent to::" msgstr "" -#: ../../library/contextlib.rst:196 +#: ../../library/contextlib.rst:198 msgid "" "Significantly, ``aclosing()`` supports deterministic cleanup of async " "generators when they happen to exit early by :keyword:`break` or an " "exception. For example::" msgstr "" -#: ../../library/contextlib.rst:207 +#: ../../library/contextlib.rst:209 msgid "" "This pattern ensures that the generator's async exit code is executed in the " "same context as its iterations (so that exceptions and context variables " @@ -198,31 +198,31 @@ msgid "" "task it depends on)." msgstr "" -#: ../../library/contextlib.rst:219 +#: ../../library/contextlib.rst:221 msgid "" "Return a context manager that returns *enter_result* from ``__enter__``, but " "otherwise does nothing. It is intended to be used as a stand-in for an " "optional context manager, for example::" msgstr "" -#: ../../library/contextlib.rst:233 +#: ../../library/contextlib.rst:235 msgid "An example using *enter_result*::" msgstr "" "一個使用 *enter_result* 的範例:\n" "\n" "::" -#: ../../library/contextlib.rst:246 +#: ../../library/contextlib.rst:248 msgid "" "It can also be used as a stand-in for :ref:`asynchronous context managers " "`::" msgstr "" -#: ../../library/contextlib.rst:262 +#: ../../library/contextlib.rst:264 msgid ":term:`asynchronous context manager` support was added." msgstr "" -#: ../../library/contextlib.rst:269 +#: ../../library/contextlib.rst:271 msgid "" "Return a context manager that suppresses any of the specified exceptions if " "they occur in the body of a :keyword:`!with` statement and then resumes " @@ -230,7 +230,7 @@ msgid "" "statement." msgstr "" -#: ../../library/contextlib.rst:274 +#: ../../library/contextlib.rst:276 msgid "" "As with any other mechanism that completely suppresses exceptions, this " "context manager should be used only to cover very specific errors where " @@ -238,35 +238,35 @@ msgid "" "do." msgstr "" -#: ../../library/contextlib.rst:279 +#: ../../library/contextlib.rst:281 msgid "For example::" msgstr "" "舉例來說:\n" "\n" "::" -#: ../../library/contextlib.rst:289 +#: ../../library/contextlib.rst:291 msgid "This code is equivalent to::" msgstr "" -#: ../../library/contextlib.rst:301 ../../library/contextlib.rst:341 -#: ../../library/contextlib.rst:351 +#: ../../library/contextlib.rst:303 ../../library/contextlib.rst:343 +#: ../../library/contextlib.rst:353 msgid "This context manager is :ref:`reentrant `." msgstr "" -#: ../../library/contextlib.rst:308 +#: ../../library/contextlib.rst:310 msgid "" "Context manager for temporarily redirecting :data:`sys.stdout` to another " "file or file-like object." msgstr "" -#: ../../library/contextlib.rst:311 +#: ../../library/contextlib.rst:313 msgid "" "This tool adds flexibility to existing functions or classes whose output is " "hardwired to stdout." msgstr "" -#: ../../library/contextlib.rst:314 +#: ../../library/contextlib.rst:316 msgid "" "For example, the output of :func:`help` normally is sent to *sys.stdout*. " "You can capture that output in a string by redirecting the output to an :" @@ -275,17 +275,17 @@ msgid "" "`with` statement::" msgstr "" -#: ../../library/contextlib.rst:324 +#: ../../library/contextlib.rst:326 msgid "" "To send the output of :func:`help` to a file on disk, redirect the output to " "a regular file::" msgstr "" -#: ../../library/contextlib.rst:331 +#: ../../library/contextlib.rst:333 msgid "To send the output of :func:`help` to *sys.stderr*::" msgstr "" -#: ../../library/contextlib.rst:336 +#: ../../library/contextlib.rst:338 msgid "" "Note that the global side effect on :data:`sys.stdout` means that this " "context manager is not suitable for use in library code and most threaded " @@ -293,59 +293,59 @@ msgid "" "it is still a useful approach for many utility scripts." msgstr "" -#: ../../library/contextlib.rst:348 +#: ../../library/contextlib.rst:350 msgid "" "Similar to :func:`~contextlib.redirect_stdout` but redirecting :data:`sys." "stderr` to another file or file-like object." msgstr "" -#: ../../library/contextlib.rst:358 +#: ../../library/contextlib.rst:360 msgid "" "A base class that enables a context manager to also be used as a decorator." msgstr "" -#: ../../library/contextlib.rst:360 +#: ../../library/contextlib.rst:362 msgid "" "Context managers inheriting from ``ContextDecorator`` have to implement " "``__enter__`` and ``__exit__`` as normal. ``__exit__`` retains its optional " "exception handling even when used as a decorator." msgstr "" -#: ../../library/contextlib.rst:364 +#: ../../library/contextlib.rst:366 msgid "" "``ContextDecorator`` is used by :func:`contextmanager`, so you get this " "functionality automatically." msgstr "" -#: ../../library/contextlib.rst:367 +#: ../../library/contextlib.rst:369 msgid "Example of ``ContextDecorator``::" msgstr "" "``ContextDecorator`` 範例:\n" "\n" "::" -#: ../../library/contextlib.rst:396 +#: ../../library/contextlib.rst:398 msgid "" "This change is just syntactic sugar for any construct of the following form::" msgstr "" -#: ../../library/contextlib.rst:402 +#: ../../library/contextlib.rst:404 msgid "``ContextDecorator`` lets you instead write::" msgstr "" -#: ../../library/contextlib.rst:408 +#: ../../library/contextlib.rst:410 msgid "" "It makes it clear that the ``cm`` applies to the whole function, rather than " "just a piece of it (and saving an indentation level is nice, too)." msgstr "" -#: ../../library/contextlib.rst:411 +#: ../../library/contextlib.rst:413 msgid "" "Existing context managers that already have a base class can be extended by " "using ``ContextDecorator`` as a mixin class::" msgstr "" -#: ../../library/contextlib.rst:424 +#: ../../library/contextlib.rst:426 msgid "" "As the decorated function must be able to be called multiple times, the " "underlying context manager must support use in multiple :keyword:`with` " @@ -353,32 +353,32 @@ msgid "" "explicit :keyword:`!with` statement inside the function should be used." msgstr "" -#: ../../library/contextlib.rst:434 +#: ../../library/contextlib.rst:436 msgid "" "Similar to :class:`ContextDecorator` but only for asynchronous functions." msgstr "" -#: ../../library/contextlib.rst:436 +#: ../../library/contextlib.rst:438 msgid "Example of ``AsyncContextDecorator``::" msgstr "" "``AsyncContextDecorator`` 範例:\n" "\n" "::" -#: ../../library/contextlib.rst:473 +#: ../../library/contextlib.rst:475 msgid "" "A context manager that is designed to make it easy to programmatically " "combine other context managers and cleanup functions, especially those that " "are optional or otherwise driven by input data." msgstr "" -#: ../../library/contextlib.rst:477 +#: ../../library/contextlib.rst:479 msgid "" "For example, a set of files may easily be handled in a single with statement " "as follows::" msgstr "" -#: ../../library/contextlib.rst:486 +#: ../../library/contextlib.rst:488 msgid "" "Each instance maintains a stack of registered callbacks that are called in " "reverse order when the instance is closed (either explicitly or implicitly " @@ -386,14 +386,14 @@ msgid "" "invoked implicitly when the context stack instance is garbage collected." msgstr "" -#: ../../library/contextlib.rst:491 +#: ../../library/contextlib.rst:493 msgid "" "This stack model is used so that context managers that acquire their " "resources in their ``__init__`` method (such as file objects) can be handled " "correctly." msgstr "" -#: ../../library/contextlib.rst:495 +#: ../../library/contextlib.rst:497 msgid "" "Since registered callbacks are invoked in the reverse order of registration, " "this ends up behaving as if multiple nested :keyword:`with` statements had " @@ -403,7 +403,7 @@ msgid "" "updated state." msgstr "" -#: ../../library/contextlib.rst:502 +#: ../../library/contextlib.rst:504 msgid "" "This is a relatively low level API that takes care of the details of " "correctly unwinding the stack of exit callbacks. It provides a suitable " @@ -411,68 +411,68 @@ msgid "" "in application specific ways." msgstr "" -#: ../../library/contextlib.rst:511 +#: ../../library/contextlib.rst:513 msgid "" "Enters a new context manager and adds its :meth:`__exit__` method to the " "callback stack. The return value is the result of the context manager's own :" "meth:`__enter__` method." msgstr "" -#: ../../library/contextlib.rst:515 +#: ../../library/contextlib.rst:517 msgid "" "These context managers may suppress exceptions just as they normally would " "if used directly as part of a :keyword:`with` statement." msgstr "" -#: ../../library/contextlib.rst:520 +#: ../../library/contextlib.rst:522 msgid "Adds a context manager's :meth:`__exit__` method to the callback stack." msgstr "" -#: ../../library/contextlib.rst:522 +#: ../../library/contextlib.rst:524 msgid "" "As ``__enter__`` is *not* invoked, this method can be used to cover part of " "an :meth:`__enter__` implementation with a context manager's own :meth:" "`__exit__` method." msgstr "" -#: ../../library/contextlib.rst:526 +#: ../../library/contextlib.rst:528 msgid "" "If passed an object that is not a context manager, this method assumes it is " "a callback with the same signature as a context manager's :meth:`__exit__` " "method and adds it directly to the callback stack." msgstr "" -#: ../../library/contextlib.rst:530 +#: ../../library/contextlib.rst:532 msgid "" "By returning true values, these callbacks can suppress exceptions the same " "way context manager :meth:`__exit__` methods can." msgstr "" -#: ../../library/contextlib.rst:533 +#: ../../library/contextlib.rst:535 msgid "" "The passed in object is returned from the function, allowing this method to " "be used as a function decorator." msgstr "" -#: ../../library/contextlib.rst:538 +#: ../../library/contextlib.rst:540 msgid "" "Accepts an arbitrary callback function and arguments and adds it to the " "callback stack." msgstr "" -#: ../../library/contextlib.rst:541 +#: ../../library/contextlib.rst:543 msgid "" "Unlike the other methods, callbacks added this way cannot suppress " "exceptions (as they are never passed the exception details)." msgstr "" -#: ../../library/contextlib.rst:544 +#: ../../library/contextlib.rst:546 msgid "" "The passed in callback is returned from the function, allowing this method " "to be used as a function decorator." msgstr "" -#: ../../library/contextlib.rst:549 +#: ../../library/contextlib.rst:551 msgid "" "Transfers the callback stack to a fresh :class:`ExitStack` instance and " "returns it. No callbacks are invoked by this operation - instead, they will " @@ -480,70 +480,70 @@ msgid "" "at the end of a :keyword:`with` statement)." msgstr "" -#: ../../library/contextlib.rst:554 +#: ../../library/contextlib.rst:556 msgid "" "For example, a group of files can be opened as an \"all or nothing\" " "operation as follows::" msgstr "" -#: ../../library/contextlib.rst:568 +#: ../../library/contextlib.rst:570 msgid "" "Immediately unwinds the callback stack, invoking callbacks in the reverse " "order of registration. For any context managers and exit callbacks " "registered, the arguments passed in will indicate that no exception occurred." msgstr "" -#: ../../library/contextlib.rst:575 +#: ../../library/contextlib.rst:577 msgid "" "An :ref:`asynchronous context manager `, similar to :" "class:`ExitStack`, that supports combining both synchronous and asynchronous " "context managers, as well as having coroutines for cleanup logic." msgstr "" -#: ../../library/contextlib.rst:580 +#: ../../library/contextlib.rst:582 msgid "" "The :meth:`close` method is not implemented, :meth:`aclose` must be used " "instead." msgstr "" -#: ../../library/contextlib.rst:585 +#: ../../library/contextlib.rst:587 msgid "" "Similar to :meth:`enter_context` but expects an asynchronous context manager." msgstr "" -#: ../../library/contextlib.rst:590 +#: ../../library/contextlib.rst:592 msgid "" "Similar to :meth:`push` but expects either an asynchronous context manager " "or a coroutine function." msgstr "" -#: ../../library/contextlib.rst:595 +#: ../../library/contextlib.rst:597 msgid "Similar to :meth:`callback` but expects a coroutine function." msgstr "" -#: ../../library/contextlib.rst:599 +#: ../../library/contextlib.rst:601 msgid "Similar to :meth:`close` but properly handles awaitables." msgstr "" -#: ../../library/contextlib.rst:601 +#: ../../library/contextlib.rst:603 msgid "Continuing the example for :func:`asynccontextmanager`::" msgstr "" -#: ../../library/contextlib.rst:613 +#: ../../library/contextlib.rst:615 msgid "Examples and Recipes" msgstr "" -#: ../../library/contextlib.rst:615 +#: ../../library/contextlib.rst:617 msgid "" "This section describes some examples and recipes for making effective use of " "the tools provided by :mod:`contextlib`." msgstr "" -#: ../../library/contextlib.rst:620 +#: ../../library/contextlib.rst:622 msgid "Supporting a variable number of context managers" msgstr "" -#: ../../library/contextlib.rst:622 +#: ../../library/contextlib.rst:624 msgid "" "The primary use case for :class:`ExitStack` is the one given in the class " "documentation: supporting a variable number of context managers and other " @@ -553,18 +553,18 @@ msgid "" "of the context managers being optional::" msgstr "" -#: ../../library/contextlib.rst:637 +#: ../../library/contextlib.rst:639 msgid "" "As shown, :class:`ExitStack` also makes it quite easy to use :keyword:`with` " "statements to manage arbitrary resources that don't natively support the " "context management protocol." msgstr "" -#: ../../library/contextlib.rst:643 +#: ../../library/contextlib.rst:645 msgid "Catching exceptions from ``__enter__`` methods" msgstr "" -#: ../../library/contextlib.rst:645 +#: ../../library/contextlib.rst:647 msgid "" "It is occasionally desirable to catch exceptions from an ``__enter__`` " "method implementation, *without* inadvertently catching exceptions from the :" @@ -573,7 +573,7 @@ msgid "" "be separated slightly in order to allow this::" msgstr "" -#: ../../library/contextlib.rst:660 +#: ../../library/contextlib.rst:662 msgid "" "Actually needing to do this is likely to indicate that the underlying API " "should be providing a direct resource management interface for use with :" @@ -584,29 +584,29 @@ msgid "" "`with` statement." msgstr "" -#: ../../library/contextlib.rst:670 +#: ../../library/contextlib.rst:672 msgid "Cleaning up in an ``__enter__`` implementation" msgstr "" -#: ../../library/contextlib.rst:672 +#: ../../library/contextlib.rst:674 msgid "" "As noted in the documentation of :meth:`ExitStack.push`, this method can be " "useful in cleaning up an already allocated resource if later steps in the :" "meth:`__enter__` implementation fail." msgstr "" -#: ../../library/contextlib.rst:676 +#: ../../library/contextlib.rst:678 msgid "" "Here's an example of doing this for a context manager that accepts resource " "acquisition and release functions, along with an optional validation " "function, and maps them to the context management protocol::" msgstr "" -#: ../../library/contextlib.rst:716 +#: ../../library/contextlib.rst:718 msgid "Replacing any use of ``try-finally`` and flag variables" msgstr "" -#: ../../library/contextlib.rst:718 +#: ../../library/contextlib.rst:720 msgid "" "A pattern you will sometimes see is a ``try-finally`` statement with a flag " "variable to indicate whether or not the body of the ``finally`` clause " @@ -614,57 +614,57 @@ msgid "" "by using an ``except`` clause instead), it looks something like this::" msgstr "" -#: ../../library/contextlib.rst:732 +#: ../../library/contextlib.rst:734 msgid "" "As with any ``try`` statement based code, this can cause problems for " "development and review, because the setup code and the cleanup code can end " "up being separated by arbitrarily long sections of code." msgstr "" -#: ../../library/contextlib.rst:736 +#: ../../library/contextlib.rst:738 msgid "" ":class:`ExitStack` makes it possible to instead register a callback for " "execution at the end of a ``with`` statement, and then later decide to skip " "executing that callback::" msgstr "" -#: ../../library/contextlib.rst:748 +#: ../../library/contextlib.rst:750 msgid "" "This allows the intended cleanup up behaviour to be made explicit up front, " "rather than requiring a separate flag variable." msgstr "" -#: ../../library/contextlib.rst:751 +#: ../../library/contextlib.rst:753 msgid "" "If a particular application uses this pattern a lot, it can be simplified " "even further by means of a small helper class::" msgstr "" -#: ../../library/contextlib.rst:769 +#: ../../library/contextlib.rst:771 msgid "" "If the resource cleanup isn't already neatly bundled into a standalone " "function, then it is still possible to use the decorator form of :meth:" "`ExitStack.callback` to declare the resource cleanup in advance::" msgstr "" -#: ../../library/contextlib.rst:784 +#: ../../library/contextlib.rst:786 msgid "" "Due to the way the decorator protocol works, a callback function declared " "this way cannot take any parameters. Instead, any resources to be released " "must be accessed as closure variables." msgstr "" -#: ../../library/contextlib.rst:790 +#: ../../library/contextlib.rst:792 msgid "Using a context manager as a function decorator" msgstr "" -#: ../../library/contextlib.rst:792 +#: ../../library/contextlib.rst:794 msgid "" ":class:`ContextDecorator` makes it possible to use a context manager in both " "an ordinary ``with`` statement and also as a function decorator." msgstr "" -#: ../../library/contextlib.rst:795 +#: ../../library/contextlib.rst:797 msgid "" "For example, it is sometimes useful to wrap functions or groups of " "statements with a logger that can track the time of entry and time of exit. " @@ -673,15 +673,15 @@ msgid "" "in a single definition::" msgstr "" -#: ../../library/contextlib.rst:816 +#: ../../library/contextlib.rst:818 msgid "Instances of this class can be used as both a context manager::" msgstr "" -#: ../../library/contextlib.rst:822 +#: ../../library/contextlib.rst:824 msgid "And also as a function decorator::" msgstr "" -#: ../../library/contextlib.rst:829 +#: ../../library/contextlib.rst:831 msgid "" "Note that there is one additional limitation when using context managers as " "function decorators: there's no way to access the return value of :meth:" @@ -689,21 +689,21 @@ msgid "" "explicit ``with`` statement." msgstr "" -#: ../../library/contextlib.rst:837 +#: ../../library/contextlib.rst:839 msgid ":pep:`343` - The \"with\" statement" msgstr "" -#: ../../library/contextlib.rst:837 +#: ../../library/contextlib.rst:839 msgid "" "The specification, background, and examples for the Python :keyword:`with` " "statement." msgstr "" -#: ../../library/contextlib.rst:843 +#: ../../library/contextlib.rst:845 msgid "Single use, reusable and reentrant context managers" msgstr "" -#: ../../library/contextlib.rst:845 +#: ../../library/contextlib.rst:847 msgid "" "Most context managers are written in a way that means they can only be used " "effectively in a :keyword:`with` statement once. These single use context " @@ -711,32 +711,32 @@ msgid "" "them a second time will trigger an exception or otherwise not work correctly." msgstr "" -#: ../../library/contextlib.rst:851 +#: ../../library/contextlib.rst:853 msgid "" "This common limitation means that it is generally advisable to create " "context managers directly in the header of the :keyword:`with` statement " "where they are used (as shown in all of the usage examples above)." msgstr "" -#: ../../library/contextlib.rst:855 +#: ../../library/contextlib.rst:857 msgid "" "Files are an example of effectively single use context managers, since the " "first :keyword:`with` statement will close the file, preventing any further " "IO operations using that file object." msgstr "" -#: ../../library/contextlib.rst:859 +#: ../../library/contextlib.rst:861 msgid "" "Context managers created using :func:`contextmanager` are also single use " "context managers, and will complain about the underlying generator failing " "to yield if an attempt is made to use them a second time::" msgstr "" -#: ../../library/contextlib.rst:887 +#: ../../library/contextlib.rst:889 msgid "Reentrant context managers" msgstr "" -#: ../../library/contextlib.rst:889 +#: ../../library/contextlib.rst:891 msgid "" "More sophisticated context managers may be \"reentrant\". These context " "managers can not only be used in multiple :keyword:`with` statements, but " @@ -744,21 +744,21 @@ msgid "" "the same context manager." msgstr "" -#: ../../library/contextlib.rst:894 +#: ../../library/contextlib.rst:896 msgid "" ":class:`threading.RLock` is an example of a reentrant context manager, as " "are :func:`suppress` and :func:`redirect_stdout`. Here's a very simple " "example of reentrant use::" msgstr "" -#: ../../library/contextlib.rst:913 +#: ../../library/contextlib.rst:915 msgid "" "Real world examples of reentrancy are more likely to involve multiple " "functions calling each other and hence be far more complicated than this " "example." msgstr "" -#: ../../library/contextlib.rst:917 +#: ../../library/contextlib.rst:919 msgid "" "Note also that being reentrant is *not* the same thing as being thread " "safe. :func:`redirect_stdout`, for example, is definitely not thread safe, " @@ -766,11 +766,11 @@ msgid "" "stdout` to a different stream." msgstr "" -#: ../../library/contextlib.rst:926 +#: ../../library/contextlib.rst:928 msgid "Reusable context managers" msgstr "" -#: ../../library/contextlib.rst:928 +#: ../../library/contextlib.rst:930 msgid "" "Distinct from both single use and reentrant context managers are \"reusable" "\" context managers (or, to be completely explicit, \"reusable, but not " @@ -780,21 +780,21 @@ msgid "" "instance has already been used in a containing with statement." msgstr "" -#: ../../library/contextlib.rst:935 +#: ../../library/contextlib.rst:937 msgid "" ":class:`threading.Lock` is an example of a reusable, but not reentrant, " "context manager (for a reentrant lock, it is necessary to use :class:" "`threading.RLock` instead)." msgstr "" -#: ../../library/contextlib.rst:939 +#: ../../library/contextlib.rst:941 msgid "" "Another example of a reusable, but not reentrant, context manager is :class:" "`ExitStack`, as it invokes *all* currently registered callbacks when leaving " "any with statement, regardless of where those callbacks were added::" msgstr "" -#: ../../library/contextlib.rst:970 +#: ../../library/contextlib.rst:972 msgid "" "As the output from the example shows, reusing a single stack object across " "multiple with statements works correctly, but attempting to nest them will " @@ -802,7 +802,7 @@ msgid "" "which is unlikely to be desirable behaviour." msgstr "" -#: ../../library/contextlib.rst:975 +#: ../../library/contextlib.rst:977 msgid "" "Using separate :class:`ExitStack` instances instead of reusing a single " "instance avoids that problem::" diff --git a/library/dataclasses.po b/library/dataclasses.po index 6d290b2fdd..62370498b5 100644 --- a/library/dataclasses.po +++ b/library/dataclasses.po @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.10\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-10-26 16:47+0000\n" +"POT-Creation-Date: 2021-11-30 00:09+0000\n" "PO-Revision-Date: 2018-07-15 18:56+0800\n" "Last-Translator: \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" @@ -399,25 +399,42 @@ msgid "" "Converts the dataclass ``instance`` to a dict (by using the factory function " "``dict_factory``). Each dataclass is converted to a dict of its fields, as " "``name: value`` pairs. dataclasses, dicts, lists, and tuples are recursed " -"into. For example::" +"into. Other objects are copied with :func:`copy.deepcopy`." msgstr "" -#: ../../library/dataclasses.rst:344 ../../library/dataclasses.rst:358 -msgid "Raises :exc:`TypeError` if ``instance`` is not a dataclass instance." +#: ../../library/dataclasses.rst:330 +msgid "Example of using :func:`asdict` on nested dataclasses::" msgstr "" -#: ../../library/dataclasses.rst:348 +#: ../../library/dataclasses.rst:347 ../../library/dataclasses.rst:367 +msgid "To create a shallow copy, the following workaround may be used::" +msgstr "" + +#: ../../library/dataclasses.rst:351 +msgid "" +":func:`asdict` raises :exc:`TypeError` if ``instance`` is not a dataclass " +"instance." +msgstr "" + +#: ../../library/dataclasses.rst:356 msgid "" "Converts the dataclass ``instance`` to a tuple (by using the factory " "function ``tuple_factory``). Each dataclass is converted to a tuple of its " -"field values. dataclasses, dicts, lists, and tuples are recursed into." +"field values. dataclasses, dicts, lists, and tuples are recursed into. " +"Other objects are copied with :func:`copy.deepcopy`." msgstr "" -#: ../../library/dataclasses.rst:353 +#: ../../library/dataclasses.rst:362 msgid "Continuing from the previous example::" msgstr "" -#: ../../library/dataclasses.rst:362 +#: ../../library/dataclasses.rst:371 +msgid "" +":func:`astuple` raises :exc:`TypeError` if ``instance`` is not a dataclass " +"instance." +msgstr "" + +#: ../../library/dataclasses.rst:376 msgid "" "Creates a new dataclass with name ``cls_name``, fields as defined in " "``fields``, base classes as given in ``bases``, and initialized with a " @@ -429,7 +446,7 @@ msgid "" "have the same meaning as they do in :func:`dataclass`." msgstr "" -#: ../../library/dataclasses.rst:372 +#: ../../library/dataclasses.rst:386 msgid "" "This function is not strictly required, because any Python mechanism for " "creating a new class with ``__annotations__`` can then apply the :func:" @@ -437,11 +454,11 @@ msgid "" "provided as a convenience. For example::" msgstr "" -#: ../../library/dataclasses.rst:384 +#: ../../library/dataclasses.rst:398 msgid "Is equivalent to::" msgstr "" -#: ../../library/dataclasses.rst:397 +#: ../../library/dataclasses.rst:411 msgid "" "Creates a new object of the same type as ``instance``, replacing fields with " "values from ``changes``. If ``instance`` is not a Data Class, raises :exc:" @@ -449,27 +466,27 @@ msgid "" "`TypeError`." msgstr "" -#: ../../library/dataclasses.rst:402 +#: ../../library/dataclasses.rst:416 msgid "" "The newly returned object is created by calling the :meth:`__init__` method " "of the dataclass. This ensures that :meth:`__post_init__`, if present, is " "also called." msgstr "" -#: ../../library/dataclasses.rst:406 +#: ../../library/dataclasses.rst:420 msgid "" "Init-only variables without default values, if any exist, must be specified " "on the call to :func:`replace` so that they can be passed to :meth:" "`__init__` and :meth:`__post_init__`." msgstr "" -#: ../../library/dataclasses.rst:410 +#: ../../library/dataclasses.rst:424 msgid "" "It is an error for ``changes`` to contain any fields that are defined as " "having ``init=False``. A :exc:`ValueError` will be raised in this case." msgstr "" -#: ../../library/dataclasses.rst:414 +#: ../../library/dataclasses.rst:428 msgid "" "Be forewarned about how ``init=False`` fields work during a call to :func:" "`replace`. They are not copied from the source object, but rather are " @@ -480,24 +497,24 @@ msgid "" "instance copying." msgstr "" -#: ../../library/dataclasses.rst:425 +#: ../../library/dataclasses.rst:439 msgid "" "Return ``True`` if its parameter is a dataclass or an instance of one, " "otherwise return ``False``." msgstr "" -#: ../../library/dataclasses.rst:428 +#: ../../library/dataclasses.rst:442 msgid "" "If you need to know if a class is an instance of a dataclass (and not a " "dataclass itself), then add a further check for ``not isinstance(obj, " "type)``::" msgstr "" -#: ../../library/dataclasses.rst:437 +#: ../../library/dataclasses.rst:451 msgid "A sentinel value signifying a missing default or default_factory." msgstr "" -#: ../../library/dataclasses.rst:441 +#: ../../library/dataclasses.rst:455 msgid "" "A sentinel value used as a type annotation. Any fields after a pseudo-field " "with the type of :const:`KW_ONLY` are marked as keyword-only fields. Note " @@ -508,30 +525,30 @@ msgid "" "is instantiated." msgstr "" -#: ../../library/dataclasses.rst:450 +#: ../../library/dataclasses.rst:464 msgid "" "In this example, the fields ``y`` and ``z`` will be marked as keyword-only " "fields::" msgstr "" -#: ../../library/dataclasses.rst:461 +#: ../../library/dataclasses.rst:475 msgid "" "In a single dataclass, it is an error to specify more than one field whose " "type is :const:`KW_ONLY`." msgstr "" -#: ../../library/dataclasses.rst:466 +#: ../../library/dataclasses.rst:480 msgid "" "Raised when an implicitly defined :meth:`__setattr__` or :meth:`__delattr__` " "is called on a dataclass which was defined with ``frozen=True``. It is a " "subclass of :exc:`AttributeError`." msgstr "" -#: ../../library/dataclasses.rst:471 +#: ../../library/dataclasses.rst:485 msgid "Post-init processing" msgstr "" -#: ../../library/dataclasses.rst:473 +#: ../../library/dataclasses.rst:487 msgid "" "The generated :meth:`__init__` code will call a method named :meth:" "`__post_init__`, if :meth:`__post_init__` is defined on the class. It will " @@ -541,13 +558,13 @@ msgid "" "generated, then :meth:`__post_init__` will not automatically be called." msgstr "" -#: ../../library/dataclasses.rst:481 +#: ../../library/dataclasses.rst:495 msgid "" "Among other uses, this allows for initializing field values that depend on " "one or more other fields. For example::" msgstr "" -#: ../../library/dataclasses.rst:493 +#: ../../library/dataclasses.rst:507 msgid "" "The :meth:`__init__` method generated by :func:`dataclass` does not call " "base class :meth:`__init__` methods. If the base class has an :meth:" @@ -555,25 +572,25 @@ msgid "" "a :meth:`__post_init__` method::" msgstr "" -#: ../../library/dataclasses.rst:510 +#: ../../library/dataclasses.rst:524 msgid "" "Note, however, that in general the dataclass-generated :meth:`__init__` " "methods don't need to be called, since the derived dataclass will take care " "of initializing all fields of any base class that is a dataclass itself." msgstr "" -#: ../../library/dataclasses.rst:514 +#: ../../library/dataclasses.rst:528 msgid "" "See the section below on init-only variables for ways to pass parameters to :" "meth:`__post_init__`. Also see the warning about how :func:`replace` " "handles ``init=False`` fields." msgstr "" -#: ../../library/dataclasses.rst:519 +#: ../../library/dataclasses.rst:533 msgid "Class variables" msgstr "" -#: ../../library/dataclasses.rst:521 +#: ../../library/dataclasses.rst:535 msgid "" "One of two places where :func:`dataclass` actually inspects the type of a " "field is to determine if a field is a class variable as defined in :pep:" @@ -583,11 +600,11 @@ msgid "" "pseudo-fields are not returned by the module-level :func:`fields` function." msgstr "" -#: ../../library/dataclasses.rst:530 +#: ../../library/dataclasses.rst:544 msgid "Init-only variables" msgstr "" -#: ../../library/dataclasses.rst:532 +#: ../../library/dataclasses.rst:546 msgid "" "The other place where :func:`dataclass` inspects a type annotation is to " "determine if a field is an init-only variable. It does this by seeing if " @@ -599,23 +616,23 @@ msgid "" "`__post_init__` method. They are not otherwise used by dataclasses." msgstr "" -#: ../../library/dataclasses.rst:542 +#: ../../library/dataclasses.rst:556 msgid "" "For example, suppose a field will be initialized from a database, if a value " "is not provided when creating the class::" msgstr "" -#: ../../library/dataclasses.rst:557 +#: ../../library/dataclasses.rst:571 msgid "" "In this case, :func:`fields` will return :class:`Field` objects for ``i`` " "and ``j``, but not for ``database``." msgstr "" -#: ../../library/dataclasses.rst:561 +#: ../../library/dataclasses.rst:575 msgid "Frozen instances" msgstr "" -#: ../../library/dataclasses.rst:563 +#: ../../library/dataclasses.rst:577 msgid "" "It is not possible to create truly immutable Python objects. However, by " "passing ``frozen=True`` to the :meth:`dataclass` decorator you can emulate " @@ -624,18 +641,18 @@ msgid "" "`FrozenInstanceError` when invoked." msgstr "" -#: ../../library/dataclasses.rst:569 +#: ../../library/dataclasses.rst:583 msgid "" "There is a tiny performance penalty when using ``frozen=True``: :meth:" "`__init__` cannot use simple assignment to initialize fields, and must use :" "meth:`object.__setattr__`." msgstr "" -#: ../../library/dataclasses.rst:574 +#: ../../library/dataclasses.rst:588 msgid "Inheritance" msgstr "" -#: ../../library/dataclasses.rst:576 +#: ../../library/dataclasses.rst:590 msgid "" "When the dataclass is being created by the :meth:`dataclass` decorator, it " "looks through all of the class's base classes in reverse MRO (that is, " @@ -647,21 +664,21 @@ msgid "" "derived classes override base classes. An example::" msgstr "" -#: ../../library/dataclasses.rst:596 +#: ../../library/dataclasses.rst:610 msgid "" "The final list of fields is, in order, ``x``, ``y``, ``z``. The final type " "of ``x`` is ``int``, as specified in class ``C``." msgstr "" -#: ../../library/dataclasses.rst:599 +#: ../../library/dataclasses.rst:613 msgid "The generated :meth:`__init__` method for ``C`` will look like::" msgstr "" -#: ../../library/dataclasses.rst:604 +#: ../../library/dataclasses.rst:618 msgid "Re-ordering of keyword-only parameters in :meth:`__init__`" msgstr "" -#: ../../library/dataclasses.rst:606 +#: ../../library/dataclasses.rst:620 msgid "" "After the parameters needed for :meth:`__init__` are computed, any keyword-" "only parameters are moved to come after all regular (non-keyword-only) " @@ -669,41 +686,41 @@ msgid "" "implemented in Python: they must come after non-keyword-only parameters." msgstr "" -#: ../../library/dataclasses.rst:612 +#: ../../library/dataclasses.rst:626 msgid "" "In this example, ``Base.y``, ``Base.w``, and ``D.t`` are keyword-only " "fields, and ``Base.x`` and ``D.z`` are regular fields::" msgstr "" -#: ../../library/dataclasses.rst:627 +#: ../../library/dataclasses.rst:641 msgid "The generated :meth:`__init__` method for ``D`` will look like::" msgstr "" -#: ../../library/dataclasses.rst:631 +#: ../../library/dataclasses.rst:645 msgid "" "Note that the parameters have been re-ordered from how they appear in the " "list of fields: parameters derived from regular fields are followed by " "parameters derived from keyword-only fields." msgstr "" -#: ../../library/dataclasses.rst:635 +#: ../../library/dataclasses.rst:649 msgid "" "The relative ordering of keyword-only parameters is maintained in the re-" "ordered :meth:`__init__` parameter list." msgstr "" -#: ../../library/dataclasses.rst:640 +#: ../../library/dataclasses.rst:654 msgid "Default factory functions" msgstr "" -#: ../../library/dataclasses.rst:642 +#: ../../library/dataclasses.rst:656 msgid "" "If a :func:`field` specifies a ``default_factory``, it is called with zero " "arguments when a default value for the field is needed. For example, to " "create a new instance of a list, use::" msgstr "" -#: ../../library/dataclasses.rst:648 +#: ../../library/dataclasses.rst:662 msgid "" "If a field is excluded from :meth:`__init__` (using ``init=False``) and the " "field also specifies ``default_factory``, then the default factory function " @@ -711,31 +728,31 @@ msgid "" "happens because there is no other way to give the field an initial value." msgstr "" -#: ../../library/dataclasses.rst:655 +#: ../../library/dataclasses.rst:669 msgid "Mutable default values" msgstr "" -#: ../../library/dataclasses.rst:657 +#: ../../library/dataclasses.rst:671 msgid "" "Python stores default member variable values in class attributes. Consider " "this example, not using dataclasses::" msgstr "" -#: ../../library/dataclasses.rst:672 +#: ../../library/dataclasses.rst:686 msgid "" "Note that the two instances of class ``C`` share the same class variable " "``x``, as expected." msgstr "" -#: ../../library/dataclasses.rst:675 +#: ../../library/dataclasses.rst:689 msgid "Using dataclasses, *if* this code was valid::" msgstr "" -#: ../../library/dataclasses.rst:683 +#: ../../library/dataclasses.rst:697 msgid "it would generate code similar to::" msgstr "" -#: ../../library/dataclasses.rst:694 +#: ../../library/dataclasses.rst:708 msgid "" "This has the same issue as the original example using class ``C``. That is, " "two instances of class ``D`` that do not specify a value for ``x`` when " @@ -748,7 +765,7 @@ msgid "" "errors." msgstr "" -#: ../../library/dataclasses.rst:705 +#: ../../library/dataclasses.rst:719 msgid "" "Using default factory functions is a way to create new instances of mutable " "types as default values for fields::" diff --git a/reference/executionmodel.po b/reference/executionmodel.po index 09d5157a2d..32e6a7b855 100644 --- a/reference/executionmodel.po +++ b/reference/executionmodel.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.10\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-10-17 00:12+0000\n" +"POT-Creation-Date: 2021-11-26 09:04+0000\n" "PO-Revision-Date: 2018-05-23 16:17+0000\n" "Last-Translator: Adrian Liaw \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" @@ -62,30 +62,69 @@ msgid "" msgstr "" #: ../../reference/executionmodel.rst:59 +msgid "The following constructs bind names:" +msgstr "" + +#: ../../reference/executionmodel.rst:61 +msgid "formal parameters to functions," +msgstr "" + +#: ../../reference/executionmodel.rst:62 +msgid "class definitions," +msgstr "" + +#: ../../reference/executionmodel.rst:63 +msgid "function definitions," +msgstr "" + +#: ../../reference/executionmodel.rst:64 +msgid "assignment expressions," +msgstr "" + +#: ../../reference/executionmodel.rst:65 msgid "" -"The following constructs bind names: formal parameters to functions, :" -"keyword:`import` statements, class and function definitions (these bind the " -"class or function name in the defining block), and targets that are " -"identifiers if occurring in an assignment, :keyword:`for` loop header, or " -"after :keyword:`!as` in a :keyword:`with` statement or :keyword:`except` " -"clause. The :keyword:`!import` statement of the form ``from ... import *`` " -"binds all names defined in the imported module, except those beginning with " -"an underscore. This form may only be used at the module level." +":ref:`targets ` that are identifiers if occurring in an " +"assignment:" +msgstr "" + +#: ../../reference/executionmodel.rst:68 +msgid ":keyword:`for` loop header," msgstr "" #: ../../reference/executionmodel.rst:69 msgid "" +"after :keyword:`!as` in a :keyword:`with` statement, :keyword:`except` " +"clause or in the as-pattern in structural pattern matching," +msgstr "" + +#: ../../reference/executionmodel.rst:71 +msgid "in a capture pattern in structural pattern matching" +msgstr "" + +#: ../../reference/executionmodel.rst:73 +msgid ":keyword:`import` statements." +msgstr "" + +#: ../../reference/executionmodel.rst:75 +msgid "" +"The :keyword:`!import` statement of the form ``from ... import *`` binds all " +"names defined in the imported module, except those beginning with an " +"underscore. This form may only be used at the module level." +msgstr "" + +#: ../../reference/executionmodel.rst:79 +msgid "" "A target occurring in a :keyword:`del` statement is also considered bound " "for this purpose (though the actual semantics are to unbind the name)." msgstr "" -#: ../../reference/executionmodel.rst:72 +#: ../../reference/executionmodel.rst:82 msgid "" "Each assignment or import statement occurs within a block defined by a class " "or function definition or at the module level (the top-level code block)." msgstr "" -#: ../../reference/executionmodel.rst:77 +#: ../../reference/executionmodel.rst:87 msgid "" "If a name is bound in a block, it is a local variable of that block, unless " "declared as :keyword:`nonlocal` or :keyword:`global`. If a name is bound at " @@ -94,17 +133,17 @@ msgid "" "not defined there, it is a :dfn:`free variable`." msgstr "" -#: ../../reference/executionmodel.rst:83 +#: ../../reference/executionmodel.rst:93 msgid "" "Each occurrence of a name in the program text refers to the :dfn:`binding` " "of that name established by the following name resolution rules." msgstr "" -#: ../../reference/executionmodel.rst:89 +#: ../../reference/executionmodel.rst:99 msgid "Resolution of names" msgstr "" -#: ../../reference/executionmodel.rst:93 +#: ../../reference/executionmodel.rst:103 msgid "" "A :dfn:`scope` defines the visibility of a name within a block. If a local " "variable is defined in a block, its scope includes that block. If the " @@ -113,14 +152,14 @@ msgid "" "different binding for the name." msgstr "" -#: ../../reference/executionmodel.rst:101 +#: ../../reference/executionmodel.rst:111 msgid "" "When a name is used in a code block, it is resolved using the nearest " "enclosing scope. The set of all such scopes visible to a code block is " "called the block's :dfn:`environment`." msgstr "" -#: ../../reference/executionmodel.rst:109 +#: ../../reference/executionmodel.rst:119 msgid "" "When a name is not found at all, a :exc:`NameError` exception is raised. If " "the current scope is a function scope, and the name refers to a local " @@ -129,7 +168,7 @@ msgid "" "`UnboundLocalError` is a subclass of :exc:`NameError`." msgstr "" -#: ../../reference/executionmodel.rst:115 +#: ../../reference/executionmodel.rst:125 msgid "" "If a name binding operation occurs anywhere within a code block, all uses of " "the name within the block are treated as references to the current block. " @@ -140,7 +179,7 @@ msgid "" "the block for name binding operations." msgstr "" -#: ../../reference/executionmodel.rst:122 +#: ../../reference/executionmodel.rst:132 msgid "" "If the :keyword:`global` statement occurs within a block, all uses of the " "names specified in the statement refer to the bindings of those names in the " @@ -152,7 +191,7 @@ msgid "" "statement must precede all uses of the listed names." msgstr "" -#: ../../reference/executionmodel.rst:131 +#: ../../reference/executionmodel.rst:141 msgid "" "The :keyword:`global` statement has the same scope as a name binding " "operation in the same block. If the nearest enclosing scope for a free " @@ -160,7 +199,7 @@ msgid "" "global." msgstr "" -#: ../../reference/executionmodel.rst:137 +#: ../../reference/executionmodel.rst:147 msgid "" "The :keyword:`nonlocal` statement causes corresponding names to refer to " "previously bound variables in the nearest enclosing function scope. :exc:" @@ -168,13 +207,13 @@ msgid "" "any enclosing function scope." msgstr "" -#: ../../reference/executionmodel.rst:144 +#: ../../reference/executionmodel.rst:154 msgid "" "The namespace for a module is automatically created the first time a module " "is imported. The main module for a script is always called :mod:`__main__`." msgstr "" -#: ../../reference/executionmodel.rst:147 +#: ../../reference/executionmodel.rst:157 msgid "" "Class definition blocks and arguments to :func:`exec` and :func:`eval` are " "special in the context of name resolution. A class definition is an " @@ -188,11 +227,11 @@ msgid "" "that the following will fail::" msgstr "" -#: ../../reference/executionmodel.rst:165 +#: ../../reference/executionmodel.rst:175 msgid "Builtins and restricted execution" msgstr "" -#: ../../reference/executionmodel.rst:171 +#: ../../reference/executionmodel.rst:181 msgid "" "Users should not touch ``__builtins__``; it is strictly an implementation " "detail. Users wanting to override values in the builtins namespace should :" @@ -200,7 +239,7 @@ msgid "" "appropriately." msgstr "" -#: ../../reference/executionmodel.rst:176 +#: ../../reference/executionmodel.rst:186 msgid "" "The builtins namespace associated with the execution of a code block is " "actually found by looking up the name ``__builtins__`` in its global " @@ -211,17 +250,17 @@ msgid "" "`builtins` module itself." msgstr "" -#: ../../reference/executionmodel.rst:188 +#: ../../reference/executionmodel.rst:198 msgid "Interaction with dynamic features" msgstr "" -#: ../../reference/executionmodel.rst:190 +#: ../../reference/executionmodel.rst:200 msgid "" "Name resolution of free variables occurs at runtime, not at compile time. " "This means that the following code will print 42::" msgstr "" -#: ../../reference/executionmodel.rst:201 +#: ../../reference/executionmodel.rst:211 msgid "" "The :func:`eval` and :func:`exec` functions do not have access to the full " "environment for resolving names. Names may be resolved in the local and " @@ -232,11 +271,11 @@ msgid "" "for both." msgstr "" -#: ../../reference/executionmodel.rst:212 +#: ../../reference/executionmodel.rst:222 msgid "Exceptions" msgstr "例外" -#: ../../reference/executionmodel.rst:223 +#: ../../reference/executionmodel.rst:233 msgid "" "Exceptions are a means of breaking out of the normal flow of control of a " "code block in order to handle errors or other exceptional conditions. An " @@ -245,7 +284,7 @@ msgid "" "or indirectly invoked the code block where the error occurred." msgstr "" -#: ../../reference/executionmodel.rst:229 +#: ../../reference/executionmodel.rst:239 msgid "" "The Python interpreter raises an exception when it detects a run-time error " "(such as division by zero). A Python program can also explicitly raise an " @@ -256,7 +295,7 @@ msgid "" "exception occurred or not in the preceding code." msgstr "" -#: ../../reference/executionmodel.rst:239 +#: ../../reference/executionmodel.rst:249 msgid "" "Python uses the \"termination\" model of error handling: an exception " "handler can find out what happened and continue execution at an outer level, " @@ -264,7 +303,7 @@ msgid "" "(except by re-entering the offending piece of code from the top)." msgstr "" -#: ../../reference/executionmodel.rst:246 +#: ../../reference/executionmodel.rst:256 msgid "" "When an exception is not handled at all, the interpreter terminates " "execution of the program, or returns to its interactive main loop. In " @@ -272,7 +311,7 @@ msgid "" "`SystemExit`." msgstr "" -#: ../../reference/executionmodel.rst:250 +#: ../../reference/executionmodel.rst:260 msgid "" "Exceptions are identified by class instances. The :keyword:`except` clause " "is selected depending on the class of the instance: it must reference the " @@ -281,7 +320,7 @@ msgid "" "condition." msgstr "" -#: ../../reference/executionmodel.rst:257 +#: ../../reference/executionmodel.rst:267 msgid "" "Exception messages are not part of the Python API. Their contents may " "change from one version of Python to the next without warning and should not " @@ -289,17 +328,17 @@ msgid "" "interpreter." msgstr "" -#: ../../reference/executionmodel.rst:261 +#: ../../reference/executionmodel.rst:271 msgid "" "See also the description of the :keyword:`try` statement in section :ref:" "`try` and :keyword:`raise` statement in section :ref:`raise`." msgstr "" -#: ../../reference/executionmodel.rst:266 +#: ../../reference/executionmodel.rst:276 msgid "Footnotes" msgstr "註解" -#: ../../reference/executionmodel.rst:267 +#: ../../reference/executionmodel.rst:277 msgid "" "This limitation occurs because the code that is executed by these operations " "is not available at the time the module is compiled."