Andriy Kornatskyy avatar Andriy Kornatskyy committed e70536c

Introduced patch for strptime regex cache max size.

Comments (0)

Files changed (7)

 
 .. automodule:: wheezy.validation.mixin
    :members:
-   
+
 wheezy.validation.model
 -----------------------
 
 .. automodule:: wheezy.validation.model
    :members:
-   
+
+wheezy.validation.patches
+-----------------------
+
+.. automodule:: wheezy.validation.patches
+   :members:
+
 wheezy.validation.rules
 -----------------------
 
 .. automodule:: wheezy.validation.rules
    :members:
-      
+
 wheezy.validation.validator
 ---------------------------
 

i18n/en/LC_MESSAGES/validation.po

 "Content-Transfer-Encoding: 8bit\n"
 
 #. thousands separator
-#: src/wheezy/validation/format.py:7
+#: src/wheezy/validation/format.py:7 src/wheezy/validation/i18n.py:6
 msgid ","
 msgstr ","
 
 #. decimal point separator
-#: src/wheezy/validation/format.py:9
+#: src/wheezy/validation/format.py:9 src/wheezy/validation/i18n.py:8
 msgid "."
 msgstr "."
 
 #. default date input format: 2008/5/18.
-#: src/wheezy/validation/format.py:11
+#: src/wheezy/validation/format.py:11 src/wheezy/validation/i18n.py:10
 msgid "%Y/%m/%d"
 msgstr "%Y/%m/%d"
 
 #. fallback date input formats: 5/18/2008. Use | to separate multiple values.
 #: src/wheezy/validation/format.py:14 src/wheezy/validation/format.py:15
+#: src/wheezy/validation/i18n.py:13
 msgid "%m/%d/%Y|%Y-%m-%d|%m/%d/%y"
 msgstr "%m/%d/%Y|%Y-%m-%d|%m/%d/%y"
 
 #. default time input format: 16:34.
 #: src/wheezy/validation/format.py:16 src/wheezy/validation/format.py:17
+#: src/wheezy/validation/i18n.py:15
 msgid "%H:%M"
 msgstr "%H:%M"
 
 #. fallback time input formats: 16:34:52. Use | to separate multiple values.
 #: src/wheezy/validation/format.py:18 src/wheezy/validation/format.py:21
+#: src/wheezy/validation/i18n.py:17
 msgid "%H:%M:%S"
 msgstr "%H:%M:%S"
 
 #. default datetime input format: 2008/5/18 16:34
 #: src/wheezy/validation/format.py:20 src/wheezy/validation/format.py:23
+#: src/wheezy/validation/i18n.py:19
 msgid "%Y/%m/%d %H:%M"
 msgstr "%Y/%m/%d %H:%M"
 
 #. fallback datetime input formats: 2008/5/18 16:34:52. Use | to separate.
 #: src/wheezy/validation/format.py:23 src/wheezy/validation/format.py:27
+#: src/wheezy/validation/i18n.py:22
 msgid ""
 "%Y/%m/%d %H:%M:%S|%m/%d/%Y %H:%M|%m/%d/%Y %H:%M:%S|%Y-%m-%d %H:%M|%Y-%m-%d "
 "%H:%M:%S|%m/%d/%y %H:%M|%m/%d/%y %H:%M:%S"

i18n/validation.po

 "Content-Transfer-Encoding: 8bit\n"
 
 #. thousands separator
-#: src/wheezy/validation/format.py:7
+#: src/wheezy/validation/format.py:7 src/wheezy/validation/i18n.py:6
 msgid ","
 msgstr ","
 
 #. decimal point separator
-#: src/wheezy/validation/format.py:9
+#: src/wheezy/validation/format.py:9 src/wheezy/validation/i18n.py:8
 msgid "."
 msgstr "."
 
 #. default date input format: 2008/5/18.
-#: src/wheezy/validation/format.py:11
+#: src/wheezy/validation/format.py:11 src/wheezy/validation/i18n.py:10
 msgid "%Y/%m/%d"
 msgstr "%Y/%m/%d"
 
 #. fallback date input formats: 5/18/2008. Use | to separate multiple values.
 #: src/wheezy/validation/format.py:14 src/wheezy/validation/format.py:15
+#: src/wheezy/validation/i18n.py:13
 msgid "%m/%d/%Y|%Y-%m-%d|%m/%d/%y"
 msgstr "%m/%d/%Y|%Y-%m-%d|%m/%d/%y"
 
 #. default time input format: 16:34.
 #: src/wheezy/validation/format.py:16 src/wheezy/validation/format.py:17
+#: src/wheezy/validation/i18n.py:15
 msgid "%H:%M"
 msgstr "%H:%M"
 
 #. fallback time input formats: 16:34:52. Use | to separate multiple values.
 #: src/wheezy/validation/format.py:18 src/wheezy/validation/format.py:21
+#: src/wheezy/validation/i18n.py:17
 msgid "%H:%M:%S"
 msgstr "%H:%M:%S"
 
 #. default datetime input format: 2008/5/18 16:34
 #: src/wheezy/validation/format.py:20 src/wheezy/validation/format.py:23
+#: src/wheezy/validation/i18n.py:19
 msgid "%Y/%m/%d %H:%M"
 msgstr "%Y/%m/%d %H:%M"
 
 #. fallback datetime input formats: 2008/5/18 16:34:52. Use | to separate.
 #: src/wheezy/validation/format.py:23 src/wheezy/validation/format.py:27
+#: src/wheezy/validation/i18n.py:22
 msgid ""
 "%Y/%m/%d %H:%M:%S|%m/%d/%Y %H:%M|%m/%d/%Y %H:%M:%S|%Y-%m-%d %H:%M|%Y-%m-%d "
 "%H:%M:%S|%m/%d/%y %H:%M|%m/%d/%y %H:%M:%S"

src/wheezy/validation/format.py

-
-""" ``format`` module.
-"""
-
-
-# thousands separator
-thousands_separator = lambda gettext: gettext(',')
-# decimal point separator
-decimal_separator = lambda gettext: gettext('.')
-# default date input format: 2008/5/18.
-default_date_input_format = lambda gettext: gettext('%Y/%m/%d')
-# fallback date input formats: 5/18/2008. Use | to separate multiple values.
-fallback_date_input_formats = lambda gettext: gettext(
-    '%m/%d/%Y|%Y-%m-%d|%m/%d/%y')
-# default time input format: 16:34.
-default_time_input_format = lambda gettext: gettext('%H:%M')
-# fallback time input formats: 16:34:52. Use | to separate multiple values.
-fallback_time_input_formats = lambda gettext: gettext('%H:%M:%S')
-# default datetime input format: 2008/5/18 16:34
-default_datetime_input_format = lambda gettext: gettext('%Y/%m/%d %H:%M')
-# fallback datetime input formats: 2008/5/18 16:34:52. Use | to separate.
-fallback_datetime_input_formats = lambda gettext: gettext(
-    '%Y/%m/%d %H:%M:%S|%m/%d/%Y %H:%M|%m/%d/%Y %H:%M:%S|'
-    '%Y-%m-%d %H:%M|%Y-%m-%d %H:%M:%S|%m/%d/%y %H:%M|%m/%d/%y %H:%M:%S')

src/wheezy/validation/i18n.py

+
+""" ``i18n`` module.
+"""
+
+# thousands separator
+thousands_separator = lambda gettext: gettext(',')
+# decimal point separator
+decimal_separator = lambda gettext: gettext('.')
+# default date input format: 2008/5/18.
+default_date_input_format = lambda gettext: gettext('%Y/%m/%d')
+# fallback date input formats: 5/18/2008. Use | to separate multiple values.
+fallback_date_input_formats = lambda gettext: gettext(
+    '%m/%d/%Y|%Y-%m-%d|%m/%d/%y')
+# default time input format: 16:34.
+default_time_input_format = lambda gettext: gettext('%H:%M')
+# fallback time input formats: 16:34:52. Use | to separate multiple values.
+fallback_time_input_formats = lambda gettext: gettext('%H:%M:%S')
+# default datetime input format: 2008/5/18 16:34
+default_datetime_input_format = lambda gettext: gettext('%Y/%m/%d %H:%M')
+# fallback datetime input formats: 2008/5/18 16:34:52. Use | to separate.
+fallback_datetime_input_formats = lambda gettext: gettext(
+    '%Y/%m/%d %H:%M:%S|%m/%d/%Y %H:%M|%m/%d/%Y %H:%M:%S|'
+    '%Y-%m-%d %H:%M|%Y-%m-%d %H:%M:%S|%m/%d/%y %H:%M|%m/%d/%y %H:%M:%S')

src/wheezy/validation/model.py

 
 from wheezy.validation.comp import null_translations
 from wheezy.validation.comp import ref_gettext
-from wheezy.validation.format import decimal_separator
-from wheezy.validation.format import default_date_input_format
-from wheezy.validation.format import default_datetime_input_format
-from wheezy.validation.format import default_time_input_format
-from wheezy.validation.format import fallback_date_input_formats
-from wheezy.validation.format import fallback_datetime_input_formats
-from wheezy.validation.format import fallback_time_input_formats
-from wheezy.validation.format import thousands_separator
+from wheezy.validation.i18n import decimal_separator
+from wheezy.validation.i18n import default_date_input_format
+from wheezy.validation.i18n import default_datetime_input_format
+from wheezy.validation.i18n import default_time_input_format
+from wheezy.validation.i18n import fallback_date_input_formats
+from wheezy.validation.i18n import fallback_datetime_input_formats
+from wheezy.validation.i18n import fallback_time_input_formats
+from wheezy.validation.i18n import thousands_separator
 
 
 def try_update_model(model, values, results, translations=None):
     'time': time_value_provider,
     'datetime': datetime_value_provider
 }
+
+
+from wheezy.validation.patches import patch_strptime_cache_size
+if not patch_strptime_cache_size():
+    from warnings import warn
+    warn('Failed to patch _strptime._CACHE_MAX_SIZE')
+    del warn
+del patch_strptime_cache_size

src/wheezy/validation/patches.py

+
+""" ``patches`` module.
+"""
+
+
+def patch_strptime_cache_size(max_size=100):
+    """ Patch for strptime regex cache max size.
+    """
+    try:
+        import _strptime
+        if not hasattr(_strptime, '_CACHE_MAX_SIZE'):
+            return False
+        if not hasattr(_strptime, '_cache_lock'):
+            return False
+    except (ImportError, AttributeError):
+        return False
+
+    l = _strptime._cache_lock
+    l.acquire()
+    try:
+        _strptime._CACHE_MAX_SIZE = max_size
+    finally:
+        l.release()
+    return True
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.