Skip to content

Commit cccfd99

Browse files
committed
merge heads
2 parents 15ac311 + 1eb6d27 commit cccfd99

27 files changed

Lines changed: 247 additions & 61 deletions

Doc/library/codecs.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,8 @@ define in order to be compatible with the Python codec registry.
458458

459459
.. method:: reset()
460460

461-
Reset the encoder to the initial state.
461+
Reset the encoder to the initial state. The output is discarded: call
462+
``.encode('', final=True)`` to reset the encoder and to get the output.
462463

463464

464465
.. method:: IncrementalEncoder.getstate()

Doc/library/signal.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,9 @@ The :mod:`signal` module defines the following functions:
187187
Send the signal *signum* to the thread *thread_id*, another thread in the same
188188
process as the caller. The signal is asynchronously directed to thread.
189189

190-
*thread_id* can be read from the :attr:`~threading.Thread.ident` attribute
191-
of :attr:`threading.Thread`. For example,
192-
``threading.current_thread().ident`` gives the identifier of the current
193-
thread.
190+
Use :func:`threading.get_ident()` or the :attr:`~threading.Thread.ident`
191+
attribute of :attr:`threading.Thread` to get a 'thread identifier' for
192+
*thread_id*.
194193

195194
If *signum* is 0, then no signal is sent, but error checking is still
196195
performed; this can be used to check if a thread is still running.

Doc/library/threading.rst

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ This module defines the following functions and objects:
4848
returned.
4949

5050

51+
.. function:: get_ident()
52+
53+
Return the 'thread identifier' of the current thread. This is a nonzero
54+
integer. Its value has no direct meaning; it is intended as a magic cookie
55+
to be used e.g. to index a dictionary of thread-specific data. Thread
56+
identifiers may be recycled when a thread exits and another thread is
57+
created.
58+
59+
.. versionadded:: 3.3
60+
61+
5162
.. function:: enumerate()
5263

5364
Return a list of all :class:`Thread` objects currently alive. The list
@@ -332,10 +343,10 @@ impossible to detect the termination of alien threads.
332343
.. attribute:: ident
333344

334345
The 'thread identifier' of this thread or ``None`` if the thread has not
335-
been started. This is a nonzero integer. See the
336-
:func:`thread.get_ident()` function. Thread identifiers may be recycled
337-
when a thread exits and another thread is created. The identifier is
338-
available even after the thread has exited.
346+
been started. This is a nonzero integer. See the :func:`get_ident()`
347+
function. Thread identifiers may be recycled when a thread exits and
348+
another thread is created. The identifier is available even after the
349+
thread has exited.
339350

340351
.. method:: is_alive()
341352

Lib/logging/__init__.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,9 @@
4141
codecs = None
4242

4343
try:
44-
import _thread as thread
4544
import threading
4645
except ImportError: #pragma: no cover
47-
thread = None
46+
threading = None
4847

4948
__author__ = "Vinay Sajip <vinay_sajip@red-dove.com>"
5049
__status__ = "production"
@@ -199,7 +198,7 @@ def _checkLevel(level):
199198
#the lock would already have been acquired - so we need an RLock.
200199
#The same argument applies to Loggers and Manager.loggerDict.
201200
#
202-
if thread:
201+
if threading:
203202
_lock = threading.RLock()
204203
else: #pragma: no cover
205204
_lock = None
@@ -278,8 +277,8 @@ def __init__(self, name, level, pathname, lineno,
278277
self.created = ct
279278
self.msecs = (ct - int(ct)) * 1000
280279
self.relativeCreated = (self.created - _startTime) * 1000
281-
if logThreads and thread:
282-
self.thread = thread.get_ident()
280+
if logThreads and threading:
281+
self.thread = threading.get_ident()
283282
self.threadName = threading.current_thread().name
284283
else: # pragma: no cover
285284
self.thread = None
@@ -773,7 +772,7 @@ def createLock(self):
773772
"""
774773
Acquire a thread lock for serializing access to the underlying I/O.
775774
"""
776-
if thread:
775+
if threading:
777776
self.lock = threading.RLock()
778777
else: #pragma: no cover
779778
self.lock = None

Lib/packaging/install.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,21 +376,37 @@ def _remove_dist(dist, paths=sys.path):
376376

377377

378378
def remove(project_name, paths=sys.path, auto_confirm=True):
379-
"""Removes a single project from the installation"""
379+
"""Removes a single project from the installation.
380+
381+
Returns True on success
382+
"""
380383
dist = get_distribution(project_name, use_egg_info=True, paths=paths)
381384
if dist is None:
382385
raise PackagingError('Distribution "%s" not found' % project_name)
383386
files = dist.list_installed_files(local=True)
384387
rmdirs = []
385388
rmfiles = []
386389
tmp = tempfile.mkdtemp(prefix=project_name + '-uninstall')
390+
391+
def _move_file(source, target):
392+
try:
393+
os.rename(source, target)
394+
except OSError as err:
395+
return err
396+
return None
397+
398+
success = True
399+
error = None
387400
try:
388401
for file_, md5, size in files:
389402
if os.path.isfile(file_):
390403
dirname, filename = os.path.split(file_)
391404
tmpfile = os.path.join(tmp, filename)
392405
try:
393-
os.rename(file_, tmpfile)
406+
error = _move_file(file_, tmpfile)
407+
if error is not None:
408+
success = False
409+
break
394410
finally:
395411
if not os.path.isfile(file_):
396412
os.rename(tmpfile, file_)
@@ -401,6 +417,11 @@ def remove(project_name, paths=sys.path, auto_confirm=True):
401417
finally:
402418
shutil.rmtree(tmp)
403419

420+
if not success:
421+
logger.info('%r cannot be removed.', project_name)
422+
logger.info('Error: %s' % str(error))
423+
return False
424+
404425
logger.info('Removing %r: ', project_name)
405426

406427
for file_ in rmfiles:
@@ -447,6 +468,8 @@ def remove(project_name, paths=sys.path, auto_confirm=True):
447468
logger.info('Success: removed %d files and %d dirs',
448469
file_count, dir_count)
449470

471+
return True
472+
450473

451474
def install(project):
452475
logger.info('Getting information about %r...', project)

Lib/packaging/tests/test_uninstall.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import sys
44
from io import StringIO
5+
import stat
56

67
from packaging.database import disable_cache, enable_cache
78
from packaging.run import main
@@ -80,12 +81,9 @@ def install_dist(self, name='Foo', dirname=None, **kw):
8081
if not dirname:
8182
dirname = self.make_dist(name, **kw)
8283
os.chdir(dirname)
83-
old_out = sys.stdout
84+
old_out = sys.stderr
8485
sys.stderr = StringIO()
85-
try:
86-
dist = self.run_setup('install_dist', '--prefix=' + self.root_dir)
87-
finally:
88-
sys.sterr = old_out
86+
dist = self.run_setup('install_dist', '--prefix=' + self.root_dir)
8987
install_lib = self.get_path(dist, 'purelib')
9088
return dist, install_lib
9189

@@ -99,10 +97,30 @@ def test_uninstall(self):
9997
self.assertIsFile(install_lib, 'foo', '__init__.py')
10098
self.assertIsFile(install_lib, 'foo', 'sub', '__init__.py')
10199
self.assertIsFile(install_lib, 'Foo-0.1.dist-info', 'RECORD')
102-
remove('Foo', paths=[install_lib])
100+
self.assertTrue(remove('Foo', paths=[install_lib]))
103101
self.assertIsNotFile(install_lib, 'foo', 'sub', '__init__.py')
104102
self.assertIsNotFile(install_lib, 'Foo-0.1.dist-info', 'RECORD')
105103

104+
@unittest.skipIf(sys.platform == 'win32', 'deactivated for now')
105+
def test_remove_issue(self):
106+
# makes sure if there are OSErrors (like permission denied)
107+
# remove() stops and display a clean error
108+
dist, install_lib = self.install_dist('Meh')
109+
110+
# breaking os.rename
111+
old = os.rename
112+
113+
def _rename(source, target):
114+
raise OSError()
115+
116+
os.rename = _rename
117+
try:
118+
self.assertFalse(remove('Meh', paths=[install_lib]))
119+
finally:
120+
os.rename = old
121+
122+
self.assertTrue(remove('Meh', paths=[install_lib]))
123+
106124

107125
def test_suite():
108126
return unittest.makeSuite(UninstallTestCase)

Lib/reprlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import builtins
66
from itertools import islice
77
try:
8-
from _thread import get_ident
8+
from threading import get_ident
99
except ImportError:
1010
from _dummy_thread import get_ident
1111

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Python の開発は、1990 年ごろから開始されています。
2+
開発者の Guido van Rossum は教育用のプログラミング言語「ABC」の開発に参加していましたが、ABC は実用上の目的にはあまり適していませんでした。
3+
このため、Guido はより実用的なプログラミング言語の開発を開始し、英国 BBS 放送のコメディ番組「モンティ パイソン」のファンである Guido はこの言語を「Python」と名づけました。
4+
このような背景から生まれた Python の言語設計は、「シンプル」で「習得が容易」という目標に重点が置かれています。
5+
多くのスクリプト系言語ではユーザの目先の利便性を優先して色々な機能を言語要素として取り入れる場合が多いのですが、Python ではそういった小細工が追加されることはあまりありません。
6+
言語自体の機能は最小限に押さえ、必要な機能は拡張モジュールとして追加する、というのが Python のポリシーです。
7+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Python $B$N3+H/$O!"(B1990 $BG/$4$m$+$i3+;O$5$l$F$$$^$9!#(B
2+
$B3+H/<T$N(B Guido van Rossum $B$O650iMQ$N%W%m%0%i%_%s%08@8l!V(BABC$B!W$N3+H/$K;22C$7$F$$$^$7$?$,!"(BABC $B$O<BMQ>e$NL\E*$K$O$"$^$jE,$7$F$$$^$;$s$G$7$?!#(B
3+
$B$3$N$?$a!"(BGuido $B$O$h$j<BMQE*$J%W%m%0%i%_%s%08@8l$N3+H/$r3+;O$7!"1Q9q(B BBS $BJ|Aw$N%3%a%G%#HVAH!V%b%s%F%#(B $B%Q%$%=%s!W$N%U%!%s$G$"$k(B Guido $B$O$3$N8@8l$r!V(BPython$B!W$HL>$E$1$^$7$?!#(B
4+
$B$3$N$h$&$JGX7J$+$i@8$^$l$?(B Python $B$N8@8l@_7W$O!"!V%7%s%W%k!W$G!V=,F@$,MF0W!W$H$$$&L\I8$K=EE@$,CV$+$l$F$$$^$9!#(B
5+
$BB?$/$N%9%/%j%W%H7O8@8l$G$O%f!<%6$NL\@h$NMxJX@-$rM%@h$7$F?'!9$J5!G=$r8@8lMWAG$H$7$F<h$jF~$l$k>l9g$,B?$$$N$G$9$,!"(BPython $B$G$O$=$&$$$C$?>.:Y9)$,DI2C$5$l$k$3$H$O$"$^$j$"$j$^$;$s!#(B
6+
$B8@8l<+BN$N5!G=$O:G>.8B$K2!$5$(!"I,MW$J5!G=$O3HD%%b%8%e!<%k$H$7$FDI2C$9$k!"$H$$$&$N$,(B Python $B$N%]%j%7!<$G$9!#(B
7+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
◎ 파이썬(Python)은 배우기 쉽고, 강력한 프로그래밍 언어입니다. 파이썬은
2+
효율적인 고수준 데이터 구조와 간단하지만 효율적인 객체지향프로그래밍을
3+
지원합니다. 파이썬의 우아(優雅)한 문법과 동적 타이핑, 그리고 인터프리팅
4+
환경은 파이썬을 스크립팅과 여러 분야에서와 대부분의 플랫폼에서의 빠른
5+
애플리케이션 개발을 할 수 있는 이상적인 언어로 만들어줍니다.
6+
7+
☆첫가끝: 날아라 쓩~ 큼! 금없이 전니다. 그런거 다.

0 commit comments

Comments
 (0)