Index: django/db/models/fields/__init__.py
===================================================================
--- django/db/models/fields/__init__.py	(révision 9781)
+++ django/db/models/fields/__init__.py	(copie de travail)
@@ -710,6 +710,21 @@
         defaults.update(kwargs)
         return super(IPAddressField, self).formfield(**defaults)
 
+class IP6AddressField(Field):
+    empty_strings_allowed = False
+    def __init__(self, *args, **kwargs):
+        kwargs['max_length'] = 39
+        Field.__init__(self, *args, **kwargs)
+
+    def get_internal_type(self):
+        return "IP6AddressField"
+
+    def formfield(self, **kwargs):
+        defaults = {'form_class': forms.IP6AddressField}
+        defaults.update(kwargs)
+        return super(IP6AddressField, self).formfield(**defaults)
+
+
 class NullBooleanField(Field):
     empty_strings_allowed = False
     def __init__(self, *args, **kwargs):
Index: django/db/backends/postgresql/introspection.py
===================================================================
--- django/db/backends/postgresql/introspection.py	(révision 9781)
+++ django/db/backends/postgresql/introspection.py	(copie de travail)
@@ -8,7 +8,7 @@
         23: 'IntegerField',
         25: 'TextField',
         701: 'FloatField',
-        869: 'IPAddressField',
+        869: 'IP6AddressField',
         1043: 'CharField',
         1082: 'DateField',
         1083: 'TimeField',
Index: django/db/backends/postgresql/creation.py
===================================================================
--- django/db/backends/postgresql/creation.py	(révision 9781)
+++ django/db/backends/postgresql/creation.py	(copie de travail)
@@ -19,6 +19,7 @@
         'FloatField':        'double precision',
         'IntegerField':      'integer',
         'IPAddressField':    'inet',
+        'IP6AddressField':   'inet',
         'NullBooleanField':  'boolean',
         'OneToOneField':     'integer',
         'PositiveIntegerField': 'integer CHECK ("%(column)s" >= 0)',
Index: django/db/backends/sqlite3/creation.py
===================================================================
--- django/db/backends/sqlite3/creation.py	(révision 9781)
+++ django/db/backends/sqlite3/creation.py	(copie de travail)
@@ -20,6 +20,7 @@
         'FloatField':                   'real',
         'IntegerField':                 'integer',
         'IPAddressField':               'char(15)',
+        'IP6AddressField':              'char(39)',
         'NullBooleanField':             'bool',
         'OneToOneField':                'integer',
         'PositiveIntegerField':         'integer unsigned',
Index: django/db/backends/mysql/creation.py
===================================================================
--- django/db/backends/mysql/creation.py	(révision 9781)
+++ django/db/backends/mysql/creation.py	(copie de travail)
@@ -19,6 +19,7 @@
         'FloatField':        'double precision',
         'IntegerField':      'integer',
         'IPAddressField':    'char(15)',
+        'IP6AddressField':   'char(39)',
         'NullBooleanField':  'bool',
         'OneToOneField':     'integer',
         'PositiveIntegerField': 'integer UNSIGNED',
@@ -63,4 +64,4 @@
                 field.rel.to._meta.db_table, field.rel.to._meta.pk.column)
             ]
         return table_output, deferred
-        
\ Pas de fin de ligne à la fin du fichier
+        
Index: django/db/backends/oracle/creation.py
===================================================================
--- django/db/backends/oracle/creation.py	(révision 9781)
+++ django/db/backends/oracle/creation.py	(copie de travail)
@@ -28,6 +28,7 @@
         'FloatField':                   'DOUBLE PRECISION',
         'IntegerField':                 'NUMBER(11)',
         'IPAddressField':               'VARCHAR2(15)',
+        'IP6AddressField':              'VARCHAR2(39)',
         'NullBooleanField':             'NUMBER(1) CHECK ((%(qn_column)s IN (0,1)) OR (%(qn_column)s IS NULL))',
         'OneToOneField':                'NUMBER(11)',
         'PositiveIntegerField':         'NUMBER(11) CHECK (%(qn_column)s >= 0)',
Index: django/forms/fields.py
===================================================================
--- django/forms/fields.py	(révision 9781)
+++ django/forms/fields.py	(copie de travail)
@@ -26,6 +26,7 @@
 import django.core.exceptions
 from django.utils.translation import ugettext_lazy as _
 from django.utils.encoding import smart_unicode, smart_str
+from django.utils.http import ip6_normalize
 
 from util import ErrorList, ValidationError
 from widgets import TextInput, PasswordInput, HiddenInput, MultipleHiddenInput, FileInput, CheckboxInput, Select, NullBooleanSelect, SelectMultiple, DateTimeInput, TimeInput, SplitDateTimeWidget, SplitHiddenDateTimeWidget
@@ -40,7 +41,7 @@
     'BooleanField', 'NullBooleanField', 'ChoiceField', 'MultipleChoiceField',
     'ComboField', 'MultiValueField', 'FloatField', 'DecimalField',
     'SplitDateTimeField', 'IPAddressField', 'FilePathField', 'SlugField',
-    'TypedChoiceField'
+    'TypedChoiceField', 'IP6AddressField'
 )
 
 # These values, if given to to_python(), will trigger the self.required check.
@@ -881,6 +882,25 @@
     def __init__(self, *args, **kwargs):
         super(IPAddressField, self).__init__(ipv4_re, *args, **kwargs)
 
+ipv6_re = re.compile(r'^[0-9a-fA-F]{1,4}(:[0-9a-fA-F]{1,4}){7}$')
+
+class IP6AddressField(CharField):
+    def __init__(self, *args, **kwargs):
+        super(IP6AddressField, self).__init__(39, 3, *args, **kwargs)
+
+    def clean(self, value):
+        value = super(IP6AddressField, self).clean(value)
+        if value == u'':
+            return value
+        if not ipv4_re.search(value):
+            try:
+                ip = ip6_normalize(value)
+                if not ipv6_re.search(ip):
+                    raise ValidationError(_(u'Enter a valid IP address.'))
+            except ValueError:
+                raise ValidationError(_(u'Enter a valid IP address.'))
+        return value
+
 slug_re = re.compile(r'^[-\w]+$')
 
 class SlugField(RegexField):
Index: django/utils/http.py
===================================================================
--- django/utils/http.py	(révision 9781)
+++ django/utils/http.py	(copie de travail)
@@ -94,3 +94,55 @@
         i = i % j
         factor -= 1
     return ''.join(base36)
+
+
+def ip6_normalize(addr):
+    """
+    Normalize an IPv6 address to allow easy regexp validation
+    mostly checks the length, and gets ride of tricky things
+    like IPv4 mapped addresses and :: shortcuts
+    
+    Outputs a string
+    """
+    # Some basic error checking
+    if addr.count('::') > 2 or ':::' in addr:
+        raise ValueError
+
+    ip = addr.split(':')
+    nbfull = len([elem for elem in ip if elem != ''])
+    nb = len(ip)
+
+    if nbfull >= 1 and '.' in ip[-1]:
+        # Convert IPv4 mapped addresses to full hexa
+        ipv4 = ip[-1].split('.')
+        hex1 = (int(ipv4[0]) << 8) + int(ipv4[1])
+        hex2 = (int(ipv4[2]) << 8) + int(ipv4[3])
+        ip[-1:] = [hex(hex1)[2:], hex(hex2)[2:]]
+        nbfull = nbfull + 1
+        nb = nb + 1
+
+    if nbfull == 8 or nbfull == nb:
+        # No need to bother
+        return addr
+    elif nbfull > 8:
+        # Has to be invalid anyway
+        raise ValueError
+
+    # Begin normalization
+    start, end, index = (None, None, 0)
+    for elem in ip:
+        if elem == '':
+            if start is None:
+                start = index
+                end = index
+            else:
+                end = index
+        index += 1
+    pad = 8 - nbfull
+    if end != start:
+        ip[start:end-start+1] = ['0'] * pad
+    else:
+        ip[start] = '0'
+        if pad > 1:
+            ip[start:1] = ['0'] * (pad - 1)
+    return ':'.join([item for item in ip if len(item) > 0])
Index: tests/regressiontests/forms/extra.py
===================================================================
--- tests/regressiontests/forms/extra.py	(révision 9781)
+++ tests/regressiontests/forms/extra.py	(copie de travail)
@@ -377,6 +377,85 @@
 ...
 ValidationError: [u'Enter a valid IPv4 address.']
 
+# IP6AddressField ##################################################################
+
+>>> f = IP6AddressField()
+>>> f.clean('')
+Traceback (most recent call last):
+...
+ValidationError: [u'This field is required.']
+>>> f.clean(None)
+Traceback (most recent call last):
+...
+ValidationError: [u'This field is required.']
+>>> f.clean('127.0.0.1')
+u'127.0.0.1'
+>>> f.clean('2a01:05d8:25ae:9451:020d:39bc:21e6:8cab')
+u'2a01:05d8:25ae:9451:020d:39bc:21e6:8cab'
+>>> f.clean('2a01:5d8:25ae:9451:20d:39bc:21e6:8cab')
+u'2a01:5d8:25ae:9451:20d:39bc:21e6:8cab'
+>>> f.clean('::1')
+u'::1'
+>>> f.clean('::ffff:88.191.32.1')
+u'::ffff:88.191.32.1'
+>>> f.clean('foo')
+Traceback (most recent call last):
+...
+ValidationError: [u'Enter a valid IP address.']
+>>> f.clean('127.0.0.')
+Traceback (most recent call last):
+...
+ValidationError: [u'Enter a valid IP address.']
+>>> f.clean('::1:')
+Traceback (most recent call last):
+...
+ValidationError: [u'Enter a valid IP address.']
+>>> f.clean('1.2.3.4.5')
+Traceback (most recent call last):
+...
+ValidationError: [u'Enter a valid IP address.']
+>>> f.clean('2a01:5d8:25ae:9451:20d:39bc:21e6:8cab:fb2c')
+Traceback (most recent call last):
+...
+ValidationError: [u'Ensure this value has at most 39 characters (it has 42).']
+>>> f.clean('2a01:5d8:25ae:9451:20d:39bc:1e6:cab:b2c')
+Traceback (most recent call last):
+...
+ValidationError: [u'Enter a valid IP address.']
+>>> f.clean('256.125.1.5')
+Traceback (most recent call last):
+...
+ValidationError: [u'Enter a valid IP address.']
+>>> f.clean('::12345')
+Traceback (most recent call last):
+...
+ValidationError: [u'Enter a valid IP address.']
+
+>>> f = IP6AddressField(required=False)
+>>> f.clean('')
+u''
+>>> f.clean(None)
+u''
+>>> f.clean('127.0.0.1')
+u'127.0.0.1'
+>>> f.clean('foo')
+Traceback (most recent call last):
+...
+ValidationError: [u'Enter a valid IP address.']
+>>> f.clean('127.0.0.')
+Traceback (most recent call last):
+...
+ValidationError: [u'Enter a valid IP address.']
+>>> f.clean('1.2.3.4.5')
+Traceback (most recent call last):
+...
+ValidationError: [u'Enter a valid IP address.']
+>>> f.clean('256.125.1.5')
+Traceback (most recent call last):
+...
+ValidationError: [u'Enter a valid IP address.']
+
+
 #################################
 # Tests of underlying functions #
 #################################
Index: docs/topics/forms/modelforms.txt
===================================================================
--- docs/topics/forms/modelforms.txt	(révision 9781)
+++ docs/topics/forms/modelforms.txt	(copie de travail)
@@ -60,6 +60,7 @@
     ``ImageField``                   ``ImageField``
     ``IntegerField``                 ``IntegerField``
     ``IPAddressField``               ``IPAddressField``
+    ``IP6AddressField``              ``IP6AddressField``
     ``ManyToManyField``              ``ModelMultipleChoiceField`` (see
                                      below)
     ``NullBooleanField``             ``CharField``
Index: docs/ref/models/fields.txt
===================================================================
--- docs/ref/models/fields.txt	(révision 9781)
+++ docs/ref/models/fields.txt	(copie de travail)
@@ -626,9 +626,18 @@
 
 .. class:: IPAddressField([**options])
 
-An IP address, in string format (e.g. "192.0.2.30"). The admin represents this
+An IPv4 address, in string format (e.g. "192.0.2.30"). The admin represents this
 as an ``<input type="text">`` (a single-line input).
 
+``IP6AddressField``
+------------------
+
+.. class:: IP6AddressField([**options])
+
+An IPv4 or IPv6 address, in string format (e.g. "192.0.2.30" or 
+"2a01:5d8:25ae:9451:20d:39bc:1e6:cab:b2c"). The admin represents this as an 
+``<input type="text">`` (a single-line input).
+
 ``NullBooleanField``
 --------------------
 
Index: docs/ref/forms/fields.txt
===================================================================
--- docs/ref/forms/fields.txt	(révision 9781)
+++ docs/ref/forms/fields.txt	(copie de travail)
@@ -623,6 +623,19 @@
       expression.
     * Error message keys: ``required``, ``invalid``
 
+``IP6AddressField``
+~~~~~~~~~~~~~~~~~~
+
+.. class:: IP6AddressField(**kwargs)
+
+    * Default widget: ``TextInput``
+    * Empty value: ``''`` (an empty string)
+    * Normalizes to: A Unicode object.
+    * Validates that the given value is a valid IPv4 or IPv6 address, using 
+      a regular expression.
+    * Error message keys: ``required``, ``invalid``
+
+
 ``MultipleChoiceField``
 ~~~~~~~~~~~~~~~~~~~~~~~
 
