# SOME DESCRIPTIVE TITLE. # Copyright (C) 2001-2025, Python Software Foundation # This file is distributed under the same license as the Python package. # FIRST AUTHOR , YEAR. # # Translators: # Rafael Fontenelle , 2025 # #, fuzzy msgid "" msgstr "" "Project-Id-Version: Python 3.12\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2025-07-25 16:03+0000\n" "PO-Revision-Date: 2025-07-18 19:57+0000\n" "Last-Translator: Rafael Fontenelle , 2025\n" "Language-Team: Chinese (China) (https://app.transifex.com/python-doc/teams/5390/zh_CN/)\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Language: zh_CN\n" "Plural-Forms: nplurals=1; plural=0;\n" #: ../../library/code.rst:2 msgid ":mod:`!code` --- Interpreter base classes" msgstr ":mod:`!code` --- 解释器基类" #: ../../library/code.rst:7 msgid "**Source code:** :source:`Lib/code.py`" msgstr "**源代码:** :source:`Lib/code.py`" #: ../../library/code.rst:11 msgid "" "The ``code`` module provides facilities to implement read-eval-print loops " "in Python. Two classes and convenience functions are included which can be " "used to build applications which provide an interactive interpreter prompt." msgstr "" "``code`` 模块提供了在 Python 中实现 read-eval-print " "循环的功能。它包含两个类和一些快捷功能,可用于构建提供交互式解释器的应用程序。" #: ../../library/code.rst:18 msgid "" "This class deals with parsing and interpreter state (the user's namespace); " "it does not deal with input buffering or prompting or input file naming (the" " filename is always passed in explicitly). The optional *locals* argument " "specifies the dictionary in which code will be executed; it defaults to a " "newly created dictionary with key ``'__name__'`` set to ``'__console__'`` " "and key ``'__doc__'`` set to ``None``." msgstr "" "这个类处理解析器和解释器状态(用户命名空间的);它不处理缓冲器、终端提示区或着输入文件名(文件名总是显示地传递)。可选的 *locals* " "参数指定一个字典,字典里面包含将在此类执行的代码;它默认创建新的字典,其键 ``'__name__'`` 设置为 ``'__console__'`` " ",键 ``'__doc__'`` 设置为 ``None`` 。" #: ../../library/code.rst:28 msgid "" "Closely emulate the behavior of the interactive Python interpreter. This " "class builds on :class:`InteractiveInterpreter` and adds prompting using the" " familiar ``sys.ps1`` and ``sys.ps2``, and input buffering." msgstr "" "尽可能模拟交互式 Python 解释器的行为。此类建立在 :class:`InteractiveInterpreter` 的基础上,使用熟悉的 " "``sys.ps1`` 和 ``sys.ps2`` 作为输入提示符,并有输入缓冲。" #: ../../library/code.rst:35 msgid "" "Convenience function to run a read-eval-print loop. This creates a new " "instance of :class:`InteractiveConsole` and sets *readfunc* to be used as " "the :meth:`InteractiveConsole.raw_input` method, if provided. If *local* is" " provided, it is passed to the :class:`InteractiveConsole` constructor for " "use as the default namespace for the interpreter loop. The " ":meth:`~InteractiveConsole.interact` method of the instance is then run with" " *banner* and *exitmsg* passed as the banner and exit message to use, if " "provided. The console object is discarded after use." msgstr "" "运行一个读取-求值-打印循环的便捷函数。 这会创建一个新的 :class:`InteractiveConsole` 实例并设置 *readfunc* " "作为 :meth:`InteractiveConsole.raw_input` 方法,如果有提供的话。 如果提供了 *local*,它将被传给 " ":class:`InteractiveConsole` 构造器以用作解析器循环的默认命名空间。 实例的 " ":meth:`~InteractiveConsole.interact` 方法将随后运行并传入 *banner* 和 *exitmsg* " "以用作标题和退出消息,如果有提供的话。 控制台对象在使用后将被丢弃。" #: ../../library/code.rst:44 msgid "Added *exitmsg* parameter." msgstr "加入 *exitmsg* 参数。" #: ../../library/code.rst:50 msgid "" "This function is useful for programs that want to emulate Python's " "interpreter main loop (a.k.a. the read-eval-print loop). The tricky part is" " to determine when the user has entered an incomplete command that can be " "completed by entering more text (as opposed to a complete command or a " "syntax error). This function *almost* always makes the same decision as the" " real interpreter main loop." msgstr "" "这个函数主要用来模拟 Python 解释器的主循环(即 read-eval-print " "循环)。难点的部分是当用户输入不完整命令时,判断能否通过之后的输入来完成(要么成为完整的命令,要么语法错误)。该函数 *几乎* " "和实际的解释器主循环的判断是相同的。" #: ../../library/code.rst:57 msgid "" "*source* is the source string; *filename* is the optional filename from " "which source was read, defaulting to ``''``; and *symbol* is the " "optional grammar start symbol, which should be ``'single'`` (the default), " "``'eval'`` or ``'exec'``." msgstr "" "*source* 是源字符串;*filename* 是可选的用作读取源的文件名,默认为 ``''``;*symbol* " "是可选的语法开启符号,应为 ``'single'`` (默认), ``'eval'`` 或 ``'exec'``。" #: ../../library/code.rst:62 msgid "" "Returns a code object (the same as ``compile(source, filename, symbol)``) if" " the command is complete and valid; ``None`` if the command is incomplete; " "raises :exc:`SyntaxError` if the command is complete and contains a syntax " "error, or raises :exc:`OverflowError` or :exc:`ValueError` if the command " "contains an invalid literal." msgstr "" "如果命令完整且有效则返回一个代码对象 (等价于 ``compile(source, filename, symbol)``);如果命令不完整则返回 " "``None``;如果命令完整但包含语法错误则会引发 :exc:`SyntaxError` 或 :exc:`OverflowError` " "而如果命令包含无效字面值则将引发 :exc:`ValueError`。" #: ../../library/code.rst:72 msgid "Interactive Interpreter Objects" msgstr "交互解释器对象" #: ../../library/code.rst:77 msgid "" "Compile and run some source in the interpreter. Arguments are the same as " "for :func:`compile_command`; the default for *filename* is ``''``, " "and for *symbol* is ``'single'``. One of several things can happen:" msgstr "" "在解释器中编译并运行一段源码。 所用参数与 :func:`compile_command` 一样;*filename* 的默认值为 " "``''``,*symbol* 则为 ``'single'``。 可能发生以下情况之一:" #: ../../library/code.rst:81 msgid "" "The input is incorrect; :func:`compile_command` raised an exception " "(:exc:`SyntaxError` or :exc:`OverflowError`). A syntax traceback will be " "printed by calling the :meth:`showsyntaxerror` method. :meth:`runsource` " "returns ``False``." msgstr "" "输入不正确;:func:`compile_command` 引发了一个异常 (:exc:`SyntaxError` 或 " ":exc:`OverflowError`)。 将通过调用 :meth:`showsyntaxerror` 方法打印语法回溯信息。 " ":meth:`runsource` 返回 ``False``。" #: ../../library/code.rst:86 msgid "" "The input is incomplete, and more input is required; :func:`compile_command`" " returned ``None``. :meth:`runsource` returns ``True``." msgstr "" "输入不完整,需要更多输入;函数 :func:`compile_command` 返回 ``None`` 。方法 :meth:`runsource` 返回" " ``True`` 。" #: ../../library/code.rst:89 msgid "" "The input is complete; :func:`compile_command` returned a code object. The " "code is executed by calling the :meth:`runcode` (which also handles run-time" " exceptions, except for :exc:`SystemExit`). :meth:`runsource` returns " "``False``." msgstr "" "输入完整;:func:`compile_command` 返回了一个代码对象。 将通过调用 :meth:`runcode` " "执行代码(该方法也会处理运行时异常,:exc:`SystemExit` 除外)。 :meth:`runsource` 返回 ``False``。" #: ../../library/code.rst:93 msgid "" "The return value can be used to decide whether to use ``sys.ps1`` or " "``sys.ps2`` to prompt the next line." msgstr "该返回值用于决定使用 ``sys.ps1`` 还是 ``sys.ps2`` 来作为下一行的输入提示符。" #: ../../library/code.rst:99 msgid "" "Execute a code object. When an exception occurs, :meth:`showtraceback` is " "called to display a traceback. All exceptions are caught except " ":exc:`SystemExit`, which is allowed to propagate." msgstr "" "执行一个代码对象。当发生异常时,调用 :meth:`showtraceback` 来显示回溯。除 :exc:`SystemExit` " "(允许传播)以外的所有异常都会被捕获。" #: ../../library/code.rst:103 msgid "" "A note about :exc:`KeyboardInterrupt`: this exception may occur elsewhere in" " this code, and may not always be caught. The caller should be prepared to " "deal with it." msgstr "" "有关 :exc:`KeyboardInterrupt` 的说明,该异常可能发生于此代码的其他位置,并且并不总能被捕获。 调用者应当准备好处理它。" #: ../../library/code.rst:110 msgid "" "Display the syntax error that just occurred. This does not display a stack " "trace because there isn't one for syntax errors. If *filename* is given, it " "is stuffed into the exception instead of the default filename provided by " "Python's parser, because it always uses ``''`` when reading from a " "string. The output is written by the :meth:`write` method." msgstr "" "显示刚发生的语法错误。 这不会显示堆栈回溯因为语法错误并无此种信息。 如果给出了 *filename*,它会被放入异常来替代 Python " "解析器所提供的默认文件名,因为它在从一个字符串读取时总是会使用 ``''``。 输出将由 :meth:`write` 方法来写入。" #: ../../library/code.rst:119 msgid "" "Display the exception that just occurred. We remove the first stack item " "because it is within the interpreter object implementation. The output is " "written by the :meth:`write` method." msgstr "显示刚发生的异常。 我们移除了第一个堆栈条目因为它从属于解释器对象的实现。 输出将由 :meth:`write` 方法来写入。" #: ../../library/code.rst:123 msgid "" "The full chained traceback is displayed instead of just the primary " "traceback." msgstr "将显示完整的链式回溯,而不只是主回溯。" #: ../../library/code.rst:129 msgid "" "Write a string to the standard error stream (``sys.stderr``). Derived " "classes should override this to provide the appropriate output handling as " "needed." msgstr "将一个字符串写入到标准错误流 (``sys.stderr``)。 所有派生类都应重写此方法以提供必要的正确输出处理。" #: ../../library/code.rst:136 msgid "Interactive Console Objects" msgstr "交互式控制台对象" #: ../../library/code.rst:138 msgid "" "The :class:`InteractiveConsole` class is a subclass of " ":class:`InteractiveInterpreter`, and so offers all the methods of the " "interpreter objects as well as the following additions." msgstr "" ":class:`InteractiveConsole` 类是 :class:`InteractiveInterpreter` " "的子类,因此它提供了解释器对象的所有方法,还有以下的额外方法。" #: ../../library/code.rst:145 msgid "" "Closely emulate the interactive Python console. The optional *banner* " "argument specify the banner to print before the first interaction; by " "default it prints a banner similar to the one printed by the standard Python" " interpreter, followed by the class name of the console object in " "parentheses (so as not to confuse this with the real interpreter -- since " "it's so close!)." msgstr "" "近似地模拟交互式 Python 终端。 可选的 *banner* 参数指定要在第一次交互前打印的条幅;默认情况下会类似于标准 Python " "解释器所打印的内容,并附上外加圆括号的终端对象类名(这样就不会与真正的解释器混淆 —— 因为确实太像了!)" #: ../../library/code.rst:151 msgid "" "The optional *exitmsg* argument specifies an exit message printed when " "exiting. Pass the empty string to suppress the exit message. If *exitmsg* is" " not given or ``None``, a default message is printed." msgstr "" "可选的 *exitmsg* 参数指定要在退出时打印的退出消息。 传入空字符串可以屏蔽退出消息。 如果 *exitmsg* 未给出或为 " "``None``,则将打印默认消息。" #: ../../library/code.rst:155 msgid "To suppress printing any banner, pass an empty string." msgstr "要禁止打印任何条幅消息,请传递一个空字符串。" #: ../../library/code.rst:158 msgid "Print an exit message when exiting." msgstr "退出时打印退出消息。" #: ../../library/code.rst:164 msgid "" "Push a line of source text to the interpreter. The line should not have a " "trailing newline; it may have internal newlines. The line is appended to a " "buffer and the interpreter's :meth:`~InteractiveInterpreter.runsource` " "method is called with the concatenated contents of the buffer as source. If" " this indicates that the command was executed or invalid, the buffer is " "reset; otherwise, the command is incomplete, and the buffer is left as it " "was after the line was appended. The return value is ``True`` if more input" " is required, ``False`` if the line was dealt with in some way (this is the " "same as :meth:`!runsource`)." msgstr "" "将一行源代码文本推入解释器。 行内容不应带有末尾换行符;它可以有内部换行符。 行内容会被添加到一缓冲区然后调用解释器的 " ":meth:`~InteractiveInterpreter.runsource` 方法并附带缓冲区内容的拼接结果作为源文本。 " "如果提示命令已执行或不合法,缓冲区将被重置;在其他情况下,则命令结束,缓冲区将在添加行后保持原样。 如果需要更多的输入则返回值为 " "``True``,如果行已按某种方式被处理则返回值为 ``False`` (这与 :meth:`!runsource` 相同)。" #: ../../library/code.rst:176 msgid "Remove any unhandled source text from the input buffer." msgstr "从输入缓冲区中删除所有未处理的内容。" #: ../../library/code.rst:181 msgid "" "Write a prompt and read a line. The returned line does not include the " "trailing newline. When the user enters the EOF key sequence, " ":exc:`EOFError` is raised. The base implementation reads from ``sys.stdin``;" " a subclass may replace this with a different implementation." msgstr "" "输出提示并读取一行。返回的行不包含末尾的换行符。当用户输入 EOF 键序列时,会引发 :exc:`EOFError` 异常。默认实现是从 " "``sys.stdin`` 读取;子类可以用其他实现代替。"