Rev 1748: Update readdir pyrex source files and usage in line with current practice. in http://people.ubuntu.com/~robertc/baz2.0/readdir
Robert Collins
robertc at robertcollins.net
Wed Aug 20 04:30:27 BST 2008
At http://people.ubuntu.com/~robertc/baz2.0/readdir
------------------------------------------------------------
revno: 1748
revision-id: robertc at robertcollins.net-20080820033017-q8y6stxz8f5kxu9y
parent: robertc at robertcollins.net-20080820020736-g2xe4921zzxtymle
committer: Robert Collins <robertc at robertcollins.net>
branch nick: readdir
timestamp: Wed 2008-08-20 13:30:17 +1000
message:
Update readdir pyrex source files and usage in line with current practice.
removed:
bzrlib/readdir.c readdir.c-20060609152855-rm6v321vuaqyh9tu-4
renamed:
bzrlib/readdir.py => bzrlib/_readdir_py.py readdir.py-20060609152855-rm6v321vuaqyh9tu-3
bzrlib/readdir.pyx => bzrlib/_readdir_pyx.pyx readdir.pyx-20060609152855-rm6v321vuaqyh9tu-1
modified:
bzrlib/osutils.py osutils.py-20050309040759-eeaff12fbf77ac86
bzrlib/tests/test_osutils.py test_osutils.py-20051201224856-e48ee24c12182989
setup.py setup.py-20050314065409-02f8a0a6e3f9bc70
bzrlib/_readdir_py.py readdir.py-20060609152855-rm6v321vuaqyh9tu-3
bzrlib/_readdir_pyx.pyx readdir.pyx-20060609152855-rm6v321vuaqyh9tu-1
=== renamed file 'bzrlib/readdir.py' => 'bzrlib/_readdir_py.py'
--- a/bzrlib/readdir.py 2008-08-20 02:07:36 +0000
+++ b/bzrlib/_readdir_py.py 2008-08-20 03:30:17 +0000
@@ -27,6 +27,6 @@
a file kind in the second element of the returned tuples.
:param path: the directory to list.
- :return: a list of (basename, None) tuples.
+ :return: a list of (None, basename) tuples.
"""
- return [(name, 'unknown') for name in os.listdir(path)]
+ return [(None, name) for name in os.listdir(path)]
=== renamed file 'bzrlib/readdir.pyx' => 'bzrlib/_readdir_pyx.pyx'
--- a/bzrlib/readdir.pyx 2008-08-20 02:07:36 +0000
+++ b/bzrlib/_readdir_pyx.pyx 2008-08-20 03:30:17 +0000
@@ -14,7 +14,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-"""Wrapper for readdir which grabs file type from d_type."""
+"""Wrapper for readdir which returns files ordered by inode."""
import os
@@ -46,6 +46,7 @@
# this will fail to compile if d_type is not defined.
# if this module fails to compile, use the .py version.
unsigned char d_type
+ int d_ino
ctypedef struct DIR
# should be DIR *, pyrex barfs.
DIR * opendir(char * name)
@@ -71,7 +72,7 @@
"""Like os.listdir, this reads a directories contents.
:param path: the directory to list.
- :return: a list of (basename, kind) tuples.
+ :return: a list of (sort_key, basename) tuples.
"""
cdef DIR *the_dir
# currently this needs a fixup - the C code says 'dirent' but should say
@@ -106,24 +107,7 @@
(name[1] == 0) or
(name[1] == dot and name [2] == 0))
):
- if entry.d_type == DT_UNKNOWN:
- type = _unknown
- elif entry.d_type == DT_REG:
- type = _file
- elif entry.d_type == DT_DIR:
- type = _directory
- elif entry.d_type == DT_FIFO:
- type = _fifo
- elif entry.d_type == DT_SOCK:
- type = _socket
- elif entry.d_type == DT_CHR:
- type = _chardev
- elif entry.d_type == DT_BLK:
- type = _block
- else:
- type = _unknown
- # result.append((entry.d_name, type))
- result.append((entry.d_name, 'unknown'))
+ result.append((entry.d_ino, entry.d_name))
finally:
if -1 == closedir(the_dir):
raise OSError(errno, strerror(errno))
=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py 2008-08-20 02:07:36 +0000
+++ b/bzrlib/osutils.py 2008-08-20 03:30:17 +0000
@@ -55,7 +55,6 @@
import bzrlib
-from bzrlib.readdir import read_dir
from bzrlib import symbol_versioning
from bzrlib.symbol_versioning import (
deprecated_function,
@@ -1278,16 +1277,13 @@
dirblock = []
append = dirblock.append
- for name, kind in sorted(_listdir(top)):
+ # read_dir supplies in should-stat order.
+ for _, name in sorted(_listdir(top)):
abspath = top_slash + name
- if kind == 'unknown':
- statvalue = _lstat(abspath)
- kind = _kind_from_mode(statvalue.st_mode & 0170000, 'unknown')
- else:
- statvalue = None
- statvalue = _lstat(abspath)
- kind = _kind_from_mode(statvalue.st_mode & 0170000, 'unknown')
+ statvalue = _lstat(abspath)
+ kind = _kind_from_mode(statvalue.st_mode & 0170000, 'unknown')
append((relprefix + name, name, kind, statvalue, abspath))
+ dirblock.sort()
yield (relroot, top), dirblock
# push the user specified dirs from dirblock
@@ -1532,3 +1528,9 @@
base = abspath(pathjoin(base, '..', '..'))
filename = pathjoin(base, resource_relpath)
return open(filename, 'rU').read()
+
+
+try:
+ from bzrlib._readdir_pyx import read_dir
+except ImportError:
+ from bzrlib._readdir_py import read_dir
=== removed file 'bzrlib/readdir.c'
--- a/bzrlib/readdir.c 2008-08-20 02:07:36 +0000
+++ b/bzrlib/readdir.c 1970-01-01 00:00:00 +0000
@@ -1,690 +0,0 @@
-/* Generated by Pyrex 0.9.6.4 on Wed Aug 20 12:04:52 2008 */
-
-#define PY_SSIZE_T_CLEAN
-#include "Python.h"
-#include "structmember.h"
-#ifndef PY_LONG_LONG
- #define PY_LONG_LONG LONG_LONG
-#endif
-#if PY_VERSION_HEX < 0x02050000
- typedef int Py_ssize_t;
- #define PY_SSIZE_T_MAX INT_MAX
- #define PY_SSIZE_T_MIN INT_MIN
- #define PyInt_FromSsize_t(z) PyInt_FromLong(z)
- #define PyInt_AsSsize_t(o) PyInt_AsLong(o)
-#endif
-#ifndef WIN32
- #ifndef __stdcall
- #define __stdcall
- #endif
- #ifndef __cdecl
- #define __cdecl
- #endif
-#endif
-#ifdef __cplusplus
-#define __PYX_EXTERN_C extern "C"
-#else
-#define __PYX_EXTERN_C extern
-#endif
-#include <math.h>
-#include "errno.h"
-#include "sys/types.h"
-#include "dirent.h"
-#include "readdir.h"
-
-
-typedef struct {PyObject **p; char *s;} __Pyx_InternTabEntry; /*proto*/
-typedef struct {PyObject **p; char *s; long n;} __Pyx_StringTabEntry; /*proto*/
-
-static PyObject *__pyx_m;
-static PyObject *__pyx_b;
-static int __pyx_lineno;
-static char *__pyx_filename;
-static char **__pyx_f;
-
-static char __pyx_mdoc[] = "Wrapper for readdir which grabs file type from d_type.";
-
-static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/
-
-static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/
-
-static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
-
-static int __Pyx_InternStrings(__Pyx_InternTabEntry *t); /*proto*/
-
-static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
-
-static void __Pyx_AddTraceback(char *funcname); /*proto*/
-
-/* Declarations from readdir */
-
-
-
-/* Implementation of readdir */
-
-static char __pyx_k11[] = ".";
-
-static PyObject *__pyx_n_os;
-static PyObject *__pyx_n_sys;
-static PyObject *__pyx_n__directory;
-static PyObject *__pyx_n_directory;
-static PyObject *__pyx_n__chardev;
-static PyObject *__pyx_n_chardev;
-static PyObject *__pyx_n__block;
-static PyObject *__pyx_n_block;
-static PyObject *__pyx_n__file;
-static PyObject *__pyx_n_file;
-static PyObject *__pyx_n__fifo;
-static PyObject *__pyx_n_fifo;
-static PyObject *__pyx_n__symlink;
-static PyObject *__pyx_n_symlink;
-static PyObject *__pyx_n__socket;
-static PyObject *__pyx_n_socket;
-static PyObject *__pyx_n__unknown;
-static PyObject *__pyx_n_unknown;
-static PyObject *__pyx_n_ord;
-static PyObject *__pyx_n_dot;
-
-static PyObject *__pyx_k11p;
-
-static PyObject *__pyx_n_OSError;
-static PyObject *__pyx_n_append;
-
-
-static PyObject *__pyx_f_7readdir_read_dir(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_7readdir_read_dir[] = "Like os.listdir, this reads a directories contents.\n\n :param path: the directory to list.\n :return: a list of (basename, kind) tuples.\n ";
-static PyObject *__pyx_f_7readdir_read_dir(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
- PyObject *__pyx_v_path = 0;
- DIR *__pyx_v_the_dir;
- dirent *__pyx_v_entry;
- dirent __pyx_v_sentinel;
- char *__pyx_v_name;
- PyObject *__pyx_v_result;
- PyObject *__pyx_v_type;
- PyObject *__pyx_r;
- char *__pyx_1;
- int __pyx_2;
- PyObject *__pyx_3 = 0;
- PyObject *__pyx_4 = 0;
- PyObject *__pyx_5 = 0;
- PyObject *__pyx_6 = 0;
- int __pyx_7;
- static char *__pyx_argnames[] = {"path",0};
- if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_path)) return 0;
- Py_INCREF(__pyx_v_path);
- __pyx_v_result = Py_None; Py_INCREF(Py_None);
- __pyx_v_type = Py_None; Py_INCREF(Py_None);
-
- /* "/home/robertc/source/baz/readdir/bzrlib/readdir.pyx":82 */
- __pyx_1 = PyString_AsString(__pyx_v_path); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; goto __pyx_L1;}
- __pyx_v_the_dir = opendir(__pyx_1);
-
- /* "/home/robertc/source/baz/readdir/bzrlib/readdir.pyx":83 */
- __pyx_2 = (NULL == __pyx_v_the_dir);
- if (__pyx_2) {
- __pyx_3 = __Pyx_GetName(__pyx_b, __pyx_n_OSError); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; goto __pyx_L1;}
- __pyx_4 = PyInt_FromLong(errno); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; goto __pyx_L1;}
- __pyx_5 = PyString_FromString(strerror(errno)); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; goto __pyx_L1;}
- __pyx_6 = PyTuple_New(2); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; goto __pyx_L1;}
- PyTuple_SET_ITEM(__pyx_6, 0, __pyx_4);
- PyTuple_SET_ITEM(__pyx_6, 1, __pyx_5);
- __pyx_4 = 0;
- __pyx_5 = 0;
- __pyx_4 = PyObject_CallObject(__pyx_3, __pyx_6); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; goto __pyx_L1;}
- Py_DECREF(__pyx_3); __pyx_3 = 0;
- Py_DECREF(__pyx_6); __pyx_6 = 0;
- __Pyx_Raise(__pyx_4, 0, 0);
- Py_DECREF(__pyx_4); __pyx_4 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; goto __pyx_L1;}
- goto __pyx_L2;
- }
- __pyx_L2:;
-
- /* "/home/robertc/source/baz/readdir/bzrlib/readdir.pyx":85 */
- __pyx_5 = PyList_New(0); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; goto __pyx_L1;}
- Py_DECREF(__pyx_v_result);
- __pyx_v_result = __pyx_5;
- __pyx_5 = 0;
-
- /* "/home/robertc/source/baz/readdir/bzrlib/readdir.pyx":86 */
- /*try:*/ {
-
- /* "/home/robertc/source/baz/readdir/bzrlib/readdir.pyx":87 */
- __pyx_v_entry = (&__pyx_v_sentinel);
-
- /* "/home/robertc/source/baz/readdir/bzrlib/readdir.pyx":88 */
- while (1) {
- __pyx_2 = (__pyx_v_entry != NULL);
- if (!__pyx_2) break;
-
- /* "/home/robertc/source/baz/readdir/bzrlib/readdir.pyx":89 */
- __pyx_v_entry = readdir(__pyx_v_the_dir);
-
- /* "/home/robertc/source/baz/readdir/bzrlib/readdir.pyx":90 */
- __pyx_2 = (__pyx_v_entry == NULL);
- if (__pyx_2) {
- __pyx_2 = (errno == EAGAIN);
- if (__pyx_2) {
- goto __pyx_L6;
- goto __pyx_L9;
- }
- __pyx_2 = (errno != ENOTDIR);
- if (__pyx_2) {
- __pyx_2 = (errno != ENOENT);
- if (__pyx_2) {
- __pyx_2 = (errno != 0);
- }
- }
- if (__pyx_2) {
- __pyx_3 = __Pyx_GetName(__pyx_b, __pyx_n_OSError); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; goto __pyx_L4;}
- __pyx_6 = PyInt_FromLong(errno); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; goto __pyx_L4;}
- __pyx_4 = PyString_FromString(strerror(errno)); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; goto __pyx_L4;}
- __pyx_5 = PyTuple_New(2); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; goto __pyx_L4;}
- PyTuple_SET_ITEM(__pyx_5, 0, __pyx_6);
- PyTuple_SET_ITEM(__pyx_5, 1, __pyx_4);
- __pyx_6 = 0;
- __pyx_4 = 0;
- __pyx_6 = PyObject_CallObject(__pyx_3, __pyx_5); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; goto __pyx_L4;}
- Py_DECREF(__pyx_3); __pyx_3 = 0;
- Py_DECREF(__pyx_5); __pyx_5 = 0;
- __Pyx_Raise(__pyx_6, 0, 0);
- Py_DECREF(__pyx_6); __pyx_6 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; goto __pyx_L4;}
- goto __pyx_L9;
- }
- /*else*/ {
- goto __pyx_L6;
- }
- __pyx_L9:;
- goto __pyx_L8;
- }
- __pyx_L8:;
-
- /* "/home/robertc/source/baz/readdir/bzrlib/readdir.pyx":104 */
- __pyx_v_name = __pyx_v_entry->d_name;
-
- /* "/home/robertc/source/baz/readdir/bzrlib/readdir.pyx":105 */
- __pyx_4 = PyInt_FromLong((__pyx_v_name[0])); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; goto __pyx_L4;}
- __pyx_3 = __Pyx_GetName(__pyx_m, __pyx_n_dot); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; goto __pyx_L4;}
- if (PyObject_Cmp(__pyx_4, __pyx_3, &__pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; goto __pyx_L4;}
- __pyx_2 = __pyx_2 == 0;
- Py_DECREF(__pyx_4); __pyx_4 = 0;
- Py_DECREF(__pyx_3); __pyx_3 = 0;
- if (__pyx_2) {
- __pyx_2 = ((__pyx_v_name[1]) == 0);
- if (!__pyx_2) {
- __pyx_5 = PyInt_FromLong((__pyx_v_name[1])); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; goto __pyx_L4;}
- __pyx_6 = __Pyx_GetName(__pyx_m, __pyx_n_dot); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; goto __pyx_L4;}
- if (PyObject_Cmp(__pyx_5, __pyx_6, &__pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; goto __pyx_L4;}
- __pyx_2 = __pyx_2 == 0;
- Py_DECREF(__pyx_5); __pyx_5 = 0;
- Py_DECREF(__pyx_6); __pyx_6 = 0;
- if (__pyx_2) {
- __pyx_2 = ((__pyx_v_name[2]) == 0);
- }
- }
- }
- __pyx_7 = (!__pyx_2);
- if (__pyx_7) {
-
- /* "/home/robertc/source/baz/readdir/bzrlib/readdir.pyx":109 */
- __pyx_2 = (__pyx_v_entry->d_type == DT_UNKNOWN);
- if (__pyx_2) {
- __pyx_4 = __Pyx_GetName(__pyx_m, __pyx_n__unknown); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; goto __pyx_L4;}
- Py_DECREF(__pyx_v_type);
- __pyx_v_type = __pyx_4;
- __pyx_4 = 0;
- goto __pyx_L11;
- }
- __pyx_7 = (__pyx_v_entry->d_type == DT_REG);
- if (__pyx_7) {
- __pyx_3 = __Pyx_GetName(__pyx_m, __pyx_n__file); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; goto __pyx_L4;}
- Py_DECREF(__pyx_v_type);
- __pyx_v_type = __pyx_3;
- __pyx_3 = 0;
- goto __pyx_L11;
- }
- __pyx_2 = (__pyx_v_entry->d_type == DT_DIR);
- if (__pyx_2) {
- __pyx_5 = __Pyx_GetName(__pyx_m, __pyx_n__directory); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; goto __pyx_L4;}
- Py_DECREF(__pyx_v_type);
- __pyx_v_type = __pyx_5;
- __pyx_5 = 0;
- goto __pyx_L11;
- }
- __pyx_7 = (__pyx_v_entry->d_type == DT_FIFO);
- if (__pyx_7) {
- __pyx_6 = __Pyx_GetName(__pyx_m, __pyx_n__fifo); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; goto __pyx_L4;}
- Py_DECREF(__pyx_v_type);
- __pyx_v_type = __pyx_6;
- __pyx_6 = 0;
- goto __pyx_L11;
- }
- __pyx_2 = (__pyx_v_entry->d_type == DT_SOCK);
- if (__pyx_2) {
- __pyx_4 = __Pyx_GetName(__pyx_m, __pyx_n__socket); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; goto __pyx_L4;}
- Py_DECREF(__pyx_v_type);
- __pyx_v_type = __pyx_4;
- __pyx_4 = 0;
- goto __pyx_L11;
- }
- __pyx_7 = (__pyx_v_entry->d_type == DT_CHR);
- if (__pyx_7) {
- __pyx_3 = __Pyx_GetName(__pyx_m, __pyx_n__chardev); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; goto __pyx_L4;}
- Py_DECREF(__pyx_v_type);
- __pyx_v_type = __pyx_3;
- __pyx_3 = 0;
- goto __pyx_L11;
- }
- __pyx_2 = (__pyx_v_entry->d_type == DT_BLK);
- if (__pyx_2) {
- __pyx_5 = __Pyx_GetName(__pyx_m, __pyx_n__block); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; goto __pyx_L4;}
- Py_DECREF(__pyx_v_type);
- __pyx_v_type = __pyx_5;
- __pyx_5 = 0;
- goto __pyx_L11;
- }
- /*else*/ {
- __pyx_6 = __Pyx_GetName(__pyx_m, __pyx_n__unknown); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; goto __pyx_L4;}
- Py_DECREF(__pyx_v_type);
- __pyx_v_type = __pyx_6;
- __pyx_6 = 0;
- }
- __pyx_L11:;
-
- /* "/home/robertc/source/baz/readdir/bzrlib/readdir.pyx":126 */
- __pyx_4 = PyObject_GetAttr(__pyx_v_result, __pyx_n_append); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; goto __pyx_L4;}
- __pyx_3 = PyString_FromString(__pyx_v_entry->d_name); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; goto __pyx_L4;}
- __pyx_5 = PyTuple_New(2); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; goto __pyx_L4;}
- PyTuple_SET_ITEM(__pyx_5, 0, __pyx_3);
- Py_INCREF(__pyx_n_unknown);
- PyTuple_SET_ITEM(__pyx_5, 1, __pyx_n_unknown);
- __pyx_3 = 0;
- __pyx_6 = PyTuple_New(1); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; goto __pyx_L4;}
- PyTuple_SET_ITEM(__pyx_6, 0, __pyx_5);
- __pyx_5 = 0;
- __pyx_3 = PyObject_CallObject(__pyx_4, __pyx_6); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; goto __pyx_L4;}
- Py_DECREF(__pyx_4); __pyx_4 = 0;
- Py_DECREF(__pyx_6); __pyx_6 = 0;
- Py_DECREF(__pyx_3); __pyx_3 = 0;
- goto __pyx_L10;
- }
- __pyx_L10:;
- __pyx_L6:;
- }
- }
- /*finally:*/ {
- int __pyx_why;
- PyObject *__pyx_exc_type, *__pyx_exc_value, *__pyx_exc_tb;
- int __pyx_exc_lineno;
- __pyx_why = 0; goto __pyx_L5;
- __pyx_L4: {
- __pyx_why = 4;
- Py_XDECREF(__pyx_5); __pyx_5 = 0;
- Py_XDECREF(__pyx_4); __pyx_4 = 0;
- Py_XDECREF(__pyx_6); __pyx_6 = 0;
- Py_XDECREF(__pyx_3); __pyx_3 = 0;
- PyErr_Fetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb);
- __pyx_exc_lineno = __pyx_lineno;
- goto __pyx_L5;
- }
- __pyx_L5:;
- __pyx_7 = ((-1) == closedir(__pyx_v_the_dir));
- if (__pyx_7) {
- __pyx_5 = __Pyx_GetName(__pyx_b, __pyx_n_OSError); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; goto __pyx_L12;}
- __pyx_4 = PyInt_FromLong(errno); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; goto __pyx_L12;}
- __pyx_6 = PyString_FromString(strerror(errno)); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; goto __pyx_L12;}
- __pyx_3 = PyTuple_New(2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; goto __pyx_L12;}
- PyTuple_SET_ITEM(__pyx_3, 0, __pyx_4);
- PyTuple_SET_ITEM(__pyx_3, 1, __pyx_6);
- __pyx_4 = 0;
- __pyx_6 = 0;
- __pyx_4 = PyObject_CallObject(__pyx_5, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; goto __pyx_L12;}
- Py_DECREF(__pyx_5); __pyx_5 = 0;
- Py_DECREF(__pyx_3); __pyx_3 = 0;
- __Pyx_Raise(__pyx_4, 0, 0);
- Py_DECREF(__pyx_4); __pyx_4 = 0;
- {__pyx_filename = __pyx_f[0]; __pyx_lineno = 129; goto __pyx_L12;}
- goto __pyx_L13;
- }
- __pyx_L13:;
- goto __pyx_L14;
- __pyx_L12:;
- if (__pyx_why == 4) {
- Py_XDECREF(__pyx_exc_type);
- Py_XDECREF(__pyx_exc_value);
- Py_XDECREF(__pyx_exc_tb);
- }
- goto __pyx_L1;
- __pyx_L14:;
- switch (__pyx_why) {
- case 4: {
- PyErr_Restore(__pyx_exc_type, __pyx_exc_value, __pyx_exc_tb);
- __pyx_lineno = __pyx_exc_lineno;
- __pyx_exc_type = 0;
- __pyx_exc_value = 0;
- __pyx_exc_tb = 0;
- goto __pyx_L1;
- }
- }
- }
-
- /* "/home/robertc/source/baz/readdir/bzrlib/readdir.pyx":130 */
- Py_INCREF(__pyx_v_result);
- __pyx_r = __pyx_v_result;
- goto __pyx_L0;
-
- __pyx_r = Py_None; Py_INCREF(Py_None);
- goto __pyx_L0;
- __pyx_L1:;
- Py_XDECREF(__pyx_3);
- Py_XDECREF(__pyx_4);
- Py_XDECREF(__pyx_5);
- Py_XDECREF(__pyx_6);
- __Pyx_AddTraceback("readdir.read_dir");
- __pyx_r = 0;
- __pyx_L0:;
- Py_DECREF(__pyx_v_result);
- Py_DECREF(__pyx_v_type);
- Py_DECREF(__pyx_v_path);
- return __pyx_r;
-}
-
-static __Pyx_InternTabEntry __pyx_intern_tab[] = {
- {&__pyx_n_OSError, "OSError"},
- {&__pyx_n__block, "_block"},
- {&__pyx_n__chardev, "_chardev"},
- {&__pyx_n__directory, "_directory"},
- {&__pyx_n__fifo, "_fifo"},
- {&__pyx_n__file, "_file"},
- {&__pyx_n__socket, "_socket"},
- {&__pyx_n__symlink, "_symlink"},
- {&__pyx_n__unknown, "_unknown"},
- {&__pyx_n_append, "append"},
- {&__pyx_n_block, "block"},
- {&__pyx_n_chardev, "chardev"},
- {&__pyx_n_directory, "directory"},
- {&__pyx_n_dot, "dot"},
- {&__pyx_n_fifo, "fifo"},
- {&__pyx_n_file, "file"},
- {&__pyx_n_ord, "ord"},
- {&__pyx_n_os, "os"},
- {&__pyx_n_socket, "socket"},
- {&__pyx_n_symlink, "symlink"},
- {&__pyx_n_sys, "sys"},
- {&__pyx_n_unknown, "unknown"},
- {0, 0}
-};
-
-static __Pyx_StringTabEntry __pyx_string_tab[] = {
- {&__pyx_k11p, __pyx_k11, sizeof(__pyx_k11)},
- {0, 0, 0}
-};
-
-static struct PyMethodDef __pyx_methods[] = {
- {"read_dir", (PyCFunction)__pyx_f_7readdir_read_dir, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7readdir_read_dir},
- {0, 0, 0, 0}
-};
-
-static void __pyx_init_filenames(void); /*proto*/
-
-PyMODINIT_FUNC initreaddir(void); /*proto*/
-PyMODINIT_FUNC initreaddir(void) {
- PyObject *__pyx_1 = 0;
- PyObject *__pyx_2 = 0;
- PyObject *__pyx_3 = 0;
- __pyx_init_filenames();
- __pyx_m = Py_InitModule4("readdir", __pyx_methods, __pyx_mdoc, 0, PYTHON_API_VERSION);
- if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;};
- Py_INCREF(__pyx_m);
- __pyx_b = PyImport_AddModule("__builtin__");
- if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;};
- if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;};
- if (__Pyx_InternStrings(__pyx_intern_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;};
- if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;};
-
- /* "/home/robertc/source/baz/readdir/bzrlib/readdir.pyx":20 */
- __pyx_1 = __Pyx_Import(__pyx_n_os, 0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; goto __pyx_L1;}
- if (PyObject_SetAttr(__pyx_m, __pyx_n_os, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; goto __pyx_L1;}
- Py_DECREF(__pyx_1); __pyx_1 = 0;
-
- /* "/home/robertc/source/baz/readdir/bzrlib/readdir.pyx":21 */
- __pyx_1 = __Pyx_Import(__pyx_n_sys, 0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 21; goto __pyx_L1;}
- if (PyObject_SetAttr(__pyx_m, __pyx_n_sys, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 21; goto __pyx_L1;}
- Py_DECREF(__pyx_1); __pyx_1 = 0;
-
- /* "/home/robertc/source/baz/readdir/bzrlib/readdir.pyx":55 */
- if (PyObject_SetAttr(__pyx_m, __pyx_n__directory, __pyx_n_directory) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; goto __pyx_L1;}
-
- /* "/home/robertc/source/baz/readdir/bzrlib/readdir.pyx":56 */
- if (PyObject_SetAttr(__pyx_m, __pyx_n__chardev, __pyx_n_chardev) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; goto __pyx_L1;}
-
- /* "/home/robertc/source/baz/readdir/bzrlib/readdir.pyx":57 */
- if (PyObject_SetAttr(__pyx_m, __pyx_n__block, __pyx_n_block) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; goto __pyx_L1;}
-
- /* "/home/robertc/source/baz/readdir/bzrlib/readdir.pyx":58 */
- if (PyObject_SetAttr(__pyx_m, __pyx_n__file, __pyx_n_file) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; goto __pyx_L1;}
-
- /* "/home/robertc/source/baz/readdir/bzrlib/readdir.pyx":59 */
- if (PyObject_SetAttr(__pyx_m, __pyx_n__fifo, __pyx_n_fifo) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;}
-
- /* "/home/robertc/source/baz/readdir/bzrlib/readdir.pyx":60 */
- if (PyObject_SetAttr(__pyx_m, __pyx_n__symlink, __pyx_n_symlink) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; goto __pyx_L1;}
-
- /* "/home/robertc/source/baz/readdir/bzrlib/readdir.pyx":61 */
- if (PyObject_SetAttr(__pyx_m, __pyx_n__socket, __pyx_n_socket) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; goto __pyx_L1;}
-
- /* "/home/robertc/source/baz/readdir/bzrlib/readdir.pyx":62 */
- if (PyObject_SetAttr(__pyx_m, __pyx_n__unknown, __pyx_n_unknown) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; goto __pyx_L1;}
-
- /* "/home/robertc/source/baz/readdir/bzrlib/readdir.pyx":64 */
- __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_ord); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;}
- __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;}
- Py_INCREF(__pyx_k11p);
- PyTuple_SET_ITEM(__pyx_2, 0, __pyx_k11p);
- __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;}
- Py_DECREF(__pyx_1); __pyx_1 = 0;
- Py_DECREF(__pyx_2); __pyx_2 = 0;
- if (PyObject_SetAttr(__pyx_m, __pyx_n_dot, __pyx_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;}
- Py_DECREF(__pyx_3); __pyx_3 = 0;
-
- /* "/home/robertc/source/baz/readdir/bzrlib/readdir.pyx":70 */
- return;
- __pyx_L1:;
- Py_XDECREF(__pyx_1);
- Py_XDECREF(__pyx_2);
- Py_XDECREF(__pyx_3);
- __Pyx_AddTraceback("readdir");
-}
-
-static char *__pyx_filenames[] = {
- "readdir.pyx",
-};
-
-/* Runtime support code */
-
-static void __pyx_init_filenames(void) {
- __pyx_f = __pyx_filenames;
-}
-
-static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list) {
- PyObject *__import__ = 0;
- PyObject *empty_list = 0;
- PyObject *module = 0;
- PyObject *global_dict = 0;
- PyObject *empty_dict = 0;
- PyObject *list;
- __import__ = PyObject_GetAttrString(__pyx_b, "__import__");
- if (!__import__)
- goto bad;
- if (from_list)
- list = from_list;
- else {
- empty_list = PyList_New(0);
- if (!empty_list)
- goto bad;
- list = empty_list;
- }
- global_dict = PyModule_GetDict(__pyx_m);
- if (!global_dict)
- goto bad;
- empty_dict = PyDict_New();
- if (!empty_dict)
- goto bad;
- module = PyObject_CallFunction(__import__, "OOOO",
- name, global_dict, empty_dict, list);
-bad:
- Py_XDECREF(empty_list);
- Py_XDECREF(__import__);
- Py_XDECREF(empty_dict);
- return module;
-}
-
-static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
- PyObject *result;
- result = PyObject_GetAttr(dict, name);
- if (!result)
- PyErr_SetObject(PyExc_NameError, name);
- return result;
-}
-
-static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
- Py_XINCREF(type);
- Py_XINCREF(value);
- Py_XINCREF(tb);
- /* First, check the traceback argument, replacing None with NULL. */
- if (tb == Py_None) {
- Py_DECREF(tb);
- tb = 0;
- }
- else if (tb != NULL && !PyTraceBack_Check(tb)) {
- PyErr_SetString(PyExc_TypeError,
- "raise: arg 3 must be a traceback or None");
- goto raise_error;
- }
- /* Next, replace a missing value with None */
- if (value == NULL) {
- value = Py_None;
- Py_INCREF(value);
- }
- #if PY_VERSION_HEX < 0x02050000
- if (!PyClass_Check(type))
- #else
- if (!PyType_Check(type))
- #endif
- {
- /* Raising an instance. The value should be a dummy. */
- if (value != Py_None) {
- PyErr_SetString(PyExc_TypeError,
- "instance exception may not have a separate value");
- goto raise_error;
- }
- /* Normalize to raise <class>, <instance> */
- Py_DECREF(value);
- value = type;
- #if PY_VERSION_HEX < 0x02050000
- if (PyInstance_Check(type)) {
- type = (PyObject*) ((PyInstanceObject*)type)->in_class;
- Py_INCREF(type);
- }
- else {
- PyErr_SetString(PyExc_TypeError,
- "raise: exception must be an old-style class or instance");
- goto raise_error;
- }
- #else
- type = (PyObject*) type->ob_type;
- Py_INCREF(type);
- if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
- PyErr_SetString(PyExc_TypeError,
- "raise: exception class must be a subclass of BaseException");
- goto raise_error;
- }
- #endif
- }
- PyErr_Restore(type, value, tb);
- return;
-raise_error:
- Py_XDECREF(value);
- Py_XDECREF(type);
- Py_XDECREF(tb);
- return;
-}
-
-static int __Pyx_InternStrings(__Pyx_InternTabEntry *t) {
- while (t->p) {
- *t->p = PyString_InternFromString(t->s);
- if (!*t->p)
- return -1;
- ++t;
- }
- return 0;
-}
-
-static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
- while (t->p) {
- *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
- if (!*t->p)
- return -1;
- ++t;
- }
- return 0;
-}
-
-#include "compile.h"
-#include "frameobject.h"
-#include "traceback.h"
-
-static void __Pyx_AddTraceback(char *funcname) {
- PyObject *py_srcfile = 0;
- PyObject *py_funcname = 0;
- PyObject *py_globals = 0;
- PyObject *empty_tuple = 0;
- PyObject *empty_string = 0;
- PyCodeObject *py_code = 0;
- PyFrameObject *py_frame = 0;
-
- py_srcfile = PyString_FromString(__pyx_filename);
- if (!py_srcfile) goto bad;
- py_funcname = PyString_FromString(funcname);
- if (!py_funcname) goto bad;
- py_globals = PyModule_GetDict(__pyx_m);
- if (!py_globals) goto bad;
- empty_tuple = PyTuple_New(0);
- if (!empty_tuple) goto bad;
- empty_string = PyString_FromString("");
- if (!empty_string) goto bad;
- py_code = PyCode_New(
- 0, /*int argcount,*/
- 0, /*int nlocals,*/
- 0, /*int stacksize,*/
- 0, /*int flags,*/
- empty_string, /*PyObject *code,*/
- empty_tuple, /*PyObject *consts,*/
- empty_tuple, /*PyObject *names,*/
- empty_tuple, /*PyObject *varnames,*/
- empty_tuple, /*PyObject *freevars,*/
- empty_tuple, /*PyObject *cellvars,*/
- py_srcfile, /*PyObject *filename,*/
- py_funcname, /*PyObject *name,*/
- __pyx_lineno, /*int firstlineno,*/
- empty_string /*PyObject *lnotab*/
- );
- if (!py_code) goto bad;
- py_frame = PyFrame_New(
- PyThreadState_Get(), /*PyThreadState *tstate,*/
- py_code, /*PyCodeObject *code,*/
- py_globals, /*PyObject *globals,*/
- 0 /*PyObject *locals*/
- );
- if (!py_frame) goto bad;
- py_frame->f_lineno = __pyx_lineno;
- PyTraceBack_Here(py_frame);
-bad:
- Py_XDECREF(py_srcfile);
- Py_XDECREF(py_funcname);
- Py_XDECREF(empty_tuple);
- Py_XDECREF(empty_string);
- Py_XDECREF(py_code);
- Py_XDECREF(py_frame);
-}
=== modified file 'bzrlib/tests/test_osutils.py'
--- a/bzrlib/tests/test_osutils.py 2008-08-20 02:07:36 +0000
+++ b/bzrlib/tests/test_osutils.py 2008-08-20 03:30:17 +0000
@@ -28,7 +28,6 @@
from bzrlib import (
errors,
osutils,
- readdir,
tests,
win32utils,
)
@@ -40,11 +39,14 @@
pumpfile,
)
from bzrlib.tests import (
+ adapt_tests,
probe_unicode_in_user_encoding,
+ split_suite_by_re,
StringIOWrapper,
SymlinkFeature,
TestCase,
TestCaseInTempDir,
+ TestScenarioApplier,
TestSkipped,
)
from bzrlib.tests.file_utils import (
@@ -53,6 +55,22 @@
from bzrlib.tests.test__walkdirs_win32 import WalkdirsWin32Feature
+def load_tests(standard_tests, module, loader):
+ """Parameterize readdir tests."""
+ to_adapt, result = split_suite_by_re(standard_tests, "readdir")
+ adapter = TestScenarioApplier()
+ from bzrlib import _readdir_py
+ adapter.scenarios = [('python', {'read_dir':_readdir_py.read_dir})]
+ try:
+ from bzrlib import _readdir_pyx
+ adapter.scenarios.append(
+ (('pyrex', {'read_dir':_readdir_pyx.read_dir})))
+ except ImportError:
+ pass
+ adapt_tests(to_adapt, adapter, result)
+ return result
+
+
class TestOSUtils(TestCaseInTempDir):
def test_contains_whitespace(self):
@@ -734,13 +752,18 @@
self.build_tree(tree)
expected_names = ['.bzr', '0file', '1dir', '2file']
# read_dir either returns None, or a value
- read_result = readdir.read_dir('.')
- if read_result[0][1] is None:
- expected_kind = ['unknown', 'unknown', 'unknown', 'unknown']
+ read_result = self.read_dir('.')
+ if read_result[0][0] is None:
+ # No innate sort:
+ expected_keys = [None, None, None, None]
+ expected = zip(expected_keys, expected_names)
+ expected.sort()
+ self.assertEqual(expected, sorted(read_result))
else:
- expected_kind = ['directory', 'file', 'directory', 'file']
- expected = zip(expected_names, expected_kind)
- self.assertEqual(expected, sorted(read_result))
+ # Check that the names we need are present in the second
+ # column
+ names = sorted([result[1] for result in read_result])
+ self.assertEqual(expected_names, names)
def test_walkdirs(self):
tree = [
=== modified file 'setup.py'
--- a/setup.py 2008-08-20 02:07:36 +0000
+++ b/setup.py 2008-08-20 03:30:17 +0000
@@ -227,7 +227,7 @@
add_pyrex_extension('bzrlib._dirstate_helpers_c')
add_pyrex_extension('bzrlib._knit_load_data_c')
-add_pyrex_extension('bzrlib.readdir')
+add_pyrex_extension('bzrlib._readdir_pyx')
if sys.platform == 'win32':
# pyrex uses the macro WIN32 to detect the platform, even though it should
# be using something like _WIN32 or MS_WINDOWS, oh well, we can give it the
More information about the bazaar-commits
mailing list