Python Regex sucks!

- Allow locale characters and space for repo name

BUG:FIXED:8361
This commit is contained in:
Faik Uygur
2009-01-29 09:05:48 +00:00
parent a63fd26868
commit 746f26b0f8
2 changed files with 23 additions and 1 deletions
+1 -1
View File
@@ -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):
+22
View File
@@ -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)