Browse Source

is_IP() made more versatile and added some comments

pull/2105/head
José Oliveira 8 years ago
parent
commit
21dea9f93c
  1. 14
      flask/helpers.py
  2. 2
      flask/sessions.py

14
flask/helpers.py

@ -959,7 +959,15 @@ def total_seconds(td):
"""
return td.days * 60 * 60 * 24 + td.seconds
def is_IP(string):
def is_IP(string, var_name):
"""Returns the if the string received is an IP or not.
:param string: the string to check if it an IP or not
:param var_name: the name of the variable that is being checked
:returns: True if string is an IP, False if not
:rtype: boolean
"""
ipv4 = string.split('.')
ipv6 = string.split(':')
try:
@ -967,7 +975,7 @@ def is_IP(string):
if not t:
ipv6[i] = "0"
if(all(int(t,16) >= 0 and int(t,16) <= 65535 for t in ipv6)):
print("IPv6 address introduced in SESSION_COOKIE_DOMAIN!")
print("IPv6 address introduced in " + var_name)
return True
except ValueError:
pass
@ -975,7 +983,7 @@ def is_IP(string):
if len(ipv4) == 4:
try:
if(all(int(t) >= 0 and int(t) <= 255 for t in ipv4)):
print("IPv4 address introduced in SESSION_COOKIE_DOMAIN!")
print("IPv4 address introduced in " + var_name)
except ValueError:
return False
else:

2
flask/sessions.py

@ -332,7 +332,7 @@ class SecureCookieSessionInterface(SessionInterface):
def save_session(self, app, session, response):
domain = self.get_cookie_domain(app)
is_IP(domain)
is_IP(domain, "SESSION_COOKIE_DOMAIN")
path = self.get_cookie_path(app)
# Delete case. If there is no session we bail early.

Loading…
Cancel
Save