11# SOME DESCRIPTIVE TITLE.
2- # Copyright (C) 2001-2019, Python Software Foundation
2+ # Copyright (C) 2001 Python Software Foundation
33# This file is distributed under the same license as the Python package.
44# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
55#
66# Translators:
7- # oon arfiandwi <oon.arfiandwi@gmail.com>, 2019
7+ # oon arfiandwi <oon.arfiandwi@gmail.com>, 2021
8+ # Elmo <work.elmoallistair@gmail.com>, 2024
89#
910#, fuzzy
1011msgid ""
1112msgstr ""
12- "Project-Id-Version : Python 3.8 \n "
13+ "Project-Id-Version : Python 3.14 \n "
1314"Report-Msgid-Bugs-To : \n "
14- "POT-Creation-Date : 2019-09-01 14:24 +0000\n "
15- "PO-Revision-Date : 2018 -06-29 21:06 +0000\n "
16- "Last-Translator : oon arfiandwi <oon.arfiandwi @gmail.com>, 2019 \n "
17- "Language-Team : Indonesian (https://www .transifex.com/python-doc/teams/5390/id/)\n "
15+ "POT-Creation-Date : 2025-05-09 14:19 +0000\n "
16+ "PO-Revision-Date : 2021 -06-28 00:57 +0000\n "
17+ "Last-Translator : Elmo <work.elmoallistair @gmail.com>, 2024 \n "
18+ "Language-Team : Indonesian (https://app .transifex.com/python-doc/teams/5390/id/)\n "
1819"MIME-Version : 1.0\n "
1920"Content-Type : text/plain; charset=UTF-8\n "
2021"Content-Transfer-Encoding : 8bit\n "
2122"Language : id\n "
2223"Plural-Forms : nplurals=1; plural=0;\n "
2324
2425#: ../../library/contextvars.rst:2
25- msgid ":mod:`contextvars` --- Context Variables"
26+ msgid ":mod:`! contextvars` --- Context Variables"
2627msgstr ""
2728
2829#: ../../library/contextvars.rst:11
@@ -37,8 +38,8 @@ msgstr ""
3738#: ../../library/contextvars.rst:17
3839msgid ""
3940"Context managers that have state should use Context Variables instead of "
40- ":func:`threading.local() ` to prevent their state from bleeding to other code"
41- " unexpectedly, when used in concurrent code."
41+ ":func:`threading.local` to prevent their state from bleeding to other code "
42+ "unexpectedly, when used in concurrent code."
4243msgstr ""
4344
4445#: ../../library/contextvars.rst:21
@@ -53,6 +54,10 @@ msgstr ""
5354msgid "This class is used to declare a new Context Variable, e.g.::"
5455msgstr ""
5556
57+ #: ../../library/contextvars.rst:33
58+ msgid "var: ContextVar[int] = ContextVar('var', default=42)"
59+ msgstr ""
60+
5661#: ../../library/contextvars.rst:35
5762msgid ""
5863"The required *name* parameter is used for introspection and debug purposes."
@@ -128,135 +133,297 @@ msgstr ""
128133msgid "For example::"
129134msgstr "Sebagai contoh::"
130135
136+ #: ../../library/contextvars.rst:87
137+ msgid ""
138+ "var = ContextVar('var')\n"
139+ "\n"
140+ "token = var.set('new value')\n"
141+ "# code that uses 'var'; var.get() returns 'new value'.\n"
142+ "var.reset(token)\n"
143+ "\n"
144+ "# After the reset call the var has no value again, so\n"
145+ "# var.get() would raise a LookupError."
146+ msgstr ""
147+
131148#: ../../library/contextvars.rst:99
132149msgid ""
133150"*Token* objects are returned by the :meth:`ContextVar.set` method. They can "
134151"be passed to the :meth:`ContextVar.reset` method to revert the value of the "
135152"variable to what it was before the corresponding *set*."
136153msgstr ""
137154
138- #: ../../library/contextvars.rst:106
155+ #: ../../library/contextvars.rst:104
156+ msgid ""
157+ "The token supports :ref:`context manager protocol <context-managers>` to "
158+ "restore the corresponding context variable value at the exit from "
159+ ":keyword:`with` block::"
160+ msgstr ""
161+
162+ #: ../../library/contextvars.rst:108
163+ msgid ""
164+ "var = ContextVar('var', default='default value')\n"
165+ "\n"
166+ "with var.set('new value'):\n"
167+ " assert var.get() == 'new value'\n"
168+ "\n"
169+ "assert var.get() == 'default value'"
170+ msgstr ""
171+
172+ #: ../../library/contextvars.rst:117
173+ msgid "Added support for usage as a context manager."
174+ msgstr ""
175+
176+ #: ../../library/contextvars.rst:121
139177msgid ""
140178"A read-only property. Points to the :class:`ContextVar` object that created"
141179" the token."
142180msgstr ""
143181
144- #: ../../library/contextvars.rst:111
182+ #: ../../library/contextvars.rst:126
145183msgid ""
146184"A read-only property. Set to the value the variable had before the "
147185":meth:`ContextVar.set` method call that created the token. It points to "
148- ":attr:`Token.MISSING` is the variable was not set before the call."
186+ ":attr:`Token.MISSING` if the variable was not set before the call."
149187msgstr ""
150188
151- #: ../../library/contextvars.rst:118
189+ #: ../../library/contextvars.rst:133
152190msgid "A marker object used by :attr:`Token.old_value`."
153191msgstr ""
154192
155- #: ../../library/contextvars.rst:122
193+ #: ../../library/contextvars.rst:137
156194msgid "Manual Context Management"
157195msgstr ""
158196
159- #: ../../library/contextvars.rst:126
197+ #: ../../library/contextvars.rst:141
160198msgid "Returns a copy of the current :class:`~contextvars.Context` object."
161199msgstr ""
162200
163- #: ../../library/contextvars.rst:128
201+ #: ../../library/contextvars.rst:143
164202msgid ""
165203"The following snippet gets a copy of the current context and prints all "
166204"variables and their values that are set in it::"
167205msgstr ""
168206
169- #: ../../library/contextvars.rst:134
207+ #: ../../library/contextvars.rst:146
170208msgid ""
171- "The function has an O(1) complexity, i.e. works equally fast for contexts "
172- "with a few context variables and for contexts that have a lot of them. "
209+ "ctx: Context = copy_context()\n "
210+ "print(list(ctx.items())) "
173211msgstr ""
174212
175- #: ../../library/contextvars.rst:141
213+ #: ../../library/contextvars.rst:149
214+ msgid ""
215+ "The function has an *O*\\ (1) complexity, i.e. works equally fast for "
216+ "contexts with a few context variables and for contexts that have a lot of "
217+ "them."
218+ msgstr ""
219+
220+ #: ../../library/contextvars.rst:156
176221msgid "A mapping of :class:`ContextVars <ContextVar>` to their values."
177222msgstr ""
178223
179- #: ../../library/contextvars.rst:143
224+ #: ../../library/contextvars.rst:158
180225msgid ""
181226"``Context()`` creates an empty context with no values in it. To get a copy "
182227"of the current context use the :func:`~contextvars.copy_context` function."
183228msgstr ""
184229
185- #: ../../library/contextvars.rst:147
186- msgid "Context implements the :class:`collections.abc.Mapping` interface."
230+ #: ../../library/contextvars.rst:162
231+ msgid ""
232+ "Each thread has its own effective stack of :class:`!Context` objects. The "
233+ ":term:`current context` is the :class:`!Context` object at the top of the "
234+ "current thread's stack. All :class:`!Context` objects in the stacks are "
235+ "considered to be *entered*."
236+ msgstr ""
237+
238+ #: ../../library/contextvars.rst:167
239+ msgid ""
240+ "*Entering* a context, which can be done by calling its :meth:`~Context.run` "
241+ "method, makes the context the current context by pushing it onto the top of "
242+ "the current thread's context stack."
187243msgstr ""
188244
189- #: ../../library/contextvars.rst:151
245+ #: ../../library/contextvars.rst:171
190246msgid ""
191- "Execute ``callable(*args, **kwargs)`` code in the context object the *run* "
192- "method is called on. Return the result of the execution or propagate an "
193- "exception if one occurred."
247+ "*Exiting* from the current context, which can be done by returning from the "
248+ "callback passed to the :meth:`~Context.run` method, restores the current "
249+ "context to what it was before the context was entered by popping the context"
250+ " off the top of the context stack."
194251msgstr ""
195252
196- #: ../../library/contextvars.rst:155
253+ #: ../../library/contextvars.rst:176
197254msgid ""
198- "Any changes to any context variables that *callable* makes will be contained"
199- " in the context object::"
255+ "Since each thread has its own context stack, :class:`ContextVar` objects "
256+ "behave in a similar fashion to :func:`threading.local` when values are "
257+ "assigned in different threads."
200258msgstr ""
201259
202- #: ../../library/contextvars.rst:184
260+ #: ../../library/contextvars.rst:180
203261msgid ""
204- "The method raises a :exc:`RuntimeError` when called on the same context "
205- "object from more than one OS thread, or when called recursively ."
262+ "Attempting to enter an already entered context, including contexts entered "
263+ "in other threads, raises a :exc:`RuntimeError` ."
206264msgstr ""
207265
208- #: ../../library/contextvars.rst:190
266+ #: ../../library/contextvars.rst:183
267+ msgid "After exiting a context, it can later be re-entered (from any thread)."
268+ msgstr ""
269+
270+ #: ../../library/contextvars.rst:185
271+ msgid ""
272+ "Any changes to :class:`ContextVar` values via the :meth:`ContextVar.set` "
273+ "method are recorded in the current context. The :meth:`ContextVar.get` "
274+ "method returns the value associated with the current context. Exiting a "
275+ "context effectively reverts any changes made to context variables while the "
276+ "context was entered (if needed, the values can be restored by re-entering "
277+ "the context)."
278+ msgstr ""
279+
280+ #: ../../library/contextvars.rst:192
281+ msgid "Context implements the :class:`collections.abc.Mapping` interface."
282+ msgstr ""
283+
284+ #: ../../library/contextvars.rst:196
285+ msgid ""
286+ "Enters the Context, executes ``callable(*args, **kwargs)``, then exits the "
287+ "Context. Returns *callable*'s return value, or propagates an exception if "
288+ "one occurred."
289+ msgstr ""
290+
291+ #: ../../library/contextvars.rst:200
292+ msgid "Example:"
293+ msgstr "Contoh:"
294+
295+ #: ../../library/contextvars.rst:202
296+ msgid ""
297+ "import contextvars\n"
298+ "\n"
299+ "var = contextvars.ContextVar('var')\n"
300+ "var.set('spam')\n"
301+ "print(var.get()) # 'spam'\n"
302+ "\n"
303+ "ctx = contextvars.copy_context()\n"
304+ "\n"
305+ "def main():\n"
306+ " # 'var' was set to 'spam' before\n"
307+ " # calling 'copy_context()' and 'ctx.run(main)', so:\n"
308+ " print(var.get()) # 'spam'\n"
309+ " print(ctx[var]) # 'spam'\n"
310+ "\n"
311+ " var.set('ham')\n"
312+ "\n"
313+ " # Now, after setting 'var' to 'ham':\n"
314+ " print(var.get()) # 'ham'\n"
315+ " print(ctx[var]) # 'ham'\n"
316+ "\n"
317+ "# Any changes that the 'main' function makes to 'var'\n"
318+ "# will be contained in 'ctx'.\n"
319+ "ctx.run(main)\n"
320+ "\n"
321+ "# The 'main()' function was run in the 'ctx' context,\n"
322+ "# so changes to 'var' are contained in it:\n"
323+ "print(ctx[var]) # 'ham'\n"
324+ "\n"
325+ "# However, outside of 'ctx', 'var' is still set to 'spam':\n"
326+ "print(var.get()) # 'spam'"
327+ msgstr ""
328+
329+ #: ../../library/contextvars.rst:248
209330msgid "Return a shallow copy of the context object."
210331msgstr ""
211332
212- #: ../../library/contextvars.rst:194
333+ #: ../../library/contextvars.rst:252
213334msgid ""
214335"Return ``True`` if the *context* has a value for *var* set; return ``False``"
215336" otherwise."
216337msgstr ""
217338
218- #: ../../library/contextvars.rst:199
339+ #: ../../library/contextvars.rst:257
219340msgid ""
220341"Return the value of the *var* :class:`ContextVar` variable. If the variable "
221342"is not set in the context object, a :exc:`KeyError` is raised."
222343msgstr ""
223344
224- #: ../../library/contextvars.rst:205
345+ #: ../../library/contextvars.rst:263
225346msgid ""
226347"Return the value for *var* if *var* has the value in the context object. "
227348"Return *default* otherwise. If *default* is not given, return ``None``."
228349msgstr ""
229350
230- #: ../../library/contextvars.rst:211
351+ #: ../../library/contextvars.rst:269
231352msgid "Return an iterator over the variables stored in the context object."
232353msgstr ""
233354
234- #: ../../library/contextvars.rst:216
355+ #: ../../library/contextvars.rst:274
235356msgid "Return the number of variables set in the context object."
236357msgstr ""
237358
238- #: ../../library/contextvars.rst:220
359+ #: ../../library/contextvars.rst:278
239360msgid "Return a list of all variables in the context object."
240361msgstr ""
241362
242- #: ../../library/contextvars.rst:224
363+ #: ../../library/contextvars.rst:282
243364msgid "Return a list of all variables' values in the context object."
244365msgstr ""
245366
246- #: ../../library/contextvars.rst:229
367+ #: ../../library/contextvars.rst:287
247368msgid ""
248369"Return a list of 2-tuples containing all variables and their values in the "
249370"context object."
250371msgstr ""
251372
252- #: ../../library/contextvars.rst:234
373+ #: ../../library/contextvars.rst:292
253374msgid "asyncio support"
254375msgstr ""
255376
256- #: ../../library/contextvars.rst:236
377+ #: ../../library/contextvars.rst:294
257378msgid ""
258379"Context variables are natively supported in :mod:`asyncio` and are ready to "
259380"be used without any extra configuration. For example, here is a simple echo"
260381" server, that uses a context variable to make the address of a remote client"
261382" available in the Task that handles that client::"
262383msgstr ""
384+
385+ #: ../../library/contextvars.rst:300
386+ msgid ""
387+ "import asyncio\n"
388+ "import contextvars\n"
389+ "\n"
390+ "client_addr_var = contextvars.ContextVar('client_addr')\n"
391+ "\n"
392+ "def render_goodbye():\n"
393+ " # The address of the currently handled client can be accessed\n"
394+ " # without passing it explicitly to this function.\n"
395+ "\n"
396+ " client_addr = client_addr_var.get()\n"
397+ " return f'Good bye, client @ {client_addr}\\ r\\ n'.encode()\n"
398+ "\n"
399+ "async def handle_request(reader, writer):\n"
400+ " addr = writer.transport.get_extra_info('socket').getpeername()\n"
401+ " client_addr_var.set(addr)\n"
402+ "\n"
403+ " # In any code that we call is now possible to get\n"
404+ " # client's address by calling 'client_addr_var.get()'.\n"
405+ "\n"
406+ " while True:\n"
407+ " line = await reader.readline()\n"
408+ " print(line)\n"
409+ " if not line.strip():\n"
410+ " break\n"
411+ "\n"
412+ " writer.write(b'HTTP/1.1 200 OK\\ r\\ n') # status line\n"
413+ " writer.write(b'\\ r\\ n') # headers\n"
414+ " writer.write(render_goodbye()) # body\n"
415+ " writer.close()\n"
416+ "\n"
417+ "async def main():\n"
418+ " srv = await asyncio.start_server(\n"
419+ " handle_request, '127.0.0.1', 8081)\n"
420+ "\n"
421+ " async with srv:\n"
422+ " await srv.serve_forever()\n"
423+ "\n"
424+ "asyncio.run(main())\n"
425+ "\n"
426+ "# To test it you can use telnet or curl:\n"
427+ "# telnet 127.0.0.1 8081\n"
428+ "# curl 127.0.0.1:8081"
429+ msgstr ""
0 commit comments