# Output file base name for HTML help builder.
htmlhelp_basename = 'python' + release.replace('.', '')
+# Split the index
+html_split_index = True
+
# Options for LaTeX output
# ------------------------
option involved in the error; be sure to do the same when calling
``parser.error()`` from your application code.
-If :mod:`optparse`'s default error-handling behaviour does not suite your needs,
-you'll need to subclass OptionParser and override ``exit()`` and/or
-:meth:`error`.
+If :mod:`optparse`'s default error-handling behaviour does not suit your needs,
+you'll need to subclass OptionParser and override its :meth:`exit` and/or
+:meth:`error` methods.
.. _optparse-putting-it-all-together:
.. ======================================================================
+.. _pep-0371:
+
+PEP 371: The ``multiprocessing`` Package
+=====================================================
+
+XXX write this.
+
+.. seealso::
+
+ :pep:`371` - Per-user ``site-packages`` Directory
+ PEP written by Jesse Noller and Richard Oudkerk;
+ implemented by Jesse Noller.
+
+.. ======================================================================
+
.. _pep-3101:
PEP 3101: Advanced String Formatting
"""
Flushes the stream.
"""
- if self.stream:
+ if self.stream and hasattr(self.stream, "flush"):
self.stream.flush()
def emit(self, record):
"""
if self.stream:
self.flush()
- self.stream.close()
+ if hasattr(self.stream, "close"):
+ self.stream.close()
StreamHandler.close(self)
self.stream = None
"""
global _uname_cache
+ no_os_uname = 0
if _uname_cache is not None:
return _uname_cache
+ processor = ''
+
# Get some infos from the builtin os.uname API...
try:
system,node,release,version,machine = os.uname()
-
except AttributeError:
- # Hmm, no uname... we'll have to poke around the system then.
- system = sys.platform
- release = ''
- version = ''
- node = _node()
- machine = ''
- processor = ''
- use_syscmd_ver = 1
+ no_os_uname = 1
+
+ if no_os_uname or not filter(None, (system, node, release, version, machine)):
+ # Hmm, no there is either no uname or uname has returned
+ #'unknowns'... we'll have to poke around the system then.
+ if no_os_uname:
+ system = sys.platform
+ release = ''
+ version = ''
+ node = _node()
+ machine = ''
+
+ use_syscmd_ver = 01
# Try win32_ver() on win32 platforms
if system == 'win32':
# available on Win XP and later; see
# http://support.microsoft.com/kb/888731 and
# http://www.geocities.com/rick_lively/MANUALS/ENV/MSWIN/PROCESSI.HTM
- machine = os.environ.get('PROCESSOR_ARCHITECTURE', '')
- processor = os.environ.get('PROCESSOR_IDENTIFIER', machine)
+ if not machine:
+ machine = os.environ.get('PROCESSOR_ARCHITECTURE', '')
+ if not processor:
+ processor = os.environ.get('PROCESSOR_IDENTIFIER', machine)
# Try the 'ver' system command available on some
# platforms
release,(version,stage,nonrel),machine = mac_ver()
system = 'MacOS'
- else:
- # System specific extensions
- if system == 'OpenVMS':
- # OpenVMS seems to have release and version mixed up
- if not release or release == '0':
- release = version
- version = ''
- # Get processor information
- try:
- import vms_lib
- except ImportError:
- pass
- else:
- csid, cpu_number = vms_lib.getsyi('SYI$_CPU',0)
- if (cpu_number >= 128):
- processor = 'Alpha'
- else:
- processor = 'VAX'
+ # System specific extensions
+ if system == 'OpenVMS':
+ # OpenVMS seems to have release and version mixed up
+ if not release or release == '0':
+ release = version
+ version = ''
+ # Get processor information
+ try:
+ import vms_lib
+ except ImportError:
+ pass
else:
- # Get processor information from the uname system command
- processor = _syscmd_uname('-p','')
+ csid, cpu_number = vms_lib.getsyi('SYI$_CPU',0)
+ if (cpu_number >= 128):
+ processor = 'Alpha'
+ else:
+ processor = 'VAX'
+ if not processor:
+ # Get processor information from the uname system command
+ processor = _syscmd_uname('-p','')
- # 'unknown' is not really any useful as information; we'll convert
- # it to '' which is more portable
+ #If any unknowns still exist, replace them with ''s, which are more portable
if system == 'unknown':
system = ''
if node == 'unknown':
class Base2(object):
mykey = 'from Base2'
-class X(Base):
- # you can't add a non-string key to X.__dict__, but it can be
- # there from the beginning :-)
- locals()[MyKey()] = 5
+# you can't add a non-string key to X.__dict__, but it can be
+# there from the beginning :-)
+X = type('X', (Base,), {MyKey(): 5})
print(X.mykey)
# I get a segfault, or a slightly wrong assertion error in a debug build.
self.assertEquals(l5(1, 2), 5)
self.assertEquals(l5(1, 2, 3), 6)
check_syntax_error(self, "lambda x: x = 2")
+ check_syntax_error(self, "lambda (None,): None")
l6 = lambda x, y, *, k=20: x+y+k
self.assertEquals(l6(1,2), 1+2+20)
self.assertEquals(l6(1,2,k=10), 1+2+10)
class LE:
def __init__(self, x):
self.x = x
- def __lt__(self, other):
+ def __le__(self, other):
return self.x >= other.x
data = [random.random() for i in range(100)]
target = sorted(data, reverse=True)
+ print("HASATTR", hasattr(LE(0), "__lt__"), LE(0).__lt__)
self.assertEqual(hsort(data, LT), target)
self.assertEqual(hsort(data, LE), target)
import sys
ISBIGENDIAN = sys.byteorder == "big"
+IS32BIT = sys.maxsize == 0x7fffffff
del sys
try:
for c in [b'\x01', b'\x7f', b'\xff', b'\x0f', b'\xf0']:
self.assertTrue(struct.unpack('>?', c)[0])
+ if IS32BIT:
+ def test_crasher(self):
+ self.assertRaises(MemoryError, struct.pack, "357913941b", "a")
+
+
def test_main():
run_unittest(StructTest)
self.check_sizeof(32768, h + self.align(2) + 2)
self.check_sizeof(32768*32768-1, h + self.align(2) + 2)
self.check_sizeof(32768*32768, h + self.align(2) + 4)
+ # tuple
+ self.check_sizeof((), h)
+ self.check_sizeof((1,2,3), h + 3*p)
def test_main():
Gustavo Niemeyer
Oscar Nierstrasz
Hrvoje Niksic
+Jesse Noller
Bill Noon
Stefan Norberg
Tim Northover
Douglas Orr
Denis S. Otkidach
Michael Otteneder
+R. M. Oudkerk
Russel Owen
Ondrej Palkovsky
Mike Pall
Monty Taylor
Amy Taylor
Tobias Thelen
+James Thomas
Robin Thomas
Eric Tiedemann
Tracy Tims
Permissions History
-------------------
+- Jesse Noller was given SVN access on 16 June 2008 by Georg Brandl,
+ for work on the multiprocessing module.
+
- Gregor Lingl was given SVN access on 10 June 2008 by MvL,
for work on the turtle module.
return NULL;
}
shape = PyTuple_New(dict->ndim);
+ if (shape == NULL)
+ return NULL;
for (i = 0; i < (int)dict->ndim; ++i)
PyTuple_SET_ITEM(shape, i, PyLong_FromSsize_t(dict->shape[i]));
}
}
+ /* check for overflow */
+ if ((len + 1) > (PY_SSIZE_T_MAX / sizeof(formatcode))) {
+ PyErr_NoMemory();
+ return -1;
+ }
+
self->s_size = size;
self->s_len = len;
codes = PyMem_MALLOC((len + 1) * sizeof(formatcode));
if (op == NULL) {
return NULL;
}
+ op->ob_descr = descr;
+ op->allocated = size;
+ op->weakreflist = NULL;
Py_SIZE(op) = size;
if (size <= 0) {
op->ob_item = NULL;
else {
op->ob_item = PyMem_NEW(char, nbytes);
if (op->ob_item == NULL) {
- PyObject_Del(op);
+ Py_DECREF(op);
return PyErr_NoMemory();
}
}
- op->ob_descr = descr;
- op->allocated = size;
- op->weakreflist = NULL;
op->ob_exports = 0;
return (PyObject *) op;
}
"can only extend with array of same kind");
return -1;
}
+ if ((Py_SIZE(self) > PY_SSIZE_T_MAX - Py_SIZE(b)) ||
+ ((Py_SIZE(self) + Py_SIZE(b)) > PY_SSIZE_T_MAX / self->ob_descr->itemsize)) {
+ PyErr_NoMemory();
+ return -1;
+ }
size = Py_SIZE(self) + Py_SIZE(b);
PyMem_RESIZE(self->ob_item, char, size*self->ob_descr->itemsize);
if (self->ob_item == NULL) {
- PyObject_Del(self);
- PyErr_NoMemory();
+ PyErr_NoMemory();
return -1;
}
memcpy(self->ob_item + Py_SIZE(self)*self->ob_descr->itemsize,
}
+static PyObject *
+tuple_sizeof(PyTupleObject *self)
+{
+ Py_ssize_t res;
+
+ res = PyTuple_Type.tp_basicsize + Py_SIZE(self) * sizeof(PyObject *);
+ return PyLong_FromSsize_t(res);
+}
+
PyDoc_STRVAR(index_doc,
"T.index(value, [start, [stop]]) -> integer -- return first index of value");
PyDoc_STRVAR(count_doc,
"T.count(value) -> integer -- return number of occurrences of value");
+PyDoc_STRVAR(sizeof_doc,
+"T.__sizeof__() -- size of T in memory, in bytes");
static PyMethodDef tuple_methods[] = {
{"__getnewargs__", (PyCFunction)tuple_getnewargs, METH_NOARGS},
+ {"__sizeof__", (PyCFunction)tuple_sizeof, METH_NOARGS, sizeof_doc},
{"index", (PyCFunction)tupleindex, METH_VARARGS, index_doc},
{"count", (PyCFunction)tuplecount, METH_O, count_doc},
{NULL, NULL} /* sentinel */
size = PyBytes_Size(p->str);
newsize = size + size + 1024;
if (newsize > 32*1024*1024) {
- newsize = size + 1024*1024;
+ newsize = size + (size >> 3); /* 12.5% overallocation */
}
if (_PyBytes_Resize(&p->str, newsize) != 0) {
p->ptr = p->end = NULL;
def init_database(name, schema,
ProductName, ProductCode, ProductVersion,
- Manufacturer):
+ Manufacturer,
+ request_uac = False):
try:
os.unlink(name)
except OSError:
si.SetProperty(PID_AUTHOR, Manufacturer)
si.SetProperty(PID_TEMPLATE, msi_type)
si.SetProperty(PID_REVNUMBER, gen_uuid())
- si.SetProperty(PID_WORDCOUNT, 2) # long file names, compressed, original media
+ if request_uac:
+ wc = 2 # long file names, compressed, original media
+ else:
+ wc = 2 | 8 # +never invoke UAC
+ si.SetProperty(PID_WORDCOUNT, wc)
si.SetProperty(PID_PAGECOUNT, 200)
si.SetProperty(PID_APPNAME, "Python MSI Library")
# XXX more properties