Skip to content

Commit d6effbf

Browse files
committed
Remove unpack_ipv4 parameter
1 parent 466575b commit d6effbf

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

rest_framework/fields.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -661,17 +661,18 @@ class IPAddressField(CharField):
661661
'invalid': _('Enter a valid IPv4 or IPv6 address.'),
662662
}
663663

664-
def __init__(self, protocol='both', unpack_ipv4=False, **kwargs):
664+
def __init__(self, protocol='both', **kwargs):
665665
self.protocol = protocol.lower()
666-
self.unpack_ipv4 = unpack_ipv4
666+
self.unpack_ipv4 = (self.protocol == 'both')
667667
super(IPAddressField, self).__init__(**kwargs)
668-
validators, error_message = ip_address_validators(protocol, unpack_ipv4)
668+
validators, error_message = ip_address_validators(protocol, self.unpack_ipv4)
669669
self.validators.extend(validators)
670670

671671
def to_internal_value(self, data):
672672
if data and ':' in data:
673673
try:
674-
return clean_ipv6_address(data, self.unpack_ipv4)
674+
if self.protocol in ('both', 'ipv6'):
675+
return clean_ipv6_address(data, self.unpack_ipv4)
675676
except DjangoValidationError:
676677
self.fail('invalid', value=data)
677678

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy