human
Complete the below
def check_csrf_origin(request, trusted_origins=None, raises=True):

    ''''Check the ``Origin`` of the request to see if it is a cross site request or
    not.
    If the value supplied by the ``Origin`` or ``Referer`` header isn\'t one of the
    trusted origins and ``raises`` is ``True``, this function will raise a
    :exc:`pyramid.exceptions.BadCSRFOrigin` exception, but if ``raises`` is
    ``False``, this function will return ``False`` instead. If the CSRF origin
    checks are successful this function will return ``True`` unconditionally.
    Additional trusted origins may be added by passing a list of domain (and
    ports if non-standard like ``[\'example.com\', \'dev.example.com:8080\']``) in
    with the ``trusted_origins`` parameter. If ``trusted_origins`` is ``None``
    (the default) this list of additional domains will be pulled from the
    ``pyramid.csrf_trusted_origins`` setting.
    Note that this function will do nothing if ``request.scheme`` is not
    ``https``.
    .. versionadded:: 1.7
    .. versionchanged:: 1.9
    Moved from :mod:`pyramid.session` to :mod:`pyramid.csrf`'
    '''

=====
Give me a the Python program you requested?
assistant
#Here is the Python program you requested.
    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