Ticket #811: ipv6.diff
File ipv6.diff, 13.9 KB (added by , 17 years ago) |
---|
-
django/oldforms/__init__.py
933 933 934 934 def isValidIPAddress(self, field_data, all_data): 935 935 try: 936 validators.isValidIP Address4(field_data, all_data)936 validators.isValidIP4Address(field_data, all_data) 937 937 except validators.ValidationError, e: 938 938 raise validators.CriticalValidationError, e.messages 939 939 … … 941 941 return data or None 942 942 html2python = staticmethod(html2python) 943 943 944 class IP6AddressField(IPAddressField): 945 def __init__(self, field_name, length=39, max_length=39, is_required=False, validator_list=None): 946 if validator_list is None: validator_list = [] 947 validator_list = [self.isValidIPAddress] + validator_list 948 TextField.__init__(self, field_name, length=length, max_length=max_length, 949 is_required=is_required, validator_list=validator_list) 950 951 def isValidIPAddress(self, field_data, all_data): 952 try: 953 validators.isValidIPAddress(field_data, all_data) 954 except validators.ValidationError, e: 955 raise validators.CriticalValidationError, e.messages 956 957 def html2python(data): 958 return data or None 959 html2python = staticmethod(html2python) 960 944 961 #################### 945 962 # MISCELLANEOUS # 946 963 #################### -
django/db/models/fields/__init__.py
894 894 defaults.update(kwargs) 895 895 return super(IPAddressField, self).formfield(**defaults) 896 896 897 class IP6AddressField(Field): 898 empty_strings_allowed = False 899 def __init__(self, *args, **kwargs): 900 kwargs['max_length'] = 39 901 Field.__init__(self, *args, **kwargs) 902 903 def get_manipulator_field_objs(self): 904 return [oldforms.IP6AddressField] 905 906 def validate(self, field_data, all_data): 907 validators.isValidIPAddress(field_data, None) 908 909 def formfield(self, **kwargs): 910 defaults = {'form_class': forms.IP6AddressField} 911 defaults.update(kwargs) 912 return super(IP6AddressField, self).formfield(**defaults) 913 914 897 915 class NullBooleanField(Field): 898 916 empty_strings_allowed = False 899 917 def __init__(self, *args, **kwargs): -
django/db/backends/ado_mssql/creation.py
12 12 'ImageField': 'varchar(%(max_length)s)', 13 13 'IntegerField': 'int', 14 14 'IPAddressField': 'char(15)', 15 'IP6AddressField': 'char(39)', 15 16 'NullBooleanField': 'bit', 16 17 'OneToOneField': 'int', 17 18 'PhoneNumberField': 'varchar(20)', -
django/db/backends/postgresql/introspection.py
75 75 23: 'IntegerField', 76 76 25: 'TextField', 77 77 701: 'FloatField', 78 869: 'IP AddressField',78 869: 'IP6AddressField', 79 79 1043: 'CharField', 80 80 1082: 'DateField', 81 81 1083: 'TimeField', -
django/db/backends/postgresql/creation.py
16 16 'ImageField': 'varchar(%(max_length)s)', 17 17 'IntegerField': 'integer', 18 18 'IPAddressField': 'inet', 19 'IP6AddressField': 'inet', 19 20 'NullBooleanField': 'boolean', 20 21 'OneToOneField': 'integer', 21 22 'PhoneNumberField': 'varchar(20)', -
django/db/backends/mysql_old/creation.py
16 16 'ImageField': 'varchar(%(max_length)s)', 17 17 'IntegerField': 'integer', 18 18 'IPAddressField': 'char(15)', 19 'IP6AddressField': 'char(39)', 19 20 'NullBooleanField': 'bool', 20 21 'OneToOneField': 'integer', 21 22 'PhoneNumberField': 'varchar(20)', -
django/db/backends/sqlite3/creation.py
15 15 'ImageField': 'varchar(%(max_length)s)', 16 16 'IntegerField': 'integer', 17 17 'IPAddressField': 'char(15)', 18 'IP6AddressField': 'char(39)', 18 19 'NullBooleanField': 'bool', 19 20 'OneToOneField': 'integer', 20 21 'PhoneNumberField': 'varchar(20)', -
django/db/backends/mysql/creation.py
16 16 'ImageField': 'varchar(%(max_length)s)', 17 17 'IntegerField': 'integer', 18 18 'IPAddressField': 'char(15)', 19 'IPAddressField': 'char(39)', 19 20 'NullBooleanField': 'bool', 20 21 'OneToOneField': 'integer', 21 22 'PhoneNumberField': 'varchar(20)', -
django/db/backends/oracle/creation.py
19 19 'ImageField': 'NVARCHAR2(%(max_length)s)', 20 20 'IntegerField': 'NUMBER(11)', 21 21 'IPAddressField': 'VARCHAR2(15)', 22 'IP6AddressField': 'VARCHAR2(39)', 22 23 'NullBooleanField': 'NUMBER(1) CHECK ((%(column)s IN (0,1)) OR (%(column)s IS NULL))', 23 24 'OneToOneField': 'NUMBER(11)', 24 25 'PhoneNumberField': 'VARCHAR2(20)', -
django/db/backends/postgresql_psycopg2/introspection.py
72 72 23: 'IntegerField', 73 73 25: 'TextField', 74 74 701: 'FloatField', 75 869: 'IP AddressField',75 869: 'IP6AddressField', 76 76 1043: 'CharField', 77 77 1082: 'DateField', 78 78 1083: 'TimeField', -
django/core/validators.py
106 106 except ValidationError: 107 107 raise ValidationError, _("Enter valid e-mail addresses separated by commas.") 108 108 109 def isValidIP Address4(field_data, all_data):109 def isValidIP4Address(field_data, all_data): 110 110 if not ip4_re.search(field_data): 111 raise ValidationError, _("Please enter a valid IPv4 address.") 112 113 def isValidIPAddress(field_data, all_data): 114 import IPy 115 try: 116 IPy.parseAddress(field_data) 117 except ValueError: 111 118 raise ValidationError, _("Please enter a valid IP address.") 112 119 113 120 def isNotEmpty(field_data, all_data): -
django/newforms/fields.py
16 16 except NameError: 17 17 from sets import Set as set 18 18 19 import IPy 20 19 21 from django.utils.translation import ugettext_lazy as _ 20 22 from django.utils.encoding import StrAndUnicode, smart_unicode, smart_str 21 23 … … 31 33 'RegexField', 'EmailField', 'FileField', 'ImageField', 'URLField', 32 34 'BooleanField', 'NullBooleanField', 'ChoiceField', 'MultipleChoiceField', 33 35 'ComboField', 'MultiValueField', 'FloatField', 'DecimalField', 34 'SplitDateTimeField', 'IPAddressField', 36 'SplitDateTimeField', 'IPAddressField', 'IP6AddressField', 35 37 ) 36 38 37 39 # These values, if given to to_python(), will trigger the self.required check. … … 754 756 755 757 def __init__(self, *args, **kwargs): 756 758 super(IPAddressField, self).__init__(ipv4_re, *args, **kwargs) 759 760 class IP6AddressField(CharField): 761 def __init__(self, *args, **kwargs): 762 super(IP6AddressField, self).__init__(39, 3, *args, **kwargs) 763 764 def clean(self, value): 765 value = super(IP6AddressField, self).clean(value) 766 if value == u'': 767 return value 768 try: 769 IPy.parseAddress(value) 770 except ValueError: 771 raise ValidationError(_(u'Enter a valid IP address.')) 772 return value -
tests/regressiontests/forms/extra.py
310 310 ... 311 311 ValidationError: [u'Enter a valid IPv4 address.'] 312 312 313 # IP6AddressField ################################################################## 314 315 >>> f = IP6AddressField() 316 >>> f.clean('') 317 Traceback (most recent call last): 318 ... 319 ValidationError: [u'This field is required.'] 320 >>> f.clean(None) 321 Traceback (most recent call last): 322 ... 323 ValidationError: [u'This field is required.'] 324 >>> f.clean('127.0.0.1') 325 u'127.0.0.1' 326 >>> f.clean('2a01:05d8:25ae:9451:020d:39bc:21e6:8cab') 327 u'2a01:05d8:25ae:9451:020d:39bc:21e6:8cab' 328 >>> f.clean('2a01:5d8:25ae:9451:20d:39bc:21e6:8cab') 329 u'2a01:5d8:25ae:9451:20d:39bc:21e6:8cab' 330 >>> f.clean('::1') 331 u'::1' 332 >>> f.clean('::ffff:88.191.32.1') 333 u'::ffff:88.191.32.1' 334 >>> f.clean('foo') 335 Traceback (most recent call last): 336 ... 337 ValidationError: [u'Enter a valid IP address.'] 338 >>> f.clean('127.0.0.') 339 Traceback (most recent call last): 340 ... 341 ValidationError: [u'Enter a valid IP address.'] 342 >>> f.clean('::1:') 343 Traceback (most recent call last): 344 ... 345 ValidationError: [u'Enter a valid IP address.'] 346 >>> f.clean('1.2.3.4.5') 347 Traceback (most recent call last): 348 ... 349 ValidationError: [u'Enter a valid IP address.'] 350 >>> f.clean('2a01:5d8:25ae:9451:20d:39bc:21e6:8cab:fb2c') 351 Traceback (most recent call last): 352 ... 353 ValidationError: [u'Ensure this value has at most 39 characters (it has 42).'] 354 >>> f.clean('2a01:5d8:25ae:9451:20d:39bc:1e6:cab:b2c') 355 Traceback (most recent call last): 356 ... 357 ValidationError: [u'Enter a valid IP address.'] 358 >>> f.clean('256.125.1.5') 359 Traceback (most recent call last): 360 ... 361 ValidationError: [u'Enter a valid IP address.'] 362 >>> f.clean('::12345') 363 Traceback (most recent call last): 364 ... 365 ValidationError: [u'Enter a valid IP address.'] 366 367 >>> f = IP6AddressField(required=False) 368 >>> f.clean('') 369 u'' 370 >>> f.clean(None) 371 u'' 372 >>> f.clean('127.0.0.1') 373 u'127.0.0.1' 374 >>> f.clean('foo') 375 Traceback (most recent call last): 376 ... 377 ValidationError: [u'Enter a valid IP address.'] 378 >>> f.clean('127.0.0.') 379 Traceback (most recent call last): 380 ... 381 ValidationError: [u'Enter a valid IP address.'] 382 >>> f.clean('1.2.3.4.5') 383 Traceback (most recent call last): 384 ... 385 ValidationError: [u'Enter a valid IP address.'] 386 >>> f.clean('256.125.1.5') 387 Traceback (most recent call last): 388 ... 389 ValidationError: [u'Enter a valid IP address.'] 390 391 313 392 ################################# 314 393 # Tests of underlying functions # 315 394 ################################# -
docs/newforms.txt
1390 1390 expression. 1391 1391 * Error message keys: ``required``, ``invalid`` 1392 1392 1393 ``IP6AddressField`` 1394 ~~~~~~~~~~~~~~~~~~ 1395 1396 * Default widget: ``TextInput`` 1397 * Empty value: ``''`` (an empty string) 1398 * Normalizes to: A Unicode object. 1399 * Validates that the given value is a valid IPv4 or IPv6 address, using 1400 IPy 1401 * Error message keys: ``required``, ``invalid`` 1402 1393 1403 ``MultipleChoiceField`` 1394 1404 ~~~~~~~~~~~~~~~~~~~~~~~ 1395 1405 -
docs/model-api.txt
388 388 389 389 The admin represents this as an ``<input type="text">`` (a single-line input). 390 390 391 ``IP6AddressField`` 392 ~~~~~~~~~~~~~~~~~~ 393 394 An IPv6 or IPv4 address, in string format (i.e. "24.124.1.30", 395 "2002:58bf:278c::1", "::ffff:88.191.52.1"). 396 397 The admin represents this as an ``<input type="text">`` (a single-line input). 398 399 Requires `IPy`_. 400 401 .. _IPy: http://software.inl.fr//trac/wiki/IPy 402 391 403 ``NullBooleanField`` 392 404 ~~~~~~~~~~~~~~~~~~~~ 393 405 -
docs/modelforms.txt
58 58 ``ImageField`` ``ImageField`` 59 59 ``IntegerField`` ``IntegerField`` 60 60 ``IPAddressField`` ``IPAddressField`` 61 ``IP6AddressField`` ``IP6AddressField`` 61 62 ``ManyToManyField`` ``ModelMultipleChoiceField`` (see 62 63 below) 63 64 ``NullBooleanField`` ``CharField`` -
docs/form_for_model.txt
65 65 ``ImageField`` ``ImageField`` 66 66 ``IntegerField`` ``IntegerField`` 67 67 ``IPAddressField`` ``IPAddressField`` 68 ``IP6AddressField`` ``IP6AddressField`` 68 69 ``ManyToManyField`` ``ModelMultipleChoiceField`` (see 69 70 below) 70 71 ``NullBooleanField`` ``CharField``