MCPcopy
hub / github.com/django/django / to_python

Method to_python

django/forms/fields.py:783–802  ·  view source on GitHub ↗
(self, value)

Source from the content-addressed store, hash-verified

781 super().__init__(strip=True, **kwargs)
782
783 def to_python(self, value):
784 value = super().to_python(value)
785 if value:
786 # Detect scheme via partition to avoid calling urlsplit() on
787 # potentially large or slow-to-normalize inputs.
788 scheme, sep, _ = value.partition(":")
789 if (
790 not sep
791 or not scheme
792 or not scheme[0].isascii()
793 or not scheme[0].isalpha()
794 or "/" in scheme
795 ):
796 # No valid scheme found -- prepend the assumed scheme. Handle
797 # scheme-relative URLs ("//example.com") separately.
798 if value.startswith("//"):
799 value = self.assume_scheme + ":" + value
800 else:
801 value = self.assume_scheme + "://" + value
802 return value
803
804
805class BooleanField(Field):

Calls 1

to_pythonMethod · 0.45