Python Regex sucks!
- Allow locale characters and space for repo name BUG:FIXED:8361
This commit is contained in:
+1
-1
@@ -625,7 +625,7 @@ def index(dirs=None, output='pisi-index.xml', skip_sources=False, skip_signing=F
|
|||||||
|
|
||||||
@locked
|
@locked
|
||||||
def add_repo(name, indexuri, at = None):
|
def add_repo(name, indexuri, at = None):
|
||||||
if not re.match("^[a-zA-Z0-9\\-\\_\\.]*$", name):
|
if not re.match("^[%s\\-\\_\\.\s]*$" % str(pisi.util.letters()), name):
|
||||||
raise pisi.Error(_('Not a valid repo name.'))
|
raise pisi.Error(_('Not a valid repo name.'))
|
||||||
repodb = pisi.db.repodb.RepoDB()
|
repodb = pisi.db.repodb.RepoDB()
|
||||||
if repodb.has_repo(name):
|
if repodb.has_repo(name):
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
"""misc. utility functions, including process and file utils"""
|
"""misc. utility functions, including process and file utils"""
|
||||||
|
|
||||||
# standard python modules
|
# standard python modules
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
@@ -22,6 +23,7 @@ import string
|
|||||||
import statvfs
|
import statvfs
|
||||||
import operator
|
import operator
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import unicodedata
|
||||||
|
|
||||||
import gettext
|
import gettext
|
||||||
__trans = gettext.translation('pisi', fallback=True)
|
__trans = gettext.translation('pisi', fallback=True)
|
||||||
@@ -673,3 +675,23 @@ def config_changed(config_file):
|
|||||||
if pisi.util.sha1_file(fpath) != config_file.hash:
|
if pisi.util.sha1_file(fpath) != config_file.hash:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
# Python regex sucks
|
||||||
|
# http://mail.python.org/pipermail/python-list/2009-January/523704.html
|
||||||
|
def letters():
|
||||||
|
start = end = None
|
||||||
|
result = []
|
||||||
|
for index in xrange(sys.maxunicode + 1):
|
||||||
|
c = unichr(index)
|
||||||
|
if unicodedata.category(c)[0] == 'L':
|
||||||
|
if start is None:
|
||||||
|
start = end = c
|
||||||
|
else:
|
||||||
|
end = c
|
||||||
|
elif start:
|
||||||
|
if start == end:
|
||||||
|
result.append(start)
|
||||||
|
else:
|
||||||
|
result.append(start + "-" + end)
|
||||||
|
start = None
|
||||||
|
return ''.join(result)
|
||||||
|
|||||||
Reference in New Issue
Block a user