given a string file name returns a geosgeometry the file may contain wkb wkt or hex if given a file name get a real handle if we get wkb need to wrap in memoryview so run through regexes given a string file name returns a geosgeometry the file may contain wkb wkt or hex if given a file name get a real handle if we get wkb need to wrap in memoryview so run through regexes
from django.contrib.gis.geos.geometry import GEOSGeometry, hex_regex, wkt_regex


def fromfile(file_h):
    
    
    if isinstance(file_h, str):
        with open(file_h, "rb") as file_h:
            buf = file_h.read()
    else:
        buf = file_h.read()

    
    if isinstance(buf, bytes):
        try:
            decoded = buf.decode()
        except UnicodeDecodeError:
            pass
        else:
            if wkt_regex.match(decoded) or hex_regex.match(decoded):
                return GEOSGeometry(decoded)
    else:
        return GEOSGeometry(buf)

    return GEOSGeometry(memoryview(buf))


def fromstr(string, **kwargs):
    "Given a string value, return a GEOSGeometry object."
    return GEOSGeometry(string, **kwargs)