8000 [po] auto sync · python/python-docs-zh-cn@6922702 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6922702

Browse files
[po] auto sync
1 parent dda0868 commit 6922702

File tree

3 files changed

+157
-4
lines changed

3 files changed

+157
-4
lines changed

.stat.json

Lines changed: 1 addition & 1 deletion
< 10000 /div>
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"translation": "80.80%", "updated_at": "2025-01-11T15:56:00Z"}
1+
{"translation": "80.81%", "updated_at": "2025-01-12T01:20:04Z"}

c-api/arg.po

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,9 @@ msgid ""
512512
":meth:`~object.__complex__` to convert the Python object to the required "
513513
"type."
514514
msgstr ""
515+
"这些格式允许将 Python 数字或单个字符表示为 C 数字。 需要 :class:`int`, :class:`float` 或 "
516+
":class:`complex` 的格式还可以使用相应的特殊方法 :meth:`~object.__index__`, "
517+
":meth:`~object.__float__` 或 :meth:`~object.__complex__` 将 Python 对象转换为所需的类型。"
515518

516519
#: ../../c-api/arg.rst:238
517520
msgid ""
@@ -520,6 +523,8 @@ msgid ""
520523
" is done --- the most significant bits are silently truncated when the "
521524
"receiving field is too small to receive the value."
522525
msgstr ""
526+
"对于有符号整数格式,如果值超出了 C 类型的范围则会引发 :exc:`OverflowError`。 对于无符号整数格式,则不会进行取值范围检查 ---"
527+
" 当接受字段太小而无法接受值时将静默地截断最高有效位。"
523528

524529
#: ../../c-api/arg.rst:244
525530
msgid "``b`` (:class:`int`) [unsigned char]"
@@ -529,7 +534,7 @@ msgstr "``b`` (:class:`int`) [unsigned char]"
529534
msgid ""
530535
"Convert a nonnegative Python integer to an unsigned tiny integer, stored in "
531536
"a C :c:expr:`unsigned char`."
532-
msgstr ""
537+
msgstr "将一个非负的 Python 整数转换为无符号微整数,存储于 C :c:expr:`unsigned char` 中。"
533538

534539
#: ../../c-api/arg.rst:248 ../../c-api/arg.rst:627
535540
msgid "``B`` (:class:`int`) [unsigned char]"
@@ -539,7 +544,7 @@ msgstr "``B`` (:class:`int`) [unsigned char]"
539544
msgid ""
540545
"Convert a Python integer to a tiny integer without overflow checking, stored"
541546
" in a C :c:expr:`unsigned char`."
542-
msgstr ""
547+
msgstr "将一个 Python 整数转换为微整数并且不进行溢出检查,存储于 C :c:expr:`unsigned char` 中。"
543548

544549
#: ../../c-api/arg.rst:252 ../../c-api/arg.rst:621
545550
msgid "``h`` (:class:`int`) [short int]"
@@ -744,6 +749,9 @@ msgid ""
744749
"this second call, the *object* parameter will be ``NULL``; *address* will "
745750
"have the same value as in the original call."
746751
msgstr ""
752+
"如果 *converter* 返回 "
753+
":c:macro:`!Py_CLEANUP_SUPPORTED`,则如果参数解析最终失败它可能会再次被调用,以使转换器有机会释放已分配的任何内存。 "
754+
"在第二次调用中,*object* 形参将为 ``NULL``; *address* 将具有与原始调用相同的值。"
747755

748756
#: ../../c-api/arg.rst:345
749757
msgid ""

howto/logging-cookbook.po

Lines changed: 146 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ msgid ""
2323
msgstr ""
2424
"Project-Id-Version: Python 3.13\n"
2525
"Report-Msgid-Bugs-To: \n"
26-
"POT-Creation-Date: 2025-01-03 14:16+0000\n"
26+
"POT-Creation-Date: 2025-01-10 14:17+0000\n"
2727
"PO-Revision-Date: 2021-06-28 00:53+0000\n"
2828
"Last-Translator: Freesand Leo <yuqinju@163.com>, 2025\n"
2929
"Language-Team: Chinese (China) (https://app.transifex.com/python-doc/teams/5390/zh_CN/)\n"
@@ -3879,6 +3879,50 @@ msgid ""
38793879
" delay = random.random() * 2 + 0.5\n"
38803880
" time.sleep(delay)"
38813881
msgstr ""
3882+
"# sender.py\n"
3883+
"import json\n"
3884+
"import logging\n"
3885+
"import logging.handlers\n"
3886+
"import time\n"
3887+
"import random\n"
3888+
"\n"
3889+
"import pynng\n"
3890+
"\n"
3891+
"DEFAULT_ADDR = \"tcp://localhost:13232\"\n"
3892+
"\n"
3893+
"class NNGSocketHandler(logging.handlers.QueueHandler):\n"
3894+
"\n"
3895+
" def __init__(self, uri):\n"
3896+
" socket = pynng.Pub0(dial=uri, send_timeout=500)\n"
3897+
" super().__init__(socket)\n"
3898+
"\n"
3899+
" def enqueue(self, record):\n"
3900+
" # Send the record as UTF-8 encoded JSON\n"
3901+
" d = dict(record.__dict__)\n"
3902+
" data = json.dumps(d)\n"
3903+
" self.queue.send(data.encode('utf-8'))\n"
3904+
"\n"
3905+
" def close(self):\n"
3906+
" self.queue.close()\n"
3907+
"\n"
3908+
"logging.getLogger('pynng').propagate = False\n"
3909+
"handler = NNGSocketHandler(DEFAULT_ADDR)\n"
3910+
"# 确保进程 ID 在输出内容中\n"
3911+
"logging.basicConfig(level=logging.DEBUG,\n"
3912+
" handlers=[logging.StreamHandler(), handler],\n"
3913+
" format='%(levelname)-8s %(name)10s %(process)6s %(message)s')\n"
3914+
"levels = (logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR,\n"
3915+
" logging.CRITICAL)\n"
3916+
"logger_names = ('myapp', 'myapp.lib1', 'myapp.lib2')\n"
3917+
"msgno = 1\n"
3918+
"while True:\n"
3919+
" # 随机地选择日志记录器和层级并记录日志\n"
3920+
" level = random.choice(levels)\n"
3921+
" logger = logging.getLogger(random.choice(logger_names))\n"
3922+
" logger.log(level, 'Message no. %5d' % msgno)\n"
3923+
" msgno += 1\n"
3924+
" delay = random.random() * 2 + 0.5\n"
3925+
" time.sleep(delay)"
38823926

38833927
#: ../../howto/logging-cookbook.rst:2034
38843928
msgid ""
@@ -6328,6 +6372,46 @@ msgid ""
63286372
"if __name__ == '__main__':\n"
63296373
" sys.exit(main())"
63306374
msgstr ""
6375+
"import argparse\n"
6376+
"import importlib\n"
6377+
"import logging\n"
6378+
"import os\n"
6379+
"import sys\n"
6380+
"\n"
6381+
"def main(args=None):\n"
6382+
" scriptname = os.path.basename(__file__)\n"
6383+
" parser = argparse.ArgumentParser(scriptname)\n"
6384+
" levels = ('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL')\n"
6385+
" parser.add_argument('--log-level', default='INFO', choices=levels)\n"
6386+
" subparsers = parser.add_subparsers(dest='command',\n"
6387+
" F438 help='Available commands:')\n"
6388+
" start_cmd = subparsers.add_parser('start', help='Start a service')\n"
6389+
" start_cmd.add_argument('name', metavar='NAME',\n"
6390+
" help='Name of service to start')\n"
6391+
" stop_cmd = subparsers.add_parser('stop',\n"
6392+
" help='Stop one or more services')\n"
6393+
" stop_cmd.add_argument('names', metavar='NAME', nargs='+',\n"
6394+
" help='Name of service to stop')\n"
6395+
" restart_cmd = subparsers.add_parser('restart',\n"
6396+
" help='Restart one or more services')\n"
6397+
" restart_cmd.add_argument('names', metavar='NAME', nargs='+',\n"
6398+
" help='Name of service to restart')\n"
6399+
" options = parser.parse_args()\n"
6400+
" # 分发命令的代码可以全都放在此文件中。 只是出于演示目的,\n"
6401+
" # 我们将在单独的模块中实现每个命令。\n"
6402+
" try:\n"
6403+
" mod = importlib.import_module(options.command)\n"
6404+
" cmd = getattr(mod, 'command')\n"
6405+
" except (ImportError, AttributeError):\n"
6406+
" print('Unable to find the code for command \\'%s\\'' % options.command)\n"
6407+
" return 1\n"
6408+
" # 这里可以做得更为灵活并从文件或目录加载配置\n"
6409+
" logging.basicConfig(level=options.log_level,\n"
6410+
" format='%(levelname)s %(name)s %(message)s')\n"
6411+
" cmd(options)\n"
6412+
"\n"
6413+
"if __name__ == '__main__':\n"
6414+
" sys.exit(main())"
63316415

63326416
#: ../../howto/logging-cookbook.rst:3469
63336417
msgid ""
@@ -6898,6 +6982,67 @@ msgid ""
68986982
" sdata = ''.join(parts)\n"
68996983
" return f'{version} {asctime} {hostname} {appname} {procid} {msgid} {sdata} {msg}'"
69006984
msgstr ""
6985+
"import datetime\n"
6986+
"import logging.handlers\n"
6987+
"import re\n"
6988+
"import socket\n"
6989+
"import time\n"
6990+
"\n"
6991+
"class SysLogHandler5424(logging.handlers.SysLogHandler):\n"
6992< 10000 span class="diff-text-marker">+
"\n"
6993+
" tz_offset = re.compile(r'([+-]\\d{2})(\\d{2})$')\n"
6994+
" escaped = re.compile(r'([\\]\"\\\\])')\n"
6995+
"\n"
6996+
" def __init__(self, *args, **kwargs):\n"
6997+
" self.msgid = kwargs.pop('msgid', None)\n"
6998+
" self.appname = kwargs.pop('appname', None)\n"
6999+
" super().__init__(*args, **kwargs)\n"
7000+
"\n"
7001+
" def format(self, record):\n"
7002+
" version = 1\n"
7003+
" asctime = datetime.datetime.fromtimestamp(record.created).isoformat()\n"
7004+
" m = self.tz_offset.match(time.strftime('%z'))\n"
7005+
" has_offset = False\n"
7006+
" if m and time.timezone:\n"
7007+
" hrs, mins = m.groups()\n"
7008+
" if int(hrs) or int(mins):\n"
7009+
" has_offset = True\n"
7010+
" if not has_offset:\n"
7011+
" asctime += 'Z'\n"
7012+
" else:\n"
7013+
" asctime += f'{hrs}:{mins}'\n"
7014+
" try:\n"
7015+
" hostname = socket.gethostname()\n"
7016+
" except Exception:\n"
7017+
" hostname = '-'\n"
7018+
" appname = self.appname or '-'\n"
7019+
" procid = record.process\n"
7020+
" msgid = '-'\n"
7021+
" msg = super().format(record)\n"
7022+
" sdata = '-'\n"
7023+
" if hasattr(record, 'structured_data'):\n"
7024+
" sd = record.structured_data\n"
7025+
" # 这应当是一个字典,其中的键为 SD-ID 而值则为\n"
7026+
" # 将 PARAM-NAME 映射到 PARAM-VALUE 的字典\n"
7027+
" # (请参阅 RFC了解其含义)\n"
7028+
" # 这里没有错误检查 —— 它只是作为演示,你可以\n"
7029+
" # 调整此代码以在生产环境中使用\n"
7030+
" parts = []\n"
7031+
"\n"
7032+
" def replacer(m):\n"
7033+
" g = m.groups()\n"
7034+
" return '\\\\' + g[0]\n"
7035+
"\n"
7036+
" for sdid, dv in sd.items():\n"
7037+
" part = f'[{sdid}'\n"
7038+
" for k, v in dv.items():\n"
7039+
" s = str(v)\n"
7040+
" s = self.escaped.sub(replacer, s)\n"
7041+
" part += f' {k}=\"{s}\"'\n"
7042+
" part += ']'\n"
7043+
" parts.append(part)\n"
7044+
" sdata = ''.join(parts)\n"
7045+
" return f'{version} {asctime} {hostname} {appname} {procid} {msgid} {sdata} {msg}'"
69017046

69027047
#: ../../howto/logging-cookbook.rst:3901
69037048
msgid ""

0 commit comments

Comments
 (0)
0