Repository navigation
Expand file tree
/
Copy pathweakref.po
More file actions
529 lines (433 loc) · 49.2 KB
/
Copy pathweakref.po
File metadata and controls
529 lines (433 loc) · 49.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
# SOME DESCRIPTIVE TITLE.
# Copyright (C) 2001 Python Software Foundation
# This file is distributed under the same license as the Python package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
# Translators:
# Danial Behzadi <dani.behzi@ubuntu.com>, 2025
# Rafael Fontenelle <rffontenelle@gmail.com>, 2025
# Revisto <theRevisto@gmail.com>, 2025
# Sepehr Rasouli <sepehrrasouli06@gmail.com>, 2026
#
msgid ""
msgstr ""
"Project-Id-Version: Python 3.14\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-09-21 11:59+0000\n"
"PO-Revision-Date: 2026-09-15 08:24+0330\n"
"Last-Translator: Sepehr Rasouli <sepehrrasouli06@gmail.com>, 2026\n"
"Language-Team: Persian (https://github.com/python/python-docs-fa/)\n"
"Language: fa\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
"X-Generator: Poedit 3.6\n"
msgid ":mod:`!weakref` --- Weak references"
msgstr ":mod:`!weakref` --- ارجاعهای ضعیف"
msgid "**Source code:** :source:`Lib/weakref.py`"
msgstr "**کد منبع:** :source:`Lib/weakref.py`"
msgid "The :mod:`!weakref` module allows the Python programmer to create :dfn:`weak references` to objects."
msgstr "ماژول :mod:`!weakref` به برنامهنویس پایتون اجازه میدهد تا :dfn:`ارجاعهای ضعیف (weak references)` به اشیاء ایجاد کند."
msgid "In the following, the term :dfn:`referent` means the object which is referred to by a weak reference."
msgstr "در ادامه، اصطلاح :dfn:`referent` به معنای شیءای است که یک ارجاع ضعیف به آن اشاره میکند."
msgid "A weak reference to an object is not enough to keep the object alive: when the only remaining references to a referent are weak references, :term:`garbage collection` is free to destroy the referent and reuse its memory for something else. However, until the object is actually destroyed the weak reference may return the object even if there are no strong references to it."
msgstr "یک ارجاع ضعیف به یک شیء برای زنده نگه داشتن آن شیء کافی نیست: هنگامی که تنها ارجاعهای باقیمانده به یک مورد ارجاع، ارجاعهای ضعیف باشند، :term:`زبالهروبی <garbage collection>` مختار است مورد ارجاع را نابود کند و حافظهی آن را برای چیز دیگری بازاستفاده کند. با این حال، تا زمانی که شیء واقعاً نابود نشده باشد، ارجاع ضعیف ممکن است شیء را برگرداند، حتی اگر هیچ ارجاع قویای به آن وجود نداشته باشد."
msgid "A primary use for weak references is to implement caches or mappings holding large objects, where it's desired that a large object not be kept alive solely because it appears in a cache or mapping."
msgstr "یک کاربرد اصلی برای ارجاعهای ضعیف، پیادهسازی نهانگاهها یا نگاشتهایی است که اشیای بزرگ را نگه میدارند، در مواردی که مطلوب است یک شیء بزرگ صرفاً به این دلیل که در یک نهانگاه یا نگاشت قرار دارد، زنده نگهداشته نشود."
msgid "For example, if you have a number of large binary image objects, you may wish to associate a name with each. If you used a Python dictionary to map names to images, or images to names, the image objects would remain alive just because they appeared as values or keys in the dictionaries. The :class:`WeakKeyDictionary` and :class:`WeakValueDictionary` classes supplied by the :mod:`!weakref` module are an alternative, using weak references to construct mappings that don't keep objects alive solely because they appear in the mapping objects. If, for example, an image object is a value in a :class:`WeakValueDictionary`, then when the last remaining references to that image object are the weak references held by weak mappings, garbage collection can reclaim the object, and its corresponding entries in weak mappings are simply deleted."
msgstr "برای مثال، اگر تعدادی شیء تصویر دودویی بزرگ داشته باشید، ممکن است بخواهید نامی به هر یک اختصاص دهید. اگر از یک دیکشنری پایتون برای نگاشت نامها به تصاویر، یا تصاویر به نامها استفاده کرده باشید، اشیاء تصویر صرفاً به این دلیل که بهعنوان مقدار یا کلید در دیکشنریها حضور دارند، زنده میماندند. کلاسهای :class:`WeakKeyDictionary` و :class:`WeakValueDictionary` ارائهشده توسط ماژول :mod:`!weakref` جایگزینی هستند که با استفاده از ارجاعهای ضعیف (weak references)، نگاشتهایی میسازند که اشیاء را صرفاً به دلیل حضور در اشیاء نگاشت زنده نگه نمیدارند. برای مثال، اگر یک شیء تصویر یک مقدار در یک :class:`WeakValueDictionary` باشد، آنگاه هنگامی که آخرین ارجاعهای باقیمانده به آن شیء تصویر، همان ارجاعهای ضعیف نگهداشتهشده توسط نگاشتهای ضعیف باشند، زبالهروبی میتواند شیء را بازیابی کند و ورودیهای متناظر آن در نگاشتهای ضعیف بهسادگی حذف میشوند."
msgid ":class:`WeakKeyDictionary` and :class:`WeakValueDictionary` use weak references in their implementation, setting up callback functions on the weak references that notify the weak dictionaries when a key or value has been reclaimed by garbage collection. :class:`WeakSet` implements the :class:`set` interface, but keeps weak references to its elements, just like a :class:`WeakKeyDictionary` does."
msgstr ":class:`WeakKeyDictionary` و :class:`WeakValueDictionary` در پیادهسازی خود از ارجاعهای ضعیف استفاده میکنند و توابع کالبک را روی ارجاعهای ضعیف تنظیم میکنند تا هنگامی که یک کلید یا مقدار توسط زبالهروبی بازیابی میشود، به دیکشنریهای ضعیف اطلاع دهند. :class:`WeakSet` رابط :class:`set` را پیادهسازی میکند، اما ارجاعهای ضعیفی به عناصر خود نگه میدارد، درست همانگونه که :class:`WeakKeyDictionary` چنین میکند."
msgid ":class:`finalize` provides a straight forward way to register a cleanup function to be called when an object is garbage collected. This is simpler to use than setting up a callback function on a raw weak reference, since the module automatically ensures that the finalizer remains alive until the object is collected."
msgstr ":class:`finalize` راه سرراستی برای ثبت یک تابع پاکسازی فراهم میکند تا هنگام زبالهروبی یک شیء فراخوانی شود. استفاده از آن سادهتر از تنظیم یک تابع کالبک روی یک ارجاع ضعیف خام است، زیرا این ماژول بهطور خودکار تضمین میکند که نهاییساز (finalizer) تا زمان زبالهروبی شدن شیء زنده میماند."
msgid "Most programs should find that using one of these weak container types or :class:`finalize` is all they need -- it's not usually necessary to create your own weak references directly. The low-level machinery is exposed by the :mod:`!weakref` module for the benefit of advanced uses."
msgstr "انتظار میرود بیشتر برنامهها متوجه شوند که استفاده از یکی از این انواع ظرف ضعیف یا :class:`finalize` برایشان کافی است — معمولاً لازم نیست ارجاعهای ضعیف خود را مستقیماً ایجاد کنید. ماژول :mod:`!weakref` سازوکار سطح پایین را برای استفادههای پیشرفته در دسترس قرار میدهد."
msgid "Not all objects can be weakly referenced. Objects which support weak references include class instances, functions written in Python (but not in C), instance methods, sets, frozensets, some :term:`file objects <file object>`, :term:`generators <generator>`, type objects, sockets, arrays, deques, regular expression pattern objects, and code objects."
msgstr "همهی اشیاء قابلیت ارجاع ضعیف ندارند. اشیایی که از ارجاع ضعیف پشتیبانی میکنند، شامل نمونههای کلاس، توابع نوشتهشده به پایتون (اما نه به C)، متدهای نمونه، مجموعهها، مجموعههای تغییرناپذیر (frozenset)، برخی :term:`اشیای پرونده <file object>`، :term:`تولیدگرها <generator>`، اشیای نوع، سوکتها، آرایهها، صفهای دوطرفه (deque)، اشیای الگوی عبارت باقاعده و اشیای کد هستند."
msgid "Added support for thread.lock, threading.Lock, and code objects."
msgstr "پشتیبانی از thread.lock، threading.Lock و اشیای کد اضافه شد."
msgid "Several built-in types such as :class:`list` and :class:`dict` do not directly support weak references but can add support through subclassing::"
msgstr "چندین نوع توکار مانند :class:`list` و :class:`dict` بهطور مستقیم از ارجاعهای ضعیف پشتیبانی نمیکنند، اما میتوان از طریق زیرکلاسسازی پشتیبانی را به آنها افزود::"
msgid ""
"class Dict(dict):\n"
" pass\n"
"\n"
"obj = Dict(red=1, green=2, blue=3) # this object is weak referenceable"
msgstr ""
"class Dict(dict):\n"
" pass\n"
"\n"
"obj = Dict(red=1, green=2, blue=3) # this object is weak referenceable"
msgid "Other built-in types such as :class:`tuple` and :class:`int` do not support weak references even when subclassed."
msgstr "سایر انواع توکار مانند :class:`tuple` و :class:`int` از ارجاعهای ضعیف پشتیبانی نمیکنند، حتی در صورت زیرکلاسسازی."
msgid "Extension types can easily be made to support weak references; see :ref:`weakref-support`."
msgstr "انواع توسعهای میتوانند بهسادگی برای پشتیبانی از ارجاعهای ضعیف آماده شوند؛ :ref:`weakref-support` را ببینید."
msgid "When ``__slots__`` are defined for a given type, weak reference support is disabled unless a ``'__weakref__'`` string is also present in the sequence of strings in the ``__slots__`` declaration. See :ref:`__slots__ documentation <slots>` for details."
msgstr "هنگامی که ``__slots__`` برای یک نوع معین تعریف شده باشد، پشتیبانی از ارجاع ضعیف غیرفعال میشود، مگر آنکه یک رشته ``'__weakref__'`` نیز در دنبالهای از رشتههای موجود در اعلان ``__slots__`` وجود داشته باشد. برای جزئیات، :ref:`مستندات __slots__ <slots>` را ببینید."
msgid "Return a weak reference to *object*. The original object can be retrieved by calling the reference object if the referent is still alive; if the referent is no longer alive, calling the reference object will cause :const:`None` to be returned. If *callback* is provided and not :const:`None`, and the returned weakref object is still alive, the callback will be called when the object is about to be finalized; the weak reference object will be passed as the only parameter to the callback; the referent will no longer be available."
msgstr "یک ارجاع ضعیف به *object* برمیگرداند. اگر موضوع ارجاع هنوز زنده باشد، میتوان شیء اصلی را با فراخوانی شیء ارجاع بازیابی کرد؛ اگر موضوع ارجاع دیگر زنده نباشد، فراخوانی شیء ارجاع باعث میشود :const:`None` برگردانده شود. اگر *callback* ارائهشده باشد و :const:`None` نباشد، و شیء ارجاع ضعیف برگرداندهشده هنوز زنده باشد، کالبک هنگامی فراخوانی خواهد شد که شیء در آستانه نهاییشدن باشد؛ شیء ارجاع ضعیف بهعنوان تنها پارامتر به کالبک داده خواهد شد؛ موضوع ارجاع دیگر در دسترس نخواهد بود."
msgid "It is allowable for many weak references to be constructed for the same object. Callbacks registered for each weak reference will be called from the most recently registered callback to the oldest registered callback."
msgstr "ایجاد چندین ارجاع ضعیف به یک شیء یکسان مجاز است. کالبکهای ثبتشده برای هر ارجاع ضعیف، از جدیدترین کالبک ثبتشده تا قدیمیترین کالبک ثبتشده فراخوانی میشوند."
msgid "Exceptions raised by the callback will be noted on the standard error output, but cannot be propagated; they are handled in exactly the same way as exceptions raised from an object's :meth:`~object.__del__` method."
msgstr "استثناهای پرتابشده توسط کالبک در خروجی خطای استاندارد ثبت خواهند شد، اما قابل انتشار نیستند؛ آنها دقیقاً همانند استثناهای پرتابشده از متد :meth:`~object.__del__` یک شیء مدیریت میشوند."
msgid "Weak references are :term:`hashable` if the *object* is hashable. They will maintain their hash value even after the *object* was deleted. If :func:`hash` is called the first time only after the *object* was deleted, the call will raise :exc:`TypeError`."
msgstr "ارجاعهای ضعیف در صورتی :term:`هشپذیر <hashable>` هستند که *شیء* هشپذیر باشد. آنها مقدار هش خود را حتی پس از حذف *شیء* حفظ میکنند. اگر :func:`hash` برای نخستین بار تنها پس از حذف *شیء* فراخوانی شود، این فراخوانی :exc:`TypeError` را پرتاب میکند."
msgid "Weak references support tests for equality, but not ordering. If the referents are still alive, two references have the same equality relationship as their referents (regardless of the *callback*). If either referent has been deleted, the references are equal only if the reference objects are the same object."
msgstr "ارجاعهای ضعیف از آزمونهای برابری پشتیبانی میکنند، اما نه از مرتبسازی. اگر موارد ارجاع هنوز زنده باشند، دو ارجاع همان رابطه برابری موارد ارجاع خود را دارند (صرفنظر از *کالبک*). اگر هر یک از موارد ارجاع حذف شده باشد، ارجاعها تنها در صورتی برابرند که اشیاء ارجاع، یک شیء یکسان باشند."
msgid "This is a subclassable type rather than a factory function."
msgstr "این یک نوع قابل زیرکلاسسازی است، نه یک تابع کارخانهای."
msgid "Weak references are :ref:`generic <generics>` over the type of the object they reference."
msgstr "ارجاعهای ضعیف نسبت به نوع شیءای که به آن ارجاع میدهند، :ref:`عام <generics>` هستند."
msgid "This read-only attribute returns the callback currently associated to the weakref. If there is no callback or if the referent of the weakref is no longer alive then this attribute will have value ``None``."
msgstr "این ویژگی فقطخواندنی، کالبکی را برمیگرداند که در حال حاضر به ارجاع ضعیف (weakref) مرتبط است. اگر کالبکی وجود نداشته باشد یا مورد ارجاعِ weakref دیگر زنده نباشد، این ویژگی مقدار ``None`` خواهد داشت."
msgid "Added the :attr:`__callback__` attribute."
msgstr "ویژگی :attr:`__callback__` اضافه شد."
msgid "Return a proxy to *object* which uses a weak reference. This supports use of the proxy in most contexts instead of requiring the explicit dereferencing used with weak reference objects. The returned object will have a type of either ``ProxyType`` or ``CallableProxyType``, depending on whether *object* is callable. Proxy objects are not :term:`hashable` regardless of the referent; this avoids a number of problems related to their fundamentally mutable nature, and prevents their use as dictionary keys. *callback* is the same as the parameter of the same name to the :func:`ref` function."
msgstr "یک پراکسی به *object* برمیگرداند که از یک ارجاع ضعیف استفاده میکند. این موضوع از استفاده از پراکسی در بیشتر زمینهها پشتیبانی میکند، بدون اینکه به ارجاعگشایی (dereferencing) صریح که با اشیاء ارجاع ضعیف به کار میرود نیاز باشد. نوع شیء برگرداندهشده، بسته به اینکه *object* قابل فراخوانی باشد یا نه، ``ProxyType`` یا ``CallableProxyType`` خواهد بود. اشیاء پراکسی صرفنظر از مورد ارجاع، :term:`hashable` نیستند؛ این امر از تعدادی مشکل مرتبط با ماهیت اساساً تغییرپذیرشان جلوگیری میکند و مانع از استفاده از آنها بهعنوان کلیدهای دیکشنری میشود. *callback* همان پارامتر همنام در تابع :func:`ref` است."
msgid "Accessing an attribute of the proxy object after the referent is garbage collected raises :exc:`ReferenceError`."
msgstr "دسترسی به یک ویژگی از شیء پراکسی پس از زبالهروبی شدن مرجع آن، باعث پرتاب :exc:`ReferenceError` میشود."
msgid "Extended the operator support on proxy objects to include the matrix multiplication operators ``@`` and ``@=``."
msgstr "پشتیبانی از عملگرها در اشیای پراکسی گسترش یافت تا شامل عملگرهای ضرب ماتریسی ``@`` و ``@=`` شود."
msgid "Return the number of weak references and proxies which refer to *object*."
msgstr "تعداد ارجاعهای ضعیف و پراکسیهایی را که به *object* ارجاع میدهند، برمیگرداند."
msgid "Return a list of all weak reference and proxy objects which refer to *object*."
msgstr "فهرستی از همهی اشیای ارجاع ضعیف و پراکسی که به *object* ارجاع میدهند برمیگرداند."
msgid "Mapping class that references keys weakly. Entries in the dictionary will be discarded when there is no longer a strong reference to the key. This can be used to associate additional data with an object owned by other parts of an application without adding attributes to those objects. This can be especially useful with objects that override attribute accesses."
msgstr "کلاس نگاشتی که کلیدها را بهصورت ضعیف ارجاع میدهد. هرگاه دیگر ارجاع قوی به کلید وجود نداشته باشد، ورودیهای دیکشنری حذف میشوند. این میتواند برای مرتبط کردن دادههای اضافی با شیءای که متعلق به بخشهای دیگر یک برنامه است، بدون افزودن ویژگیها به آن اشیاء استفاده شود. این میتواند بهویژه برای اشیایی که دسترسی به ویژگیها را بازنویسی میکنند، مفید باشد."
msgid "Note that when a key with equal value to an existing key (but not equal identity) is inserted into the dictionary, it replaces the value but does not replace the existing key. Due to this, when the reference to the original key is deleted, it also deletes the entry in the dictionary::"
msgstr "توجه داشته باشید که هنگامی که کلیدی با مقدار برابر با یک کلید موجود (اما با هویت نابرابر) در دیکشنری درج میشود، مقدار جایگزین میشود، اما کلید موجود جایگزین نمیشود. به همین دلیل، هنگامی که مرجع کلید اصلی حذف شود، آیتم موجود در دیکشنری نیز حذف میشود::"
msgid ""
">>> class T(str): pass\n"
"...\n"
">>> k1, k2 = T(), T()\n"
">>> d = weakref.WeakKeyDictionary()\n"
">>> d[k1] = 1 # d = {k1: 1}\n"
">>> d[k2] = 2 # d = {k1: 2}\n"
">>> del k1 # d = {}"
msgstr ""
">>> class T(str): pass\n"
"...\n"
">>> k1, k2 = T(), T()\n"
">>> d = weakref.WeakKeyDictionary()\n"
">>> d[k1] = 1 # d = {k1: 1}\n"
">>> d[k2] = 2 # d = {k1: 2}\n"
">>> del k1 # d = {}"
msgid "A workaround would be to remove the key prior to reassignment::"
msgstr "یک راهحل موقت این است که کلید را پیش از انتساب مجدد حذف کنید::"
msgid ""
">>> class T(str): pass\n"
"...\n"
">>> k1, k2 = T(), T()\n"
">>> d = weakref.WeakKeyDictionary()\n"
">>> d[k1] = 1 # d = {k1: 1}\n"
">>> del d[k1]\n"
">>> d[k2] = 2 # d = {k2: 2}\n"
">>> del k1 # d = {k2: 2}"
msgstr ""
">>> class T(str): pass\n"
"...\n"
">>> k1, k2 = T(), T()\n"
">>> d = weakref.WeakKeyDictionary()\n"
">>> d[k1] = 1 # d = {k1: 1}\n"
">>> del d[k1]\n"
">>> d[k2] = 2 # d = {k2: 2}\n"
">>> del k1 # d = {k2: 2}"
msgid "Added support for ``|`` and ``|=`` operators, as specified in :pep:`584`."
msgstr "پشتیبانی از عملگرهای ``|`` و ``|=``، همانطور که در :pep:`584` مشخص شده است، افزوده شد."
msgid ":class:`WeakKeyDictionary` objects have an additional method that exposes the internal references directly. The references are not guaranteed to be \"live\" at the time they are used, so the result of calling the references needs to be checked before being used. This can be used to avoid creating references that will cause the garbage collector to keep the keys around longer than needed."
msgstr "اشیای :class:`WeakKeyDictionary` یک متد اضافه دارند که ارجاعهای داخلی را بهطور مستقیم آشکار میکند. تضمینی نیست که این ارجاعها در زمان استفاده «زنده» باشند، بنابراین نتیجهی فراخوانی ارجاعها باید پیش از استفاده بررسی شود. این میتواند برای اجتناب از ایجاد ارجاعهایی به کار رود که باعث میشود زبالهروبی کلیدها را بیش از حد نیاز نگه دارد."
msgid "Return an iterable of the weak references to the keys."
msgstr "یک پیمایشپذیر از ارجاعهای ضعیف به کلیدها برمیگرداند."
msgid "Mapping class that references values weakly. Entries in the dictionary will be discarded when no strong reference to the value exists any more."
msgstr "کلاس نگاشتی که به مقادیر بهصورت ضعیف ارجاع میدهد. هنگامی که دیگر هیچ ارجاع قوی به مقدار وجود نداشته باشد، ورودیهای دیکشنری حذف میشوند."
msgid ":class:`WeakValueDictionary` objects have an additional method that has the same issues as the :meth:`WeakKeyDictionary.keyrefs` method."
msgstr "اشیای :class:`WeakValueDictionary` یک متد اضافی دارند که همان مشکلات متد :meth:`WeakKeyDictionary.keyrefs` را دارد."
msgid "Return an iterable of the weak references to the values."
msgstr "یک پیمایشپذیر از ارجاعهای ضعیف به مقادیر برمیگرداند."
msgid "Set class that keeps weak references to its elements. An element will be discarded when no strong reference to it exists any more."
msgstr "کلاس مجموعهای که ارجاعهای ضعیف به عناصر خود را نگه میدارد. هرگاه دیگر هیچ ارجاع قویای به یک عنصر وجود نداشته باشد، آن عنصر حذف میشود."
msgid "A custom :class:`ref` subclass which simulates a weak reference to a bound method (i.e., a method defined on a class and looked up on an instance). Since a bound method is ephemeral, a standard weak reference cannot keep hold of it. :class:`WeakMethod` has special code to recreate the bound method until either the object or the original function dies::"
msgstr "یک زیرکلاس سفارشی از :class:`ref` که یک ارجاع ضعیف به یک متد مقید را شبیهسازی میکند (یعنی متدی که در یک کلاس تعریف شده و روی یک نمونه جستوجو میشود). از آنجا که متد مقید گذرا است، یک ارجاع ضعیف استاندارد نمیتواند آن را نگه دارد. :class:`WeakMethod` کد ویژهای برای بازسازی متد مقید دارد تا پیش از آنکه شیء یا تابع اصلی از بین برود::"
msgid ""
">>> class C:\n"
"... def method(self):\n"
"... print(\"method called!\")\n"
"...\n"
">>> c = C()\n"
">>> r = weakref.ref(c.method)\n"
">>> r()\n"
">>> r = weakref.WeakMethod(c.method)\n"
">>> r()\n"
"<bound method C.method of <__main__.C object at 0x7fc859830220>>\n"
">>> r()()\n"
"method called!\n"
">>> del c\n"
">>> gc.collect()\n"
"0\n"
">>> r()\n"
">>>"
msgstr ""
">>> class C:\n"
"... def method(self):\n"
"... print(\"method called!\")\n"
"...\n"
">>> c = C()\n"
">>> r = weakref.ref(c.method)\n"
">>> r()\n"
">>> r = weakref.WeakMethod(c.method)\n"
">>> r()\n"
"<bound method C.method of <__main__.C object at 0x7fc859830220>>\n"
">>> r()()\n"
"method called!\n"
">>> del c\n"
">>> gc.collect()\n"
"0\n"
">>> r()\n"
">>>"
msgid "*callback* is the same as the parameter of the same name to the :func:`ref` function."
msgstr "*callback* همان پارامتر همنام در تابع :func:`ref` است."
msgid "Return a callable finalizer object which will be called when *obj* is garbage collected. Unlike an ordinary weak reference, a finalizer will always survive until the reference object is collected, greatly simplifying lifecycle management."
msgstr "یک شیء نهاییسازٔ فراخوانیپذیر برمیگرداند که هنگام زبالهروبی *obj* فراخوانی میشود. برخلاف یک ارجاع ضعیف معمولی، نهاییساز همیشه تا زمانی که شیء ارجاعشده زبالهروبی شود باقی میماند و مدیریت چرخهی عمر را بسیار سادهتر میکند."
msgid "A finalizer is considered *alive* until it is called (either explicitly or at garbage collection), and after that it is *dead*. Calling a live finalizer returns the result of evaluating ``func(*arg, **kwargs)``, whereas calling a dead finalizer returns :const:`None`."
msgstr "یک نهاییساز تا پیش از آنکه فراخوانی شود (چه بهصراحت و چه در زمان زبالهروبی)، *زنده* در نظر گرفته میشود و پس از آن *مرده* است. فراخوانی یک نهاییساز زنده، نتیجه ارزیابی ``func(*arg, **kwargs)`` را برمیگرداند، در حالی که فراخوانی یک نهاییساز مرده :const:`None` را برمیگرداند."
msgid "Exceptions raised by finalizer callbacks during garbage collection will be shown on the standard error output, but cannot be propagated. They are handled in the same way as exceptions raised from an object's :meth:`~object.__del__` method or a weak reference's callback."
msgstr "استثناهایی که توسط کالبکهای نهاییساز در حین زبالهروبی پرتاب میشوند، در خروجی خطای استاندارد نمایش داده خواهند شد، اما نمیتوانند انتشار یابند. آنها به همان شیوهای مدیریت میشوند که استثناهای پرتابشده از متد :meth:`~object.__del__` یک شیء یا کالبک یک ارجاع ضعیف مدیریت میشوند."
msgid "When the program exits (or more generally, at :term:`interpreter shutdown`), each remaining live finalizer is called unless its :attr:`atexit` attribute has been set to false. They are called in reverse order of creation."
msgstr "وقتی برنامه خارج میشود (یا بهطور کلیتر، در :term:`خاموش شدن مفسر <interpreter shutdown>`)، هر نهاییساز زنده باقیمانده فراخوانی میشود، مگر اینکه ویژگی :attr:`atexit` آن روی false تنظیم شده باشد. آنها به ترتیب معکوس ایجاد فراخوانی میشوند."
msgid "A finalizer will never invoke its callback during the later part of the :term:`interpreter shutdown` when module globals are liable to have been replaced by :const:`None`."
msgstr "یک نهاییساز هرگز کالبک خود را در بخش پایانی :term:`خاموش شدن مفسر <interpreter shutdown>` فراخوانی نمیکند، هنگامی که متغیرهای سراسری ماژول ممکن است با :const:`None` جایگزین شده باشند."
msgid "If *self* is alive then mark it as dead and return the result of calling ``func(*args, **kwargs)``. If *self* is dead then return :const:`None`."
msgstr "اگر *self* زنده باشد، آن را بهعنوان مرده علامتگذاری میکند و نتیجه فراخوانی ``func(*args, **kwargs)`` را برمیگرداند. اگر *self* مرده باشد، :const:`None` را برمیگرداند."
msgid "If *self* is alive then mark it as dead and return the tuple ``(obj, func, args, kwargs)``. If *self* is dead then return :const:`None`."
msgstr "اگر *self* زنده باشد، آن را بهعنوان مرده علامتگذاری میکند و تاپل ``(obj, func, args, kwargs)`` را برمیگرداند. اگر *self* مرده باشد، :const:`None` را برمیگرداند."
msgid "If *self* is alive then return the tuple ``(obj, func, args, kwargs)``. If *self* is dead then return :const:`None`."
msgstr "اگر *self* زنده باشد، تاپل ``(obj, func, args, kwargs)`` را برمیگرداند. اگر *self* مرده باشد، :const:`None` را برمیگرداند."
msgid "Property which is true if the finalizer is alive, false otherwise."
msgstr "ویژگیای که اگر نهاییساز زنده باشد، true است، در غیر این صورت false است."
msgid "A writable boolean property which by default is true. At :term:`interpreter shutdown`, all remaining live finalizers for which :attr:`.atexit` is true are called in reverse order of creation."
msgstr "یک ویژگی بولی قابلنوشتن که بهصورت پیشفرض true است. در :term:`خاموش شدن مفسر <interpreter shutdown>`، تمام نهاییسازهای زنده باقیمانده که برای آنها :attr:`.atexit` برابر true باشد، به ترتیب معکوس ایجاد فراخوانی میشوند."
msgid "It is important to ensure that *func*, *args* and *kwargs* do not own any references to *obj*, either directly or indirectly, since otherwise *obj* will never be garbage collected. In particular, *func* should not be a bound method of *obj*."
msgstr "مهم است اطمینان حاصل کنید که *func*، *args* و *kwargs* مالک هیچ ارجاعی به *obj* نباشند، چه بهطور مستقیم و چه بهطور غیرمستقیم، زیرا در غیر این صورت *obj* هرگز زبالهروبی نخواهد شد. بهویژه، *func* نباید یک متد مقید (bound method) به *obj* باشد."
msgid "The type object for weak references objects."
msgstr "شیء نوع برای اشیاء ارجاع ضعیف."
msgid "The type object for proxies of objects which are not callable."
msgstr "شیء نوع برای پراکسیهای اشیایی که فراخوانیپذیر نیستند."
msgid "The type object for proxies of callable objects."
msgstr "شیء نوع برای پراکسیهای اشیای فراخوانیپذیر."
msgid "Sequence containing all the type objects for proxies. This can make it simpler to test if an object is a proxy without being dependent on naming both proxy types."
msgstr "دنبالهای شامل تمام اشیای نوع مربوط به پراکسیها. این موضوع میتواند بررسی اینکه آیا یک شیء پراکسی است را بدون وابستگی به نامبردن از هر دو نوع پراکسی سادهتر کند."
msgid ":pep:`205` - Weak References"
msgstr ":pep:`205` - ارجاعهای ضعیف"
msgid "The proposal and rationale for this feature, including links to earlier implementations and information about similar features in other languages."
msgstr "پیشنهاد و دلایل این ویژگی، شامل پیوندهایی به پیادهسازیهای پیشین و اطلاعاتی درباره ویژگیهای مشابه در زبانهای دیگر."
msgid "Weak Reference Objects"
msgstr "اشیای ارجاع ضعیف"
msgid "Weak reference objects have no methods and no attributes besides :attr:`ref.__callback__`. A weak reference object allows the referent to be obtained, if it still exists, by calling it:"
msgstr "اشیای ارجاع ضعیف هیچ متد و هیچ ویژگیای به جز :attr:`ref.__callback__` ندارند. یک شیء ارجاع ضعیف به شما امکان میدهد که با فراخوانی این شیء، مورد ارجاع را، اگر هنوز وجود داشته باشد، به دست آورید:"
msgid "If the referent no longer exists, calling the reference object returns :const:`None`:"
msgstr "اگر مورد ارجاع دیگر وجود نداشته باشد، فراخوانی شیء ارجاع :const:`None` را برمیگرداند:"
msgid "Testing that a weak reference object is still live should be done using the expression ``ref() is not None``. Normally, application code that needs to use a reference object should follow this pattern::"
msgstr "بررسی زنده بودن یک شیء ارجاع ضعیف (weak reference) باید با استفاده از عبارت ``ref() is not None`` انجام شود. معمولاً، کد برنامهای که نیاز به استفاده از یک شیء ارجاع دارد باید از این الگو پیروی کند::"
msgid ""
"# r is a weak reference object\n"
"o = r()\n"
"if o is None:\n"
" # referent has been garbage collected\n"
" print(\"Object has been deallocated; can't frobnicate.\")\n"
"else:\n"
" print(\"Object is still live!\")\n"
" o.do_something_useful()"
msgstr ""
"# r is a weak reference object\n"
"o = r()\n"
"if o is None:\n"
" # referent has been garbage collected\n"
" print(\"Object has been deallocated; can't frobnicate.\")\n"
"else:\n"
" print(\"Object is still live!\")\n"
" o.do_something_useful()"
msgid "Using a separate test for \"liveness\" creates race conditions in threaded applications; another thread can cause a weak reference to become invalidated before the weak reference is called; the idiom shown above is safe in threaded applications as well as single-threaded applications."
msgstr "استفاده از یک بررسی جداگانه برای «زنده بودن» باعث ایجاد شرایط رقابتی در برنامههای چندنخی میشود؛ نخ دیگری میتواند باعث شود یک ارجاع ضعیف پیش از فراخوانیاش نامعتبر شود؛ الگوی نشاندادهشده در بالا هم در برنامههای چندنخی و هم در برنامههای تکنخی ایمن است."
msgid "Specialized versions of :class:`ref` objects can be created through subclassing. This is used in the implementation of the :class:`WeakValueDictionary` to reduce the memory overhead for each entry in the mapping. This may be most useful to associate additional information with a reference, but could also be used to insert additional processing on calls to retrieve the referent."
msgstr "میتوان نسخههای تخصصیشدهای از اشیای :class:`ref` را از طریق زیرکلاسسازی ایجاد کرد. این روش در پیادهسازی :class:`WeakValueDictionary` برای کاهش سربار حافظهی هر آیتم در نگاشت به کار میرود. این ممکن است بیشترین کاربرد را برای مرتبط کردن اطلاعات اضافی با یک ارجاع داشته باشد، اما همچنین میتواند برای درج پردازش اضافی در فراخوانیهای بازیابی مورد ارجاع استفاده شود."
msgid "This example shows how a subclass of :class:`ref` can be used to store additional information about an object and affect the value that's returned when the referent is accessed::"
msgstr "این مثال نشان میدهد که چگونه میتوان از یک زیرکلاس از :class:`ref` برای ذخیره اطلاعات بیشتر درباره یک شیء و تأثیرگذاری بر مقداری که هنگام دسترسی به شیء ارجاعشده برگردانده میشود، استفاده کرد::"
msgid ""
"import weakref\n"
"\n"
"class ExtendedRef(weakref.ref):\n"
" def __init__(self, ob, callback=None, /, **annotations):\n"
" super().__init__(ob, callback)\n"
" self.__counter = 0\n"
" for k, v in annotations.items():\n"
" setattr(self, k, v)\n"
"\n"
" def __call__(self):\n"
" \"\"\"Return a pair containing the referent and the number of\n"
" times the reference has been called.\n"
" \"\"\"\n"
" ob = super().__call__()\n"
" if ob is not None:\n"
" self.__counter += 1\n"
" ob = (ob, self.__counter)\n"
" return ob"
msgstr ""
"import weakref\n"
"\n"
"class ExtendedRef(weakref.ref):\n"
" def __init__(self, ob, callback=None, /, **annotations):\n"
" super().__init__(ob, callback)\n"
" self.__counter = 0\n"
" for k, v in annotations.items():\n"
" setattr(self, k, v)\n"
"\n"
" def __call__(self):\n"
" \"\"\"Return a pair containing the referent and the number of\n"
" times the reference has been called.\n"
" \"\"\"\n"
" ob = super().__call__()\n"
" if ob is not None:\n"
" self.__counter += 1\n"
" ob = (ob, self.__counter)\n"
" return ob"
msgid "Example"
msgstr "مثال"
msgid "This simple example shows how an application can use object IDs to retrieve objects that it has seen before. The IDs of the objects can then be used in other data structures without forcing the objects to remain alive, but the objects can still be retrieved by ID if they do."
msgstr "این مثال ساده نشان میدهد که یک برنامه چگونه میتواند از شناسههای اشیاء برای بازیابی اشیایی که پیشتر دیده است استفاده کند. سپس میتوان از شناسههای اشیاء در سایر ساختارهای داده استفاده کرد، بدون آنکه اشیاء مجبور به زنده ماندن شوند، اما اگر زنده بمانند، همچنان میتوان آنها را با شناسه بازیابی کرد."
msgid ""
"import weakref\n"
"\n"
"_id2obj_dict = weakref.WeakValueDictionary()\n"
"\n"
"def remember(obj):\n"
" oid = id(obj)\n"
" _id2obj_dict[oid] = obj\n"
" return oid\n"
"\n"
"def id2obj(oid):\n"
" return _id2obj_dict[oid]"
msgstr ""
"import weakref\n"
"\n"
"_id2obj_dict = weakref.WeakValueDictionary()\n"
"\n"
"def remember(obj):\n"
" oid = id(obj)\n"
" _id2obj_dict[oid] = obj\n"
" return oid\n"
"\n"
"def id2obj(oid):\n"
" return _id2obj_dict[oid]"
msgid "Finalizer Objects"
msgstr "اشیای نهاییساز (Finalizer Objects)"
msgid "The main benefit of using :class:`finalize` is that it makes it simple to register a callback without needing to preserve the returned finalizer object. For instance"
msgstr "مزیت اصلی استفاده از :class:`finalize` این است که ثبت یک کالبک را بدون نیاز به نگهداری شیء نهاییساز بازگشتی ساده میکند. برای مثال"
msgid "The finalizer can be called directly as well. However the finalizer will invoke the callback at most once."
msgstr "همچنین میتوان نهاییساز را مستقیماً فراخوانی کرد. با این حال، نهاییساز کالبک را حداکثر یک بار فراخوانی میکند."
msgid "You can unregister a finalizer using its :meth:`~finalize.detach` method. This kills the finalizer and returns the arguments passed to the constructor when it was created."
msgstr "شما میتوانید با استفاده از متد :meth:`~finalize.detach` آن، ثبت یک نهاییساز را لغو کنید. این کار نهاییساز را از بین میبرد و آرگومانهایی را که هنگام ایجاد آن به سازنده داده شده بودند، برمیگرداند."
msgid "Unless you set the :attr:`~finalize.atexit` attribute to :const:`False`, a finalizer will be called when the program exits if it is still alive. For instance"
msgstr "مگر اینکه ویژگی :attr:`~finalize.atexit` را روی :const:`False` تنظیم کنید، نهاییساز در صورتی که هنوز زنده باشد، هنگام خروج برنامه فراخوانی خواهد شد. برای مثال"
msgid ""
">>> obj = Object()\n"
">>> weakref.finalize(obj, print, \"obj dead or exiting\")\n"
"<finalize object at ...; for 'Object' at ...>\n"
">>> exit()\n"
"obj dead or exiting"
msgstr ""
">>> obj = Object()\n"
">>> weakref.finalize(obj, print, \"obj dead or exiting\")\n"
"<finalize object at ...; for 'Object' at ...>\n"
">>> exit()\n"
"obj dead or exiting"
msgid "Comparing finalizers with :meth:`~object.__del__` methods"
msgstr "مقایسهی نهاییسازها با متدهای :meth:`~object.__del__`"
msgid "Suppose we want to create a class whose instances represent temporary directories. The directories should be deleted with their contents when the first of the following events occurs:"
msgstr "فرض کنید میخواهیم کلاسی بسازیم که نمونههای آن نشاندهندهی پوشههای موقت هستند. این پوشهها باید همراه با محتویاتشان حذف شوند، زمانی که نخستین مورد از رویدادهای زیر رخ دهد:"
msgid "the object is garbage collected,"
msgstr "شیء زبالهروبی میشود،"
msgid "the object's :meth:`!remove` method is called, or"
msgstr "متد :meth:`!remove` شیء فراخوانی میشود، یا"
msgid "the program exits."
msgstr "برنامه خارج میشود."
msgid "We might try to implement the class using a :meth:`~object.__del__` method as follows::"
msgstr "ممکن است بخواهید کلاس را با استفاده از متد :meth:`~object.__del__` بهصورت زیر پیادهسازی کنید::"
msgid ""
"class TempDir:\n"
" def __init__(self):\n"
" self.name = tempfile.mkdtemp()\n"
"\n"
" def remove(self):\n"
" if self.name is not None:\n"
" shutil.rmtree(self.name)\n"
" self.name = None\n"
"\n"
" @property\n"
" def removed(self):\n"
" return self.name is None\n"
"\n"
" def __del__(self):\n"
" self.remove()"
msgstr ""
"class TempDir:\n"
" def __init__(self):\n"
" self.name = tempfile.mkdtemp()\n"
"\n"
" def remove(self):\n"
" if self.name is not None:\n"
" shutil.rmtree(self.name)\n"
" self.name = None\n"
"\n"
" @property\n"
" def removed(self):\n"
" return self.name is None\n"
"\n"
" def __del__(self):\n"
" self.remove()"
msgid "Starting with Python 3.4, :meth:`~object.__del__` methods no longer prevent reference cycles from being garbage collected, and module globals are no longer forced to :const:`None` during :term:`interpreter shutdown`. So this code should work without any issues on CPython."
msgstr "از پایتون 3.4 به بعد، متدهای :meth:`~object.__del__` دیگر مانع از زبالهروبی شدن چرخههای ارجاع نمیشوند، و متغیرهای سراسری ماژول دیگر در :term:`interpreter shutdown` بهاجبار به :const:`None` تنظیم نمیشوند. بنابراین این کد باید بدون هیچ مشکلی در CPython اجرا شود."
msgid "However, handling of :meth:`~object.__del__` methods is notoriously implementation specific, since it depends on internal details of the interpreter's garbage collector implementation."
msgstr "با این حال، مدیریت متدهای :meth:`~object.__del__` بهطور معروفی به پیادهسازی وابسته است، زیرا به جزئیات داخلی پیادهسازی زبالهروبی مفسر بستگی دارد."
msgid "A more robust alternative can be to define a finalizer which only references the specific functions and objects that it needs, rather than having access to the full state of the object::"
msgstr "یک جایگزین مطمئنتر میتواند تعریف یک نهاییساز باشد که فقط به توابع و اشیاء خاصی که به آنها نیاز دارد ارجاع میدهد، نه اینکه به وضعیت کامل شیء دسترسی داشته باشد::"
msgid ""
"class TempDir:\n"
" def __init__(self):\n"
" self.name = tempfile.mkdtemp()\n"
" self._finalizer = weakref.finalize(self, shutil.rmtree, self.name)\n"
"\n"
" def remove(self):\n"
" self._finalizer()\n"
"\n"
" @property\n"
" def removed(self):\n"
" return not self._finalizer.alive"
msgstr ""
"class TempDir:\n"
" def __init__(self):\n"
" self.name = tempfile.mkdtemp()\n"
" self._finalizer = weakref.finalize(self, shutil.rmtree, self.name)\n"
"\n"
" def remove(self):\n"
" self._finalizer()\n"
"\n"
" @property\n"
" def removed(self):\n"
" return not self._finalizer.alive"
msgid "Defined like this, our finalizer only receives a reference to the details it needs to clean up the directory appropriately. If the object never gets garbage collected the finalizer will still be called at exit."
msgstr "با این تعریف، نهاییساز ما فقط ارجاعی به جزئیات مورد نیاز برای پاکسازی مناسب پوشه دریافت میکند. اگر شیء هرگز زبالهروبی نشود، نهاییساز همچنان در هنگام خروج فراخوانی خواهد شد."
msgid "The other advantage of weakref based finalizers is that they can be used to register finalizers for classes where the definition is controlled by a third party, such as running code when a module is unloaded::"
msgstr "مزیت دیگر نهاییسازهای مبتنی بر weakref این است که میتوان از آنها برای ثبت نهاییسازها برای کلاسهایی استفاده کرد که تعریف آنها توسط یک شخص ثالث کنترل میشود، مانند اجرای کد هنگامی که یک ماژول از حافظه خارج میشود::"
msgid ""
"import weakref, sys\n"
"def unloading_module():\n"
" # implicit reference to the module globals from the function body\n"
"weakref.finalize(sys.modules[__name__], unloading_module)"
msgstr ""
"import weakref, sys\n"
"def unloading_module():\n"
" # implicit reference to the module globals from the function body\n"
"weakref.finalize(sys.modules[__name__], unloading_module)"
msgid "If you create a finalizer object in a daemonic thread just as the program exits then there is the possibility that the finalizer does not get called at exit. However, in a daemonic thread :func:`atexit.register`, ``try: ... finally: ...`` and ``with: ...`` do not guarantee that cleanup occurs either."
msgstr "اگر درست هنگام خروج برنامه، یک شیء نهاییساز را در یک نخ daemon (daemonic thread) ایجاد کنید، این احتمال وجود دارد که finalizer در زمان خروج فراخوانی نشود. با این حال، در یک نخ daemon، :func:`atexit.register`، ``try: ... finally: ...`` و ``with: ...`` نیز تضمین نمیکنند که پاکسازی انجام شود."