Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Checkins

cpython (merge default -> default): Merge

 

 

First page Previous page 1 2 3 Next page Last page  View All Python checkins RSS feed   Index | Next | Previous | View Threaded


python-checkins at python

May 4, 2012, 1:06 PM

Post #51 of 57 (91 views)
Permalink
cpython (merge default -> default): merge [In reply to]

http://hg.python.org/cpython/rev/20f8b105525e
changeset: 76759:20f8b105525e
parent: 76758:7fbb4443ffb7
parent: 76756:4459d82ff127
user: Brett Cannon <brett [at] python>
date: Fri May 04 16:04:59 2012 -0400
summary:
merge

files:
PCbuild/make_buildinfo.c | 67 +++++++++++++++++++++++++++-
1 files changed, 66 insertions(+), 1 deletions(-)


diff --git a/PCbuild/make_buildinfo.c b/PCbuild/make_buildinfo.c
--- a/PCbuild/make_buildinfo.c
+++ b/PCbuild/make_buildinfo.c
@@ -2,6 +2,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
+#include <io.h>

#define CMD_SIZE 500

@@ -61,6 +62,51 @@
return 1;
}

+const char DELIMS[] = { " \n" };
+
+int get_mercurial_info(char * hgbranch, char * hgtag, char * hgrev, int size)
+{
+ int result = 0;
+ char filename[CMD_SIZE];
+ char cmdline[CMD_SIZE];
+
+ strcpy_s(filename, CMD_SIZE, "tmpXXXXXX");
+ if (_mktemp_s(filename, CMD_SIZE) == 0) {
+ int rc;
+
+ strcpy_s(cmdline, CMD_SIZE, "hg id -bit > ");
+ strcat_s(cmdline, CMD_SIZE, filename);
+ rc = system(cmdline);
+ if (rc == 0) {
+ FILE * fp;
+
+ if (fopen_s(&fp, filename, "r") == 0) {
+ char * cp = fgets(cmdline, CMD_SIZE, fp);
+
+ if (cp) {
+ char * context = NULL;
+ char * tp = strtok_s(cp, DELIMS, &context);
+ if (tp) {
+ strcpy_s(hgrev, size, tp);
+ tp = strtok_s(NULL, DELIMS, &context);
+ if (tp) {
+ strcpy_s(hgbranch, size, tp);
+ tp = strtok_s(NULL, DELIMS, &context);
+ if (tp) {
+ strcpy_s(hgtag, size, tp);
+ result = 1;
+ }
+ }
+ }
+ }
+ fclose(fp);
+ }
+ }
+ _unlink(filename);
+ }
+ return result;
+}
+
int main(int argc, char*argv[])
{
char command[CMD_SIZE] = "cl.exe -c -D_WIN32 -DUSE_DL_EXPORT -D_WINDOWS -DWIN32 -D_WINDLL ";
@@ -109,8 +155,27 @@
strcat_s(command, CMD_SIZE, "\"");
strcat_s(command, CMD_SIZE, tmppath);
strcat_s(command, CMD_SIZE, "getbuildinfo2.c\" -DSUBWCREV ");
- } else
+ }
+ else {
+ char hgtag[CMD_SIZE];
+ char hgbranch[CMD_SIZE];
+ char hgrev[CMD_SIZE];
+
+ if (get_mercurial_info(hgbranch, hgtag, hgrev, CMD_SIZE)) {
+ strcat_s(command, CMD_SIZE, "-DHGBRANCH=\\\"");
+ strcat_s(command, CMD_SIZE, hgbranch);
+ strcat_s(command, CMD_SIZE, "\\\"");
+
+ strcat_s(command, CMD_SIZE, " -DHGTAG=\\\"");
+ strcat_s(command, CMD_SIZE, hgtag);
+ strcat_s(command, CMD_SIZE, "\\\"");
+
+ strcat_s(command, CMD_SIZE, " -DHGVERSION=\\\"");
+ strcat_s(command, CMD_SIZE, hgrev);
+ strcat_s(command, CMD_SIZE, "\\\" ");
+ }
strcat_s(command, CMD_SIZE, "..\\Modules\\getbuildinfo.c");
+ }
strcat_s(command, CMD_SIZE, " -Fo\"");
strcat_s(command, CMD_SIZE, tmppath);
strcat_s(command, CMD_SIZE, "getbuildinfo.o\" -I..\\Include -I..\\PC");

--
Repository URL: http://hg.python.org/cpython


python-checkins at python

May 4, 2012, 1:18 PM

Post #52 of 57 (91 views)
Permalink
cpython (merge default -> default): Merge [In reply to]

http://hg.python.org/cpython/rev/5b2f40ed32fd
changeset: 76763:5b2f40ed32fd
parent: 76762:5bcce348571e
parent: 76761:06944dad6098
user: Antoine Pitrou <solipsis [at] pitrou>
date: Fri May 04 22:16:09 2012 +0200
summary:
Merge

files:
Python/import.c | 22 ----------------------
Python/importdl.h | 15 ---------------
2 files changed, 0 insertions(+), 37 deletions(-)


diff --git a/Python/import.c b/Python/import.c
--- a/Python/import.c
+++ b/Python/import.c
@@ -2091,17 +2091,6 @@
{NULL, NULL} /* sentinel */
};

-static int
-setint(PyObject *d, char *name, int value)
-{
- PyObject *v;
- int err;
-
- v = PyLong_FromLong((long)value);
- err = PyDict_SetItemString(d, name, v);
- Py_XDECREF(v);
- return err;
-}

static struct PyModuleDef impmodule = {
PyModuleDef_HEAD_INIT,
@@ -2127,17 +2116,6 @@
if (d == NULL)
goto failure;

- if (setint(d, "SEARCH_ERROR", SEARCH_ERROR) < 0) goto failure;
- if (setint(d, "PY_SOURCE", PY_SOURCE) < 0) goto failure;
- if (setint(d, "PY_COMPILED", PY_COMPILED) < 0) goto failure;
- if (setint(d, "C_EXTENSION", C_EXTENSION) < 0) goto failure;
- if (setint(d, "PY_RESOURCE", PY_RESOURCE) < 0) goto failure;
- if (setint(d, "PKG_DIRECTORY", PKG_DIRECTORY) < 0) goto failure;
- if (setint(d, "C_BUILTIN", C_BUILTIN) < 0) goto failure;
- if (setint(d, "PY_FROZEN", PY_FROZEN) < 0) goto failure;
- if (setint(d, "PY_CODERESOURCE", PY_CODERESOURCE) < 0) goto failure;
- if (setint(d, "IMP_HOOK", IMP_HOOK) < 0) goto failure;
-
return m;
failure:
Py_XDECREF(m);
diff --git a/Python/importdl.h b/Python/importdl.h
--- a/Python/importdl.h
+++ b/Python/importdl.h
@@ -6,21 +6,6 @@
#endif


-/* Definitions for dynamic loading of extension modules */
-enum filetype {
- SEARCH_ERROR,
- PY_SOURCE,
- PY_COMPILED,
- C_EXTENSION,
- PY_RESOURCE, /* Mac only */
- PKG_DIRECTORY,
- C_BUILTIN,
- PY_FROZEN,
- PY_CODERESOURCE, /* Mac only */
- IMP_HOOK
-};
-
-
extern const char *_PyImport_DynLoadFiletab[];

extern PyObject *_PyImport_LoadDynamicModule(PyObject *name, PyObject *pathname,

--
Repository URL: http://hg.python.org/cpython


python-checkins at python

May 4, 2012, 2:18 PM

Post #53 of 57 (89 views)
Permalink
cpython (merge default -> default): Merge [In reply to]

http://hg.python.org/cpython/rev/57cbffae4f74
changeset: 76767:57cbffae4f74
parent: 76766:66ccd993dfdf
parent: 76765:146001e3364d
user: Antoine Pitrou <solipsis [at] pitrou>
date: Fri May 04 23:17:03 2012 +0200
summary:
Merge

files:
Lib/importlib/_bootstrap.py | 7 +------
Python/importlib.h | Bin
2 files changed, 1 insertions(+), 6 deletions(-)


diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -1151,12 +1151,7 @@


def _install(sys_module, _imp_module):
- """Install importlib as the implementation of import.
-
- It is assumed that _imp and sys have been imported and injected into the
- global namespace for the module prior to calling this function.
-
- """
+ """Install importlib as the implementation of import."""
_setup(sys_module, _imp_module)
extensions = ExtensionFileLoader, _imp_module.extension_suffixes(), False
source = SourceFileLoader, _SOURCE_SUFFIXES, True
diff --git a/Python/importlib.h b/Python/importlib.h
index 9c531f013f45b202d3523994af2799d4270339a7..292308fc78123e9fa10c7131bb110c47559975dd
GIT binary patch
[stripped]

--
Repository URL: http://hg.python.org/cpython


python-checkins at python

May 12, 2012, 10:05 AM

Post #54 of 57 (83 views)
Permalink
cpython (merge default -> default): Merge [In reply to]

http://hg.python.org/cpython/rev/3b368c4ad7c5
changeset: 76884:3b368c4ad7c5
parent: 76883:85824b819bcb
parent: 76882:9d9495fabeb9
user: Antoine Pitrou <solipsis [at] pitrou>
date: Sat May 12 19:02:47 2012 +0200
summary:
Merge

files:
Objects/unicodeobject.c | 14 ++++++++++----
1 files changed, 10 insertions(+), 4 deletions(-)


diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -9075,12 +9075,15 @@

kind1 = PyUnicode_KIND(str_obj);
kind2 = PyUnicode_KIND(sub_obj);
- kind = kind2;
+ kind = kind1;
buf1 = PyUnicode_DATA(str_obj);
buf2 = PyUnicode_DATA(sub_obj);
if (kind2 != kind) {
- if (kind2 > kind)
- return 0;
+ if (kind2 > kind) {
+ Py_DECREF(sub_obj);
+ Py_DECREF(str_obj);
+ return 0;
+ }
buf2 = _PyUnicode_AsKind(sub_obj, kind);
}
if (!buf2)
@@ -10659,8 +10662,11 @@
buf1 = PyUnicode_DATA(str);
buf2 = PyUnicode_DATA(sub);
if (kind2 != kind) {
- if (kind2 > kind)
+ if (kind2 > kind) {
+ Py_DECREF(sub);
+ Py_DECREF(str);
return 0;
+ }
buf2 = _PyUnicode_AsKind(sub, kind);
}
if (!buf2) {

--
Repository URL: http://hg.python.org/cpython


python-checkins at python

May 12, 2012, 2:52 PM

Post #55 of 57 (80 views)
Permalink
cpython (merge default -> default): Merge [In reply to]

http://hg.python.org/cpython/rev/964cfda9ccc5
changeset: 76893:964cfda9ccc5
parent: 76892:10e8b97d0fd7
parent: 76889:8d85f9920878
user: Antoine Pitrou <solipsis [at] pitrou>
date: Sat May 12 23:43:55 2012 +0200
summary:
Merge

files:
Lib/test/test_shutil.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)


diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py
--- a/Lib/test/test_shutil.py
+++ b/Lib/test/test_shutil.py
@@ -343,7 +343,7 @@
orig_setxattr = os.setxattr
os.setxattr = _raise_on_user_foo
shutil._copyxattr(src, dst)
- self.assertEqual(['user.bar'], os.listxattr(dst))
+ self.assertIn('user.bar', os.listxattr(dst))
finally:
os.setxattr = orig_setxattr


--
Repository URL: http://hg.python.org/cpython


python-checkins at python

May 12, 2012, 2:52 PM

Post #56 of 57 (83 views)
Permalink
cpython (merge default -> default): Merge [In reply to]

http://hg.python.org/cpython/rev/5bd55fb3e091
changeset: 76894:5bd55fb3e091
parent: 76893:964cfda9ccc5
parent: 76891:7bf8ac742d2f
user: Antoine Pitrou <solipsis [at] pitrou>
date: Sat May 12 23:44:59 2012 +0200
summary:
Merge

files:
Doc/library/importlib.rst | 14 ++++++
Lib/importlib/__init__.py | 24 ++++++++++
Lib/importlib/test/test_api.py | 50 +++++++++++++++++++++-
Lib/pyclbr.py | 25 +++++++---
Lib/test/test_unicode.py | 8 ---
Misc/NEWS | 2 +
6 files changed, 105 insertions(+), 18 deletions(-)


diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst
--- a/Doc/library/importlib.rst
+++ b/Doc/library/importlib.rst
@@ -86,6 +86,20 @@
that was imported (e.g. ``pkg.mod``), while :func:`__import__` returns the
top-level package or module (e.g. ``pkg``).

+.. function:: find_loader(name, path=None)
+
+ Find the loader for a module, optionally within the specified *path*. If the
+ module is in :attr:`sys.modules`, then ``sys.modules[name].__loader__`` is
+ returned (unless the loader would be ``None``, in which case
+ :exc:`ValueError` is raised). Otherwise a search using :attr:`sys.meta_path`
+ is done. ``None`` is returned if no loader is found.
+
+ A dotted name does not have its parent's implicitly imported. If that is
+ desired (although not nessarily required to find the loader, it will most
+ likely be needed if the loader actually is used to load the module), then
+ you will have to import the packages containing the module prior to calling
+ this function.
+
.. function:: invalidate_caches()

Invalidate the internal caches of the finders stored at
diff --git a/Lib/importlib/__init__.py b/Lib/importlib/__init__.py
--- a/Lib/importlib/__init__.py
+++ b/Lib/importlib/__init__.py
@@ -29,6 +29,30 @@
finder.invalidate_caches()


+def find_loader(name, path=None):
+ """Find the loader for the specified module.
+
+ First, sys.modules is checked to see if the module was already imported. If
+ so, then sys.modules[name].__loader__ is returned. If that happens to be
+ set to None, then ValueError is raised. If the module is not in
+ sys.modules, then sys.meta_path is searched for a suitable loader with the
+ value of 'path' given to the finders. None is returned if no loader could
+ be found.
+
+ Dotted names do not have their parent packages implicitly imported.
+
+ """
+ try:
+ loader = sys.modules[name].__loader__
+ if loader is None:
+ raise ValueError('{}.__loader__ is None'.format(name))
+ else:
+ return loader
+ except KeyError:
+ pass
+ return _bootstrap._find_module(name, path)
+
+
def import_module(name, package=None):
"""Import a module.

diff --git a/Lib/importlib/test/test_api.py b/Lib/importlib/test/test_api.py
--- a/Lib/importlib/test/test_api.py
+++ b/Lib/importlib/test/test_api.py
@@ -85,6 +85,54 @@
self.assertEqual(b_load_count, 1)


+class FindLoaderTests(unittest.TestCase):
+
+ class FakeMetaFinder:
+ @staticmethod
+ def find_module(name, path=None): return name, path
+
+ def test_sys_modules(self):
+ # If a module with __loader__ is in sys.modules, then return it.
+ name = 'some_mod'
+ with util.uncache(name):
+ module = imp.new_module(name)
+ loader = 'a loader!'
+ module.__loader__ = loader
+ sys.modules[name] = module
+ found = importlib.find_loader(name)
+ self.assertEqual(loader, found)
+
+ def test_sys_modules_loader_is_None(self):
+ # If sys.modules[name].__loader__ is None, raise ValueError.
+ name = 'some_mod'
+ with util.uncache(name):
+ module = imp.new_module(name)
+ module.__loader__ = None
+ sys.modules[name] = module
+ with self.assertRaises(ValueError):
+ importlib.find_loader(name)
+
+ def test_success(self):
+ # Return the loader found on sys.meta_path.
+ name = 'some_mod'
+ with util.uncache(name):
+ with util.import_state(meta_path=[self.FakeMetaFinder]):
+ self.assertEqual((name, None), importlib.find_loader(name))
+
+ def test_success_path(self):
+ # Searching on a path should work.
+ name = 'some_mod'
+ path = 'path to some place'
+ with util.uncache(name):
+ with util.import_state(meta_path=[self.FakeMetaFinder]):
+ self.assertEqual((name, path),
+ importlib.find_loader(name, path))
+
+ def test_nothing(self):
+ # None is returned upon failure to find a loader.
+ self.assertIsNone(importlib.find_loader('nevergoingtofindthismodule'))
+
+
class InvalidateCacheTests(unittest.TestCase):

def test_method_called(self):
@@ -114,7 +162,7 @@

def test_main():
from test.support import run_unittest
- run_unittest(ImportModuleTests)
+ run_unittest(ImportModuleTests, FindLoaderTests, InvalidateCacheTests)


if __name__ == '__main__':
diff --git a/Lib/pyclbr.py b/Lib/pyclbr.py
--- a/Lib/pyclbr.py
+++ b/Lib/pyclbr.py
@@ -39,8 +39,10 @@
lineno -- the line in the file on which the class statement occurred
"""

+import io
+import os
import sys
-import imp
+import importlib
import tokenize
from token import NAME, DEDENT, OP
from operator import itemgetter
@@ -133,19 +135,24 @@
# Search the path for the module
f = None
if inpackage is not None:
- f, fname, (_s, _m, ty) = imp.find_module(module, path)
+ search_path = path
else:
- f, fname, (_s, _m, ty) = imp.find_module(module, path + sys.path)
- if ty == imp.PKG_DIRECTORY:
- dict['__path__'] = [fname]
- path = [fname] + path
- f, fname, (_s, _m, ty) = imp.find_module('__init__', [fname])
+ search_path = path + sys.path
+ loader = importlib.find_loader(fullmodule, search_path)
+ fname = loader.get_filename(fullmodule)
_modules[fullmodule] = dict
- if ty != imp.PY_SOURCE:
+ if loader.is_package(fullmodule):
+ dict['__path__'] = [os.path.dirname(fname)]
+ try:
+ source = loader.get_source(fullmodule)
+ if source is None:
+ return dict
+ except (AttributeError, ImportError):
# not Python source, can't do anything with this module
- f.close()
return dict

+ f = io.StringIO(source)
+
stack = [] # stack of (class, indent) pairs

g = tokenize.generate_tokens(f.readline)
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -1422,14 +1422,6 @@
self.assertRaises(TypeError, str, b"hello", "test.unicode2")
self.assertRaises(TypeError, "hello".encode, "test.unicode1")
self.assertRaises(TypeError, "hello".encode, "test.unicode2")
- # executes PyUnicode_Encode()
- import imp
- self.assertRaises(
- ImportError,
- imp.find_module,
- "non-existing module",
- ["non-existing dir"]
- )

# Error handling (wrong arguments)
self.assertRaises(TypeError, "hello".encode, 42, 42, 42)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -23,6 +23,8 @@
Library
-------

+- Issue #13959: Introduce importlib.find_loader().
+
- Issue #14082: shutil.copy2() now copies extended attributes, if possible.
Patch by Hynek Schlawack.


--
Repository URL: http://hg.python.org/cpython


python-checkins at python

May 17, 2012, 12:07 PM

Post #57 of 57 (77 views)
Permalink
cpython (merge default -> default): Merge [In reply to]

http://hg.python.org/cpython/rev/8e3425396912
changeset: 77017:8e3425396912
parent: 77016:423a26e8ffbb
parent: 77015:c62fa6892424
user: Antoine Pitrou <solipsis [at] pitrou>
date: Thu May 17 21:04:49 2012 +0200
summary:
Merge

files:
Lib/tarfile.py | 4 ++--
Misc/ACKS | 1 +
Misc/NEWS | 3 +++
3 files changed, 6 insertions(+), 2 deletions(-)


diff --git a/Lib/tarfile.py b/Lib/tarfile.py
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -245,8 +245,8 @@
the high bit set. So we calculate two checksums, unsigned and
signed.
"""
- unsigned_chksum = 256 + sum(struct.unpack("148B", buf[:148]) + struct.unpack("356B", buf[156:512]))
- signed_chksum = 256 + sum(struct.unpack("148b", buf[:148]) + struct.unpack("356b", buf[156:512]))
+ unsigned_chksum = 256 + sum(struct.unpack_from("148B8x356B", buf))
+ signed_chksum = 256 + sum(struct.unpack_from("148b8x356b", buf))
return unsigned_chksum, signed_chksum

def copyfileobj(src, dst, length=None):
diff --git a/Misc/ACKS b/Misc/ACKS
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -776,6 +776,7 @@
Joe Peterson
Randy Pausch
Samuele Pedroni
+Justin Peel
Marcel van der Peijl
Berker Peksag
Steven Pemberton
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -38,6 +38,9 @@
Library
-------

+- Issue #13031: Small speed-up for tarfile when unzipping tarfiles.
+ Patch by Justin Peel.
+
- Issue #14780: urllib.request.urlopen() now has a ``cadefault`` argument
to use the default certificate store. Initial patch by James Oakley.


--
Repository URL: http://hg.python.org/cpython

First page Previous page 1 2 3 Next page Last page  View All Python checkins RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.