39
39
40
40
import cgi
41
41
from email .utils import parseaddr , formataddr
42
- from string import letters , digits , printable
42
+ from string import ascii_letters , digits , printable
43
43
from unicodedata import category , normalize , name as unicode_name
44
44
45
45
from mig .shared .base import force_unicode , force_utf8
105
105
106
106
# We must be careful about characters that have special regex meaning
107
107
108
- VALID_SAFE_PATH_CHARACTERS = letters + digits + "/.,_-+="
109
- VALID_PATH_CHARACTERS = letters + digits + CURRENCY + "/.,_-+±×÷=½¾" + \
108
+ VALID_SAFE_PATH_CHARACTERS = ascii_letters + digits + "/.,_-+="
109
+ VALID_PATH_CHARACTERS = ascii_letters + digits + CURRENCY + "/.,_-+±×÷=½¾" + \
110
110
" " + "'" + ":;@§%‰()~!&¶"
111
111
112
112
# Plain text here only - *no* html tags, i.e. no '<' or '>' !!
113
113
114
114
VALID_TEXT_CHARACTERS = VALID_PATH_CHARACTERS + CURRENCY + '?#*[]{}' + '"' + \
115
115
"`|^" + '\\ ' + '\n \r \t '
116
- VALID_FQDN_CHARACTERS = letters + digits + '.-'
117
- VALID_BACKEND_NAME_CHARACTERS = letters + digits + '-_'
116
+ VALID_FQDN_CHARACTERS = ascii_letters + digits + '.-'
117
+ VALID_BACKEND_NAME_CHARACTERS = ascii_letters + digits + '-_'
118
118
VALID_BASEURL_CHARACTERS = VALID_FQDN_CHARACTERS + ':/_'
119
119
VALID_URL_CHARACTERS = VALID_BASEURL_CHARACTERS + '?;&%='
120
120
# According to https://tools.ietf.org/html/rfc3986#section-2 URLs may contain
138
138
# Allow these chars in addition to plain letters and digits
139
139
# We explicitly allow email chars in CN to work around broken DNs
140
140
141
- #############################################################################
142
- # IMPORTANT: never allow '+' or '_' in name: reserved for path translation! #
143
- #############################################################################
141
+ #*****************************************************************************
142
+ #* IMPORTANT: never allow '+' or '_' in name: reserved for path translation! *
143
+ #*****************************************************************************
144
144
145
145
name_extras = ' -@.'
146
146
147
- #############################################################################
148
- # IMPORTANT: never allow '+' in DN: reserved for path translation! #
149
- #############################################################################
147
+ #*****************************************************************************
148
+ #* IMPORTANT: never allow '+' in DN: reserved for path translation! *
149
+ #*****************************************************************************
150
150
# We allow ':' in DN, however, as it is used by e.g. DanID:
151
151
# /C=DK/O=Ingen organisatorisk tilknytning/CN=${NAME}/serialNumber=PID:${SERIAL}
152
152
# Similarly we must allow '_' in DN since it is valid in emailAddress. We only
165
165
166
166
valid_integer_chars = digits + integer_extras
167
167
valid_float_chars = digits + float_extras
168
- valid_password_chars = letters + digits + password_extras
169
- valid_name_chars = letters + digits + name_extras
170
- valid_dn_chars = letters + digits + dn_extras
168
+ valid_password_chars = ascii_letters + digits + password_extras
169
+ valid_name_chars = ascii_letters + digits + name_extras
170
+ valid_dn_chars = ascii_letters + digits + dn_extras
171
171
valid_username_chars = user_id_charset
172
172
VALID_INTEGER_CHARACTERS = valid_integer_chars
173
173
VALID_FLOAT_CHARACTERS = valid_float_chars
@@ -305,7 +305,8 @@ def valid_printable(contents, min_length=0, max_length=-1):
305
305
def valid_ascii (contents , min_length = 0 , max_length = - 1 , extra_chars = '' ):
306
306
"""Verify that supplied contents only contain ascii characters"""
307
307
308
- __valid_contents (contents , letters + extra_chars , min_length , max_length )
308
+ __valid_contents (
309
+ contents , ascii_letters + extra_chars , min_length , max_length )
309
310
310
311
311
312
def valid_numeric (contents , min_length = 0 , max_length = - 1 ):
@@ -317,7 +318,8 @@ def valid_numeric(contents, min_length=0, max_length=-1):
317
318
def valid_alphanumeric (contents , min_length = 0 , max_length = - 1 , extra_chars = '' ):
318
319
"""Verify that supplied contents only contain alphanumeric characters"""
319
320
320
- __valid_contents (contents , letters + digits + extra_chars , min_length ,
321
+ __valid_contents (
322
+ contents , ascii_letters + digits + extra_chars , min_length ,
321
323
max_length )
322
324
323
325
@@ -814,7 +816,7 @@ def __valid_gdp_var(gdp_var):
814
816
"""Verify that supplied gdp_var only contains characters that
815
817
we consider valid in various gdp variable names.
816
818
"""
817
- __valid_contents (gdp_var , letters + '_' )
819
+ __valid_contents (gdp_var , ascii_letters + '_' )
818
820
819
821
820
822
def valid_gdp_category_id (category_id ):
@@ -835,7 +837,7 @@ def valid_gdp_ref_value(ref_value):
835
837
"""Verify that supplied ref_value only contains characters that
836
838
we consider valid in GDP ref values.
837
839
"""
838
- __valid_contents (ref_value , letters + digits + '+-=/.:_' )
840
+ __valid_contents (ref_value , ascii_letters + digits + '+-=/.:_' )
839
841
840
842
841
843
def valid_cloud_instance_id (
@@ -1026,8 +1028,9 @@ def valid_workflow_attributes(attributes):
1026
1028
1027
1029
1028
1030
def valid_workflow_operation (operation ):
1029
- """Verify that the supplied workflow
1030
- operation only contains letters + _ """
1031
+ """Verify that the supplied workflow operation only contains letters and
1032
+ underscores.
1033
+ """
1031
1034
valid_ascii (operation , extra_chars = '_' )
1032
1035
1033
1036
@@ -1055,19 +1058,23 @@ def valid_job_attributes(attributes):
1055
1058
1056
1059
1057
1060
def valid_job_type (type ):
1058
- """Verify that the supplied job type only contains letters + _ """
1061
+ """Verify that the supplied job type only contains letters and
1062
+ underscores.
1063
+ """
1059
1064
valid_ascii (type , extra_chars = '_' )
1060
1065
1061
1066
1062
1067
def valid_job_operation (operation ):
1063
- """Verify that the supplied job operation only contains letters + _ """
1068
+ """Verify that the supplied job operation only contains letters and
1069
+ underscores.
1070
+ """
1064
1071
valid_ascii (operation , extra_chars = '_' )
1065
1072
1066
1073
1067
1074
def filter_ascii (contents ):
1068
1075
"""Filter supplied contents to only contain ascii characters"""
1069
1076
1070
- return __filter_contents (contents , letters )
1077
+ return __filter_contents (contents , ascii_letters )
1071
1078
1072
1079
1073
1080
def filter_numeric (contents ):
@@ -1079,13 +1086,13 @@ def filter_numeric(contents):
1079
1086
def filter_alphanumeric (contents ):
1080
1087
"""Filter supplied contents to only contain alphanumeric characters"""
1081
1088
1082
- return __filter_contents (contents , letters + digits )
1089
+ return __filter_contents (contents , ascii_letters + digits )
1083
1090
1084
1091
1085
1092
def filter_alphanumeric_and_spaces (contents ):
1086
1093
"""Filter supplied contents to only contain alphanumeric characters"""
1087
1094
1088
- return __filter_contents (contents , letters + digits + ' ' )
1095
+ return __filter_contents (contents , ascii_letters + digits + ' ' )
1089
1096
1090
1097
1091
1098
def filter_date (contents ):
0 commit comments