Kaydet (Commit) 107690c2 authored tarafından Georg Brandl's avatar Georg Brandl

Merged revisions 76884-76885,76887,76889-76890,76895 via svnmerge from

svn+ssh://svn.python.org/python/branches/py3k

................
  r76884 | georg.brandl | 2009-12-19 18:35:49 +0100 (Sa, 19 Dez 2009) | 9 lines

  Merged revisions 76883 via svnmerge from
  svn+ssh://pythondev@svn.python.org/python/trunk

  ........
    r76883 | georg.brandl | 2009-12-19 18:34:32 +0100 (Sa, 19 Dez 2009) | 1 line

    #7521: remove Py_GetBuildNumber(), which was removed in favor of Py_GetBuildInfo().
  ........
................
  r76885 | georg.brandl | 2009-12-19 18:36:20 +0100 (Sa, 19 Dez 2009) | 1 line

  #7521: remove PyEval_GetRestricted() from the docs.
................
  r76887 | georg.brandl | 2009-12-19 18:46:40 +0100 (Sa, 19 Dez 2009) | 9 lines

  Recorded merge of revisions 76886 via svnmerge from
  svn+ssh://pythondev@svn.python.org/python/trunk

  ........
    r76886 | georg.brandl | 2009-12-19 18:43:33 +0100 (Sa, 19 Dez 2009) | 1 line

    #7493: review of Design FAQ by Florent Xicluna.
  ........
................
  r76889 | georg.brandl | 2009-12-19 18:57:51 +0100 (Sa, 19 Dez 2009) | 1 line

  #7499: Review of Library FAQ by Florent Xicluna.
................
  r76890 | georg.brandl | 2009-12-19 18:59:59 +0100 (Sa, 19 Dez 2009) | 1 line

  #7500: add "Python 3 review needed" comments and fix a few obvious errors.
................
  r76895 | georg.brandl | 2009-12-19 19:23:28 +0100 (Sa, 19 Dez 2009) | 1 line

  #7380: Fix some str/bytearray/bytes issues in uuid docs and implementation.
................
üst c06f34fa
......@@ -285,13 +285,6 @@ Initialization, Finalization, and Threads
modify its value. The value is available to Python code as :data:`sys.version`.
.. cfunction:: const char* Py_GetBuildNumber()
Return a string representing the Subversion revision that this Python executable
was built from. This number is a string because it may contain a trailing 'M'
if Python was built from a mixed revision source tree.
.. cfunction:: const char* Py_GetPlatform()
.. index:: single: platform (in module sys)
......
......@@ -29,12 +29,6 @@ Reflection
currently executing.
.. cfunction:: int PyEval_GetRestricted()
If there is a current frame and it is executing in restricted mode, return true,
otherwise false.
.. cfunction:: const char* PyEval_GetFuncName(PyObject *func)
Return the name of *func* if it is a function, class or instance object, else the
......
......@@ -234,8 +234,10 @@ code breakage.
.. XXX talk about protocols?
Note that for string operations Python has moved from external functions (the
``string`` module) to methods. However, ``len()`` is still a function.
.. note::
For string operations, Python has moved from external functions (the
``string`` module) to methods. However, ``len()`` is still a function.
Why is join() a string method instead of a list or tuple method?
......@@ -306,14 +308,15 @@ expensive. In versions of Python prior to 2.0 it was common to use this idiom::
This only made sense when you expected the dict to have the key almost all the
time. If that wasn't the case, you coded it like this::
if dict.has_key(key):
if key in dict(key):
value = dict[key]
else:
dict[key] = getvalue(key)
value = dict[key]
(In Python 2.0 and higher, you can code this as ``value = dict.setdefault(key,
getvalue(key))``.)
For this specific case, you could also use ``value = dict.setdefault(key,
getvalue(key))``, but only if the ``getvalue()`` call is cheap enough because it
is evaluated in all cases.
Why isn't there a switch or case statement in Python?
......@@ -750,7 +753,7 @@ requested again. This is called "memoizing", and can be implemented like this::
# Callers will never provide a third parameter for this function.
def expensive (arg1, arg2, _cache={}):
if _cache.has_key((arg1, arg2)):
if (arg1, arg2) in _cache:
return _cache[(arg1, arg2)]
# Calculate the value
......
......@@ -7,6 +7,9 @@ Extending/Embedding FAQ
.. highlight:: c
.. XXX need review for Python 3.
Can I create my own functions in C?
-----------------------------------
......@@ -53,8 +56,7 @@ with a tool such as `SWIG <http://www.swig.org>`_. `SIP
<http://www.riverbankcomputing.co.uk/software/sip/>`__, `CXX
<http://cxx.sourceforge.net/>`_ `Boost
<http://www.boost.org/libs/python/doc/index.html>`_, or `Weave
<http://www.scipy.org/Weave>`_ are also alternatives for wrapping
C++ libraries.
<http://www.scipy.org/Weave>`_ are also alternatives for wrapping C++ libraries.
How can I execute arbitrary Python statements from C?
......@@ -161,8 +163,8 @@ Sample code and use for catching stdout:
...
>>> import sys
>>> sys.stdout = StdoutCatcher()
>>> print 'foo'
>>> print 'hello world!'
>>> print('foo')
>>> print('hello world!')
>>> sys.stderr.write(sys.stdout.data)
foo
hello world!
......@@ -199,7 +201,11 @@ begin by reading :ref:`the "Extending and Embedding" document
whole lot of difference between C and C++ -- so the strategy of building a new
Python type around a C structure (pointer) type will also work for C++ objects.
For C++ libraries, see :ref:`c-wrapper-software`.
For C++ libraries, you can look at `SIP
<http://www.riverbankcomputing.co.uk/sip/>`_, `CXX
<http://cxx.sourceforge.net/>`_, `Boost
<http://www.boost.org/libs/python/doc/index.html>`_, `Weave
<http://www.scipy.org/Weave>`_ or `SWIG <http://www.swig.org>`_
I added a module using the Setup file and the make fails; why?
......@@ -468,12 +474,9 @@ checking the value of sys.maxunicode:
>>> import sys
>>> if sys.maxunicode > 65535:
... print 'UCS4 build'
... print('UCS4 build')
... else:
... print 'UCS2 build'
... print('UCS2 build')
The only way to solve this problem is to use extension modules compiled with a
Python binary built using the same size for Unicode characters.
......@@ -6,6 +6,9 @@ Graphic User Interface FAQ
.. contents::
.. XXX need review for Python 3.
General GUI Questions
=====================
......@@ -159,6 +162,3 @@ The most common cause is that the widget to which the binding applies doesn't
have "keyboard focus". Check out the Tk documentation for the focus command.
Usually a widget is given the keyboard focus by clicking in it (but not for
labels; see the takefocus option).
This diff is collapsed.
......@@ -8,6 +8,10 @@ Python on Windows FAQ
.. contents::
.. XXX need review for Python 3.
XXX need review for Windows Vista/Seven?
How do I run a Python program under Windows?
--------------------------------------------
......@@ -67,7 +71,7 @@ Python statements or expressions interactively and have them executed or
evaluated while you wait. This is one of Python's strongest features. Check it
by entering a few expressions of your choice and seeing the results::
>>> print "Hello"
>>> print("Hello")
Hello
>>> "Hello" * 3
HelloHelloHello
......@@ -507,7 +511,7 @@ Example::
import win32pipe
f = win32pipe.popen('dir /c c:\\')
print f.readlines()
print(f.readlines())
f.close()
......
.. _urllib-howto:
***********************************************************
HOWTO Fetch Internet Resources Using The urllib Package
***********************************************************
......
......@@ -31,9 +31,9 @@ random UUID.
UUID('{12345678-1234-5678-1234-567812345678}')
UUID('12345678123456781234567812345678')
UUID('urn:uuid:12345678-1234-5678-1234-567812345678')
UUID(bytes='\x12\x34\x56\x78'*4)
UUID(bytes_le='\x78\x56\x34\x12\x34\x12\x78\x56' +
'\x12\x34\x56\x78\x12\x34\x56\x78')
UUID(bytes=b'\x12\x34\x56\x78'*4)
UUID(bytes_le=b'\x78\x56\x34\x12\x34\x12\x78\x56' +
b'\x12\x34\x56\x78\x12\x34\x56\x78')
UUID(fields=(0x12345678, 0x1234, 0x5678, 0x12, 0x34, 0x567812345678))
UUID(int=0x12345678123456781234567812345678)
......@@ -247,7 +247,7 @@ Here are some examples of typical usage of the :mod:`uuid` module::
# get the raw 16 bytes of the UUID
>>> x.bytes
'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f'
b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f'
# make a UUID from a 16-byte string
>>> uuid.UUID(bytes=x.bytes)
......
from unittest import TestCase
from test import support
import builtins
import uuid
def importable(name):
......@@ -176,6 +177,11 @@ class TestUUID(TestCase):
for u in equivalents:
for v in equivalents:
equal(u, v)
# Bug 7380: "bytes" and "bytes_le" should give the same type.
equal(type(u.bytes), builtins.bytes)
equal(type(u.bytes_le), builtins.bytes)
ascending.append(u)
# Test comparison of UUIDs.
......
......@@ -13,7 +13,7 @@ Typical usage:
>>> import uuid
# make a UUID based on the host ID and current time
>>> uuid.uuid1()
>>> uuid.uuid1() # doctest: +SKIP
UUID('a8098c1a-f86e-11da-bd1a-00112444be1e')
# make a UUID using an MD5 hash of a namespace UUID and a name
......@@ -21,7 +21,7 @@ Typical usage:
UUID('6fa459ea-ee8a-3ca4-894e-db77e160355e')
# make a random UUID
>>> uuid.uuid4()
>>> uuid.uuid4() # doctest: +SKIP
UUID('16fd2706-8baf-433b-82eb-8c7fada847da')
# make a UUID using a SHA-1 hash of a namespace UUID and a name
......@@ -237,7 +237,7 @@ class UUID(object):
bytes = bytearray()
for shift in range(0, 128, 8):
bytes.insert(0, (self.int >> shift) & 0xff)
return bytes
return bytes_(bytes)
@property
def bytes_le(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment