diff -r 2612a56e0082 Lib/zipfile.py --- a/Lib/zipfile.py Thu Sep 05 14:19:51 2013 +0200 +++ b/Lib/zipfile.py Wed Oct 16 23:40:49 2013 +0200 @@ -1353,7 +1353,7 @@ class PyZipFile(ZipFile): """Class to create ZIP archives with Python library files and packages.""" - def writepy(self, pathname, basename = ""): + def writepy(self, pathname, basename = "", filterfunc=None): """Add all files from "pathname" to the ZIP archive. If pathname is a package directory, search the directory and @@ -1364,7 +1364,13 @@ archive. Added modules are always module.pyo or module.pyc. This method will compile the module.py into module.pyc if necessary. + If filterfunc(pathname) is given, it is called with every argument. + When it is False, the file or directory is skipped. """ + if filterfunc and not filterfunc(pathname): + if self.debug: + print 'pathname "%s" skipped by filterfunc' % pathname + return dir, name = os.path.split(pathname) if os.path.isdir(pathname): initname = os.path.join(pathname, "__init__.py") @@ -1389,7 +1395,8 @@ if os.path.isdir(path): if os.path.isfile(os.path.join(path, "__init__.py")): # This is a package directory, add it - self.writepy(path, basename) # Recursive call + self.writepy(path, basename, + filterfunc=filterfunc) # Recursive call elif ext == ".py": fname, arcname = self._get_codename(path[0:-3], basename)