#28628: Audit for and abolish all use of '\d' in regexes
--------------------------------------+------------------------------------
     Reporter:  James Bennett         |                    Owner:  JunyiJ
         Type:  Cleanup/optimization  |                   Status:  assigned
    Component:  Documentation         |                  Version:  master
     Severity:  Normal                |               Resolution:
     Keywords:                        |             Triage Stage:  Accepted
    Has patch:  0                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  0
Easy pickings:  0                     |                    UI/UX:  0
--------------------------------------+------------------------------------

Comment (by JunyiJ):

 **I searched and replace '/d' using bash and the following places are
 changed:


 {{{
 django/django/http/request.py:21:host_validation_re =
 re.compile(r"^([a-z0-9.-]+|\[[a-f0-9]*:[a-f0-9\.:]+\])(:\d+)?$")
 django/django/contrib/gis/geometry.py:7:wkt_regex =
 re.compile(r'^(SRID=(?P<srid>\-?\d+);)?'
 django/django/contrib/gis/gdal/libgdal.py:87:version_regex =
 re.compile(r'^(?P<major>\d+)\.(?P<minor>\d+)(\.(?P<subminor>\d+))?')
 django/django/contrib/gis/geos/geometry.py:116:            match =
 re.match(b'SRID=(?P<srid>\-?\d+)', srid_part)
 django/django/contrib/gis/db/backends/postgis/operations.py:344:
 proj_regex = re.compile(r'(\d+)\.(\d+)\.(\d+)')
 django/django/contrib/humanize/templatetags/humanize.py:48:    new =
 re.sub(r"^(-?\d+)(\d{3})", r'\g<1>,\g<2>', orig)
 django/django/core/management/commands/makemessages.py:402:        m =
 re.search(r'(\d+)\.(\d+)\.?(\d+)?', out)
 django/django/core/validators.py:78:    ipv4_re =
 r'(?:25[0-5]|2[0-4]\d|[0-1]?\d?\d)(?:\.(?:25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}'
 django/django/core/validators.py:99:        r'(?::\d{2,5})?'  # port
 django/django/core/validators.py:136:            host_match =
 re.search(r'^\[(.+)\](?::\d{2,5})?$', urlsplit(value).netloc)
 django/django/core/validators.py:153:    _lazy_re_compile(r'^-?\d+\Z'),
 django/django/core/validators.py:296:    regexp =
 _lazy_re_compile(r'^%(neg)s\d+(?:%(sep)s%(neg)s\d+)*\Z' % {
 django/django/template/defaultfilters.py:238:    return
 re.sub(r"\d([A-Z])", lambda m: m.group(0).lower(), t)
 django/django/views/i18n.py:249:        match =
 re.search(r'nplurals=\s*(\d+)', self._plural_string or '')
 django/django/utils/dateparse.py:14:
 r'(?P<year>\d{4})-(?P<month>\d{1,2})-(?P<day>\d{1,2})$'
 django/django/utils/dateparse.py:18:
 r'(?P<hour>\d{1,2}):(?P<minute>\d{1,2})'
 django/django/utils/dateparse.py:19:
 r'(?::(?P<second>\d{1,2})(?:\.(?P<microsecond>\d{1,6})\d{0,6})?)?'
 django/django/utils/dateparse.py:23:
 r'(?P<year>\d{4})-(?P<month>\d{1,2})-(?P<day>\d{1,2})'
 django/django/utils/dateparse.py:24:    r'[T
 ](?P<hour>\d{1,2}):(?P<minute>\d{1,2})'
 django/django/utils/dateparse.py:25:
 r'(?::(?P<second>\d{1,2})(?:\.(?P<microsecond>\d{1,6})\d{0,6})?)?'
 django/django/utils/dateparse.py:26:
 r'(?P<tzinfo>Z|[+-]\d{2}(?::?\d{2})?)?$'
 django/django/utils/dateparse.py:31:    r'(?:(?P<days>-?\d+) (days?, )?)?'
 django/django/utils/dateparse.py:32:
 r'((?:(?P<hours>-?\d+):)(?=\d+:\d+))?'
 django/django/utils/dateparse.py:33:    r'(?:(?P<minutes>-?\d+):)?'
 django/django/utils/dateparse.py:34:    r'(?P<seconds>-?\d+)'
 django/django/utils/dateparse.py:35:
 r'(?:\.(?P<microseconds>\d{1,6})\d{0,6})?'
 django/django/utils/dateparse.py:44:    r'(?:(?P<days>\d+(.\d+)?)D)?'
 django/django/utils/dateparse.py:46:    r'(?:(?P<hours>\d+(.\d+)?)H)?'
 django/django/utils/dateparse.py:47:    r'(?:(?P<minutes>\d+(.\d+)?)M)?'
 django/django/utils/dateparse.py:48:    r'(?:(?P<seconds>\d+(.\d+)?)S)?'
 django/django/utils/dateparse.py:58:    r'(?:(?P<days>-?\d+) (days? ?))?'
 django/django/utils/dateparse.py:60:    r'(?P<hours>\d+):'
 django/django/utils/dateparse.py:61:    r'(?P<minutes>\d\d):'
 django/django/utils/dateparse.py:62:    r'(?P<seconds>\d\d)'
 django/django/utils/dateparse.py:63:
 r'(?:\.(?P<microseconds>\d{1,6}))?'
 django/django/utils/http.py:30:__D = r'(?P<day>\d{2})'
 django/django/utils/http.py:31:__D2 = r'(?P<day>[ \d]\d)'
 django/django/utils/http.py:33:__Y = r'(?P<year>\d{4})'
 django/django/utils/http.py:34:__Y2 = r'(?P<year>\d{2})'
 django/django/utils/http.py:35:__T =
 r'(?P<hour>\d{2}):(?P<min>\d{2}):(?P<sec>\d{2})'
 django/django/utils/html.py:27:unencoded_ampersands_re =
 re.compile(r'&(?!(\w+|#\d+);)')
 django/django/test/client.py:34:CONTENT_TYPE_RE = re.compile(r'.*;
 charset=([\w\d-]+);?')
 django/django/forms/widgets.py:925:    date_re =
 re.compile(r'(\d{4}|0)-(\d\d?)-(\d\d?)$')
 django/django/db/backends/sqlite3/introspection.py:8:field_size_re =
 re.compile(r'^\s*(?:var)?char\s*\(\s*(\d+)\s*\)\s*$')
 django/django/db/backends/mysql/base.py:49:server_version_re =
 re.compile(r'(\d{1,2})\.(\d{1,2})\.(\d{1,2})')
 django/django/db/migrations/writer.py:170:            if
 re.match(r"^import (.*)\.\d+[^\s]*$", line):
 django/django/db/migrations/autodetector.py:1233:        match =
 re.match(r'^\d+', name)
 django/tests/i18n/tests.py:524:            self.assertEqual(r'j \d\e F
 \d\e Y', get_format('DATE_FORMAT'))
 django/tests/logging_tests/tests.py:527:
 self.assertRegex(logger_output.getvalue(), r'^\[[-:,.\s\d]+\] %s' %
 log_msg)
 django/tests/gis_tests/geo3d/tests.py:218:        ref_kml_regex =
 
re.compile(r'^<Point><coordinates>-95.363\d+,29.763\d+,18</coordinates></Point>$')
 django/tests/sitemaps_tests/urls/http.py:198:
 url(r'^i18n/testmodel/(?P<id>\d+)/$', testmodelview,
 name='i18n_testmodel'),
 django/tests/urlpatterns_reverse/urls.py:28:
 url(r'^optional/(?P<arg1>\d+)/(?:(?P<arg2>\d+)/)?', absolute_kwargs_view,
 name="named_optional"),
 django/tests/urlpatterns_reverse/urls.py:29:
 url(r'^optional/(?P<arg1>\d+)/(?:(?P<arg2>\d+)/)?$', absolute_kwargs_view,
 name="named_optional_terminated"),
 }}}




 However, when I sent a pull request, I found the checks are not
 successful. I am still trying to figure it out. Help are welcome!****
 ==
 ==
 ==
 ==
 == **

-- 
Ticket URL: <https://code.djangoproject.com/ticket/28628#comment:8>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/069.e6fe3fbd006dfc00bf9f275d84c777b5%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to