human
I wrote the below code

    def _fail(reason):
        if raises:
            raise BadCSRFOrigin(reason)
        else:
            return False
    if (request.scheme == 'https'):
        origin = request.headers.get('Origin')
        if (origin is None):
            origin = request.referrer
        if (not origin):
            return _fail('Origin    checking    failed    -    no    Origin    or    Referer.')
        originp = urlparse.urlparse(origin)
        if (originp.scheme != 'https'):
            return _fail('Referer    checking    failed    -    Referer    is    insecure    while    host    is    secure.')
        if (trusted_origins is None):
            trusted_origins = aslist(request.registry.settings.get('pyramid.csrf_trusted_origins', []))
        if (request.host_port not in set(['80', '443'])):
            trusted_origins.append('{0.domain}:{0.host_port}'.format(request))
        else:
            trusted_origins.append(request.domain)
        if (not any((is_same_domain(originp.netloc, host) for host in trusted_origins))):
            reason = 'Referer    checking    failed    -    {0}    does    not    match    any    trusted    origins.'
            return _fail(reason.format(origin))
    return True

What's a good function header?
assistant
#Here's a good function header.

def check_csrf_origin(request, trusted_origins=None, raises=True):