[Python-modules-commits] [python-regex] 01/05: Import python-regex_0.1.20161121.orig.tar.gz

Sandro Tosi morph at moszumanska.debian.org
Sat Dec 10 23:09:22 UTC 2016


This is an automated email from the git hooks/post-receive script.

morph pushed a commit to branch master
in repository python-regex.

commit bd2ae6be9564abe4da2034da2bfa5ff3a5ed31cc
Author: Sandro Tosi <morph at debian.org>
Date:   Sat Dec 10 14:10:26 2016 -0500

    Import python-regex_0.1.20161121.orig.tar.gz
---
 PKG-INFO              |  2 +-
 Python2/_regex.c      | 56 +++++++++++++++++++++++++++++++++----
 Python2/regex.py      |  2 +-
 Python2/test_regex.py | 17 ++++++++++++
 Python3/_regex.c      | 76 ++++++++++++++++++++++-----------------------------
 Python3/regex.py      |  2 +-
 Python3/test_regex.py | 17 ++++++++++++
 setup.py              |  7 +++--
 8 files changed, 125 insertions(+), 54 deletions(-)

diff --git a/PKG-INFO b/PKG-INFO
index 419362f..e61af1a 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: regex
-Version: 2016.09.22
+Version: 2016.11.21
 Summary: Alternative regular expression module, to replace re.
 Home-page: https://bitbucket.org/mrabarnett/mrab-regex
 Author: Matthew Barnett
diff --git a/Python2/_regex.c b/Python2/_regex.c
index 3b23892..17c08e2 100644
--- a/Python2/_regex.c
+++ b/Python2/_regex.c
@@ -10029,7 +10029,7 @@ Py_LOCAL_INLINE(BOOL) any_error_permitted(RE_State* state) {
 
     return fuzzy_info->total_cost <= values[RE_FUZZY_VAL_MAX_COST] &&
       fuzzy_info->counts[RE_FUZZY_ERR] < values[RE_FUZZY_VAL_MAX_ERR] &&
-      state->total_errors <= state->max_errors;
+      state->total_errors < state->max_errors;
 }
 
 /* Checks whether this additional fuzzy error is permitted. */
@@ -10042,7 +10042,7 @@ Py_LOCAL_INLINE(BOOL) this_error_permitted(RE_State* state, int fuzzy_type) {
 
     return fuzzy_info->total_cost + values[RE_FUZZY_VAL_COST_BASE + fuzzy_type]
       <= values[RE_FUZZY_VAL_MAX_COST] && fuzzy_info->counts[fuzzy_type] <
-      values[RE_FUZZY_VAL_MAX_BASE + fuzzy_type] && state->total_errors + 1 <=
+      values[RE_FUZZY_VAL_MAX_BASE + fuzzy_type] && state->total_errors <
       state->max_errors;
 }
 
@@ -10074,6 +10074,9 @@ Py_LOCAL_INLINE(int) next_fuzzy_match_item(RE_State* state, RE_FuzzyData* data,
         switch (data->fuzzy_type) {
         case RE_FUZZY_DEL:
             /* Could a character at text_pos have been deleted? */
+            if (step == 0)
+                return RE_ERROR_FAILURE;
+
             if (is_string)
                 data->new_string_pos += step;
             else
@@ -10084,7 +10087,10 @@ Py_LOCAL_INLINE(int) next_fuzzy_match_item(RE_State* state, RE_FuzzyData* data,
             if (!data->permit_insertion)
                 return RE_ERROR_FAILURE;
 
-            new_pos = data->new_text_pos + step;
+            if (step == 0)
+                new_pos = data->new_text_pos + data->step;
+            else
+                new_pos = data->new_text_pos + step;
             if (state->slice_start <= new_pos && new_pos <= state->slice_end) {
                 data->new_text_pos = new_pos;
                 return RE_ERROR_SUCCESS;
@@ -10093,6 +10099,9 @@ Py_LOCAL_INLINE(int) next_fuzzy_match_item(RE_State* state, RE_FuzzyData* data,
             return check_fuzzy_partial(state, new_pos);
         case RE_FUZZY_SUB:
             /* Could the character at text_pos have been substituted? */
+            if (step == 0)
+                return RE_ERROR_FAILURE;
+
             new_pos = data->new_text_pos + step;
             if (state->slice_start <= new_pos && new_pos <= state->slice_end) {
                 data->new_text_pos = new_pos;
@@ -16615,13 +16624,14 @@ Py_LOCAL_INLINE(int) do_best_fuzzy_match(RE_SafeState* safe_state, BOOL search)
                  */
                 add_to_best_list(safe_state, &best_list, state->match_pos,
                   state->text_pos);
-        }
+        } else
+            start_pos = state->match_pos + step;
 
         /* Should we keep searching? */
         if (!search)
             break;
 
-        start_pos = state->match_pos + step;
+        state->max_errors = fewest_errors - 1;
     }
 
     if (found_match) {
@@ -17116,7 +17126,7 @@ Py_LOCAL_INLINE(BOOL) get_string(PyObject* string, RE_StringInfo* str_info) {
      * instead.
      */
     if (PyUnicode_Check(string)) {
-        /* Unicode strings doesn't always support the buffer interface. */
+        /* Unicode strings don't always support the buffer interface. */
         str_info->characters = (void*)PyUnicode_AS_DATA(string);
         str_info->length = PyUnicode_GET_SIZE(string);
         str_info->charsize = sizeof(Py_UNICODE);
@@ -17125,6 +17135,39 @@ Py_LOCAL_INLINE(BOOL) get_string(PyObject* string, RE_StringInfo* str_info) {
         return TRUE;
     }
 
+#if defined(PYPY_VERSION)
+    if (PyString_Check(string)) {
+        /* Bytestrings don't always support the buffer interface. */
+        str_info->characters = (void*)PyString_AS_STRING(string);
+        str_info->length = PyString_GET_SIZE(string);
+        str_info->charsize = 1;
+        str_info->is_unicode = FALSE;
+        str_info->should_release = FALSE;
+        return TRUE;
+    }
+
+#endif
+#if defined(PYPY_VERSION)
+    /* Get pointer to string buffer. */
+    if (PyObject_GetBuffer(string, &str_info->view, PyBUF_SIMPLE) != 0) {
+        printf("PyObject_GetBuffer failed!\n");
+        PyErr_SetString(PyExc_TypeError, "expected string or buffer");
+        return FALSE;
+    }
+
+    if (!str_info->view.buf) {
+        PyBuffer_Release(&str_info->view);
+        PyErr_SetString(PyExc_ValueError, "buffer is NULL");
+        return FALSE;
+    }
+
+    str_info->should_release = TRUE;
+
+    str_info->characters = str_info->view.buf;
+    str_info->length = str_info->view.len;
+    str_info->charsize = 1;
+    str_info->is_unicode = FALSE;
+#else
     /* Get pointer to string buffer. */
 #if PY_VERSION_HEX >= 0x02060000
     buffer = Py_TYPE(string)->tp_as_buffer;
@@ -17196,6 +17239,7 @@ Py_LOCAL_INLINE(BOOL) get_string(PyObject* string, RE_StringInfo* str_info) {
 
     str_info->length = size;
     str_info->is_unicode = FALSE;
+#endif
 
     return TRUE;
 }
diff --git a/Python2/regex.py b/Python2/regex.py
index edaec00..a868ea2 100644
--- a/Python2/regex.py
+++ b/Python2/regex.py
@@ -239,7 +239,7 @@ __all__ = ["compile", "escape", "findall", "finditer", "fullmatch", "match",
   "U", "UNICODE", "V0", "VERSION0", "V1", "VERSION1", "X", "VERBOSE", "W",
   "WORD", "error", "Regex"]
 
-__version__ = "2.4.108"
+__version__ = "2.4.112"
 
 # --------------------------------------------------------------------
 # Public interface.
diff --git a/Python2/test_regex.py b/Python2/test_regex.py
index 01be01e..5d7321f 100644
--- a/Python2/test_regex.py
+++ b/Python2/test_regex.py
@@ -3696,6 +3696,23 @@ thing
         self.assertEqual(regex.match(r'\w*(ea)\w*|\w*e(?!a)\w*',
           'easier').groups(), ('ea', ))
 
+        # Hg issue 225: BESTMATCH in fuzzy match not working
+        self.assertEqual(regex.search('(^1234$){i,d}', '12234',
+          regex.BESTMATCH).span(), (0, 5))
+        self.assertEqual(regex.search('(^1234$){i,d}', '12234',
+          regex.BESTMATCH).fuzzy_counts, (0, 1, 0))
+
+        self.assertEqual(regex.search('(^1234$){s,i,d}', '12234',
+          regex.BESTMATCH).span(), (0, 5))
+        self.assertEqual(regex.search('(^1234$){s,i,d}', '12234',
+          regex.BESTMATCH).fuzzy_counts, (0, 1, 0))
+
+        # Hg issue 226: Error matching at start of string
+        self.assertEqual(regex.search('(^123$){s,i,d}', 'xxxxxxxx123',
+          regex.BESTMATCH).span(), (0, 11))
+        self.assertEqual(regex.search('(^123$){s,i,d}', 'xxxxxxxx123',
+          regex.BESTMATCH).fuzzy_counts, (0, 8, 0))
+
     def test_subscripted_captures(self):
         self.assertEqual(regex.match(r'(?P<x>.)+',
           'abc').expandf('{0} {0[0]} {0[-1]}'), 'abc abc abc')
diff --git a/Python3/_regex.c b/Python3/_regex.c
index 70a2ad8..5080e6e 100644
--- a/Python3/_regex.c
+++ b/Python3/_regex.c
@@ -10058,7 +10058,7 @@ Py_LOCAL_INLINE(BOOL) any_error_permitted(RE_State* state) {
 
     return fuzzy_info->total_cost <= values[RE_FUZZY_VAL_MAX_COST] &&
       fuzzy_info->counts[RE_FUZZY_ERR] < values[RE_FUZZY_VAL_MAX_ERR] &&
-      state->total_errors <= state->max_errors;
+      state->total_errors < state->max_errors;
 }
 
 /* Checks whether this additional fuzzy error is permitted. */
@@ -10071,7 +10071,7 @@ Py_LOCAL_INLINE(BOOL) this_error_permitted(RE_State* state, int fuzzy_type) {
 
     return fuzzy_info->total_cost + values[RE_FUZZY_VAL_COST_BASE + fuzzy_type]
       <= values[RE_FUZZY_VAL_MAX_COST] && fuzzy_info->counts[fuzzy_type] <
-      values[RE_FUZZY_VAL_MAX_BASE + fuzzy_type] && state->total_errors + 1 <=
+      values[RE_FUZZY_VAL_MAX_BASE + fuzzy_type] && state->total_errors <
       state->max_errors;
 }
 
@@ -10103,6 +10103,9 @@ Py_LOCAL_INLINE(int) next_fuzzy_match_item(RE_State* state, RE_FuzzyData* data,
         switch (data->fuzzy_type) {
         case RE_FUZZY_DEL:
             /* Could a character at text_pos have been deleted? */
+            if (step == 0)
+                return RE_ERROR_FAILURE;
+
             if (is_string)
                 data->new_string_pos += step;
             else
@@ -10113,7 +10116,10 @@ Py_LOCAL_INLINE(int) next_fuzzy_match_item(RE_State* state, RE_FuzzyData* data,
             if (!data->permit_insertion)
                 return RE_ERROR_FAILURE;
 
-            new_pos = data->new_text_pos + step;
+            if (step == 0)
+                new_pos = data->new_text_pos + data->step;
+            else
+                new_pos = data->new_text_pos + step;
             if (state->slice_start <= new_pos && new_pos <= state->slice_end) {
                 data->new_text_pos = new_pos;
                 return RE_ERROR_SUCCESS;
@@ -10122,6 +10128,9 @@ Py_LOCAL_INLINE(int) next_fuzzy_match_item(RE_State* state, RE_FuzzyData* data,
             return check_fuzzy_partial(state, new_pos);
         case RE_FUZZY_SUB:
             /* Could the character at text_pos have been substituted? */
+            if (step == 0)
+                return RE_ERROR_FAILURE;
+
             new_pos = data->new_text_pos + step;
             if (state->slice_start <= new_pos && new_pos <= state->slice_end) {
                 data->new_text_pos = new_pos;
@@ -16644,13 +16653,14 @@ Py_LOCAL_INLINE(int) do_best_fuzzy_match(RE_SafeState* safe_state, BOOL search)
                  */
                 add_to_best_list(safe_state, &best_list, state->match_pos,
                   state->text_pos);
-        }
+        } else
+            start_pos = state->match_pos + step;
 
         /* Should we keep searching? */
         if (!search)
             break;
 
-        start_pos = state->match_pos + step;
+        state->max_errors = fewest_errors - 1;
     }
 
     if (found_match) {
@@ -17137,15 +17147,11 @@ Py_LOCAL_INLINE(BOOL) get_string(PyObject* string, RE_StringInfo* str_info) {
      * and a character size. Return FALSE if the object is not a string (or not
      * compatible).
      */
-    PyBufferProcs* buffer;
-    Py_ssize_t bytes;
-    Py_ssize_t size;
-
     /* Unicode objects do not support the buffer API. So, get the data directly
      * instead.
      */
     if (PyUnicode_Check(string)) {
-        /* Unicode strings doesn't always support the buffer interface. */
+        /* Unicode strings don't always support the buffer interface. */
 #if PY_VERSION_HEX >= 0x03030000
         if (PyUnicode_READY(string) == -1)
             return FALSE;
@@ -17163,51 +17169,35 @@ Py_LOCAL_INLINE(BOOL) get_string(PyObject* string, RE_StringInfo* str_info) {
         return TRUE;
     }
 
-    /* Get pointer to string buffer. */
-    buffer = Py_TYPE(string)->tp_as_buffer;
-    str_info->view.len = -1;
-
-    if (!buffer) {
-        PyErr_SetString(PyExc_TypeError, "expected string or buffer");
-        return FALSE;
+#if defined(PYPY_VERSION)
+    if (PyBytes_Check(string)) {
+        /* Bytestrings don't always support the buffer interface. */
+        str_info->characters = (void*)PyBytes_AS_STRING(string);
+        str_info->length = PyBytes_GET_SIZE(string);
+        str_info->charsize = 1;
+        str_info->is_unicode = FALSE;
+        str_info->should_release = FALSE;
+        return TRUE;
     }
 
-    if (!buffer->bf_getbuffer || (*buffer->bf_getbuffer)(string,
-      &str_info->view, PyBUF_SIMPLE) < 0) {
+#endif
+    /* Get pointer to string buffer. */
+    if (PyObject_GetBuffer(string, &str_info->view, PyBUF_SIMPLE) != 0) {
         PyErr_SetString(PyExc_TypeError, "expected string or buffer");
         return FALSE;
     }
 
-    str_info->should_release = TRUE;
-
-    /* Determine buffer size. */
-    bytes = str_info->view.len;
-    str_info->characters = str_info->view.buf;
-
-    if (str_info->characters == NULL) {
+    if (!str_info->view.buf) {
         PyBuffer_Release(&str_info->view);
         PyErr_SetString(PyExc_ValueError, "buffer is NULL");
         return FALSE;
     }
 
-    if (bytes < 0) {
-        PyBuffer_Release(&str_info->view);
-        PyErr_SetString(PyExc_TypeError, "buffer has negative size");
-        return FALSE;
-    }
-
-    /* Determine character size. */
-    size = PyObject_Size(string);
-
-    if (PyBytes_Check(string) || bytes == size)
-        str_info->charsize = 1;
-    else {
-        PyBuffer_Release(&str_info->view);
-        PyErr_SetString(PyExc_TypeError, "buffer size mismatch");
-        return FALSE;
-    }
+    str_info->should_release = TRUE;
 
-    str_info->length = size;
+    str_info->characters = str_info->view.buf;
+    str_info->length = str_info->view.len;
+    str_info->charsize = 1;
     str_info->is_unicode = FALSE;
 
     return TRUE;
diff --git a/Python3/regex.py b/Python3/regex.py
index 7524fa0..d809c9a 100644
--- a/Python3/regex.py
+++ b/Python3/regex.py
@@ -239,7 +239,7 @@ __all__ = ["compile", "escape", "findall", "finditer", "fullmatch", "match",
   "U", "UNICODE", "V0", "VERSION0", "V1", "VERSION1", "X", "VERBOSE", "W",
   "WORD", "error", "Regex"]
 
-__version__ = "2.4.108"
+__version__ = "2.4.112"
 
 # --------------------------------------------------------------------
 # Public interface.
diff --git a/Python3/test_regex.py b/Python3/test_regex.py
index 6c45734..36a4f93 100644
--- a/Python3/test_regex.py
+++ b/Python3/test_regex.py
@@ -3800,6 +3800,23 @@ thing
         self.assertEqual(regex.match(r'\w*(ea)\w*|\w*e(?!a)\w*',
           'easier').groups(), ('ea', ))
 
+        # Hg issue 225: BESTMATCH in fuzzy match not working
+        self.assertEqual(regex.search('(^1234$){i,d}', '12234',
+          regex.BESTMATCH).span(), (0, 5))
+        self.assertEqual(regex.search('(^1234$){i,d}', '12234',
+          regex.BESTMATCH).fuzzy_counts, (0, 1, 0))
+
+        self.assertEqual(regex.search('(^1234$){s,i,d}', '12234',
+          regex.BESTMATCH).span(), (0, 5))
+        self.assertEqual(regex.search('(^1234$){s,i,d}', '12234',
+          regex.BESTMATCH).fuzzy_counts, (0, 1, 0))
+
+        # Hg issue 226: Error matching at start of string
+        self.assertEqual(regex.search('(^123$){s,i,d}', 'xxxxxxxx123',
+          regex.BESTMATCH).span(), (0, 11))
+        self.assertEqual(regex.search('(^123$){s,i,d}', 'xxxxxxxx123',
+          regex.BESTMATCH).fuzzy_counts, (0, 8, 0))
+
     def test_subscripted_captures(self):
         self.assertEqual(regex.match(r'(?P<x>.)+',
           'abc').expandf('{0} {0[0]} {0[-1]}'), 'abc abc abc')
diff --git a/setup.py b/setup.py
index 1375fad..7ab366a 100644
--- a/setup.py
+++ b/setup.py
@@ -3,7 +3,10 @@
 import os
 import sys
 
-from distutils.core import setup, Extension
+try:
+    from setuptools import setup, Extension
+except ImportError:
+    from distutils.core import setup, Extension
 
 MAJOR, MINOR = sys.version_info[:2]
 BASE_DIR = os.path.dirname(os.path.abspath(__file__))
@@ -13,7 +16,7 @@ DOCS_DIR = os.path.join(BASE_DIR, 'docs')
 
 setup(
     name='regex',
-    version='2016.09.22',
+    version='2016.11.21',
     description='Alternative regular expression module, to replace re.',
     long_description=open(os.path.join(DOCS_DIR, 'Features.rst')).read(),
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-regex.git



More information about the Python-modules-commits mailing list