def get_or_create(model, **kwargs):
    """ Returns an instance of model and whether or not it already existed in a tuple. """
    instance = model.query.filter_by(**kwargs).first()
    if instance:
        return instance, False
    else:
        instance = model(**kwargs)
        return instance, True
@@ -1,8 +1,78 @@
+from urllib.parse import urlparse, urljoin%0Afrom flask import request%0A%0A
 def get_
@@ -367,8 +367,258 @@
 ce, True
+%0A%0Adef is_safe_url(target):%0A    %22%22%22 Checks if an URL is safe. %22%22%22%0A    ref_url = urlparse(request.host_url)%0A    test_url = urlparse(urljoin(request.host_url, target))%0A    return test_url.scheme in (%22http%22, %22https%22) and ref_url.netloc == test_url.netloc

Add utility function for checking URL safety