Ticket #811: ip6field.diff
File ip6field.diff, 6.3 KB (added by , 19 years ago) |
---|
-
django/core/formfields.py
712 712 return data or None 713 713 html2python = staticmethod(html2python) 714 714 715 class IP6AddressField(TextField): 716 def __init__(self, field_name, length=39, maxlength=39, is_required=False, validator_list=[]): 717 validator_list = [self.isValidIPAddress] + validator_list 718 TextField.__init__(self, field_name, length=length, maxlength=maxlength, 719 is_required=is_required, validator_list=validator_list) 720 721 def isValidIPAddress(self, field_data, all_data): 722 try: 723 validators.isValidIPAddress6(field_data, all_data) 724 except validators.ValidationError, e: 725 raise validators.CriticalValidationError, e.messages 726 727 def html2python(data): 728 return data or None 729 html2python = staticmethod(html2python) 730 715 731 #################### 716 732 # MISCELLANEOUS # 717 733 #################### -
django/core/db/backends/ado_mssql.py
145 145 'ImageField': 'varchar(100)', 146 146 'IntegerField': 'int', 147 147 'IPAddressField': 'char(15)', 148 'IP6AddressField': 'char(39)', 148 149 'ManyToManyField': None, 149 150 'NullBooleanField': 'bit', 150 151 'OneToOneField': 'int', -
django/core/db/backends/postgresql.py
166 166 'ImageField': 'varchar(100)', 167 167 'IntegerField': 'integer', 168 168 'IPAddressField': 'inet', 169 'IP6AddressField': 'inet', 169 170 'ManyToManyField': None, 170 171 'NullBooleanField': 'boolean', 171 172 'OneToOneField': 'integer', -
django/core/db/backends/sqlite3.py
164 164 'ImageField': 'varchar(100)', 165 165 'IntegerField': 'integer', 166 166 'IPAddressField': 'char(15)', 167 'IP6AddressField': 'char(39)', 167 168 'ManyToManyField': None, 168 169 'NullBooleanField': 'bool', 169 170 'OneToOneField': 'integer', -
django/core/db/backends/mysql.py
161 161 'ImageField': 'varchar(100)', 162 162 'IntegerField': 'integer', 163 163 'IPAddressField': 'char(15)', 164 'IP6AddressField': 'char(39)', 164 165 'ManyToManyField': None, 165 166 'NullBooleanField': 'bool', 166 167 'OneToOneField': 'integer', -
django/core/meta/fields.py
507 507 def get_manipulator_field_objs(self): 508 508 return [formfields.IPAddressField] 509 509 510 class IP6AddressField(Field): 511 def __init__(self, *args, **kwargs): 512 kwargs['maxlength'] = 15 513 Field.__init__(self, *args, **kwargs) 514 515 def get_manipulator_field_objs(self): 516 return [formfields.IP6AddressField] 517 510 518 class NullBooleanField(Field): 511 519 def __init__(self, *args, **kwargs): 512 520 kwargs['null'] = True -
django/core/validators.py
21 21 email_re = re.compile(r'^((([\t\x20]*[!#-\'\*\+\-/-9=\?A-Z\^-~]+[\t\x20]*|"[\x01-\x09\x0B\x0C\x0E-\x21\x23-\x5B\x5D-\x7F]*")+)?[\t\x20]*<([\t\x20]*[!#-\'\*\+\-/-9=\?A-Z\^-~]+(\.[!#-\'\*\+\-/-9=\?A-Z\^-~]+)*|"[\x01-\x09\x0B\x0C\x0E-\x21\x23-\x5B\x5D-\x7F]*")@(([a-zA-Z0-9][-a-zA-Z0-9]*[a-zA-Z0-9]\.)+[a-zA-Z]{2,}|\[(([0-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\])>[\t\x20]*|([\t\x20]*[!#-\'\*\+\-/-9=\?A-Z\^-~]+(\.[!#-\'\*\+\-/-9=\?A-Z\^-~]+)*|"[\x01-\x09\x0B\x0C\x0E-\x21\x23-\x5B\x5D-\x7F]*")@(([a-zA-Z0-9][-a-zA-Z0-9]*[a-zA-Z0-9]\.)+[a-zA-Z]{2,}|\[(([0-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]?[0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\]))$') 22 22 integer_re = re.compile(r'^-?\d+$') 23 23 ip4_re = re.compile(r'^(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}$') 24 _ip6_hex_re = r'(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}' 25 _ip6_hex_compressed_re = r'((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)::((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)' 26 _ip6_ipv4_compat_re = r'((?:[0-9A-Fa-f]{1,4}:){6,6})(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}' 27 _ip6_ipv4_compat_compressed_re = r'((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)::((?:[0-9A-Fa-f]{1,4}:)*)(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}' 28 ip6_re = re.compile('^(%s|%s|%s|%s)$' % (_ip6_hex_re, _ip6_hex_compressed_re, _ip6_ipv4_compat_re, _ip6_ipv4_compat_compressed_re)) 24 29 phone_re = re.compile(r'^[A-PR-Y0-9]{3}-[A-PR-Y0-9]{3}-[A-PR-Y0-9]{4}$', re.IGNORECASE) 25 30 slug_re = re.compile(r'^[-\w]+$') 26 31 url_re = re.compile(r'^http://\S+$') … … 93 98 except ValidationError: 94 99 raise ValidationError, _("Enter valid e-mail addresses separated by commas.") 95 100 101 def isValidIPAddress(field_data, all_data): 102 if not (ip4_re.search(field_data) or ip6_re.search(field_data)): 103 raise ValidationError, _("Please enter a valid IPv4 or IPv6 address.") 104 96 105 def isValidIPAddress4(field_data, all_data): 97 106 if not ip4_re.search(field_data): 98 raise ValidationError, _("Please enter a valid IP address.")107 raise ValidationError, _("Please enter a valid IPv4 address.") 99 108 109 def isValidIPAddress6(field_data, all_data): 110 if not ip6_re.search(field_data): 111 raise ValidationError, _("Please enter a valid IPv6 address.") 112 100 113 def isNotEmpty(field_data, all_data): 101 114 if field_data.strip() == '': 102 115 raise ValidationError, _("Empty values are not allowed here.")