예제 #1
0
def _genUrl ( path, query = {}, need_full = 0, noescape=None ):
    """
    Generate the URL given a URI. If need_full is 1, the generated URL 
    will contain the server part.
    """

    if noescape is None:
	path = urllib.quote(path)

    if query:
        path = path + skunklib.urlencode ( query )

    if need_full:
        if path[0] != '/':
            raise SkunkRuntimeError, \
                'full url being generated with relative path: %s' % path
        conn=AE.Component.componentStack[0].namespace['CONNECTION']
        if conn.env.get('HTTPS')=='on':
            scheme='https'
        else:
            scheme='http'
        host=conn.requestHeaders.get('Host')
        if not host:
            host=conn.env.get('SERVER_NAME')
            port=conn.env.get("SERVER_PORT")
            if port:
                if (scheme=='http' and not port=='80') or (scheme=='https' and not port=='443'):
                    host='%s:%s' % (host, port)
        url='%s://%s%s' % (scheme, host, path)

    else:
        url = path

    return url
예제 #2
0
def _genUrl(path, query={}, need_full=0, noescape=None):
    """
    Generate the URL given a URI. If need_full is 1, the generated URL 
    will contain the server part.
    """

    if noescape is None:
        path = urllib.quote(path)

    if query:
        path = path + skunklib.urlencode(query)

    # Ok, get the hostname - from config file
    if need_full:
        if path[0] != '/':
            raise SkunkRuntimeError, \
                'full url being generated with relative path: %s' % path

        url = 'http://' + AE.Component.componentStack[0].namespace[
            'CONNECTION'].requestHeaders['Host'] + path
    else:
        url = path

    return url
예제 #3
0
def _genUrl(path, query={}, need_full=0, noescape=None):
    """
    Generate the URL given a URI. If need_full is 1, the generated URL 
    will contain the server part.
    """

    if noescape is None:
        path = urllib.quote(path)

    if query:
        path = path + skunklib.urlencode(query)

    if need_full:
        if path[0] != '/':
            raise SkunkRuntimeError, \
                'full url being generated with relative path: %s' % path
        conn = AE.Component.componentStack[0].namespace['CONNECTION']
        if conn.env.get('HTTPS') == 'on':
            scheme = 'https'
        else:
            scheme = 'http'
        host = conn.requestHeaders.get('Host')
        if not host:
            host = conn.env.get('SERVER_NAME')
            port = conn.env.get("SERVER_PORT")
            if port:
                if (scheme == 'http'
                        and not port == '80') or (scheme == 'https'
                                                  and not port == '443'):
                    host = '%s:%s' % (host, port)
        url = '%s://%s%s' % (scheme, host, path)

    else:
        url = path

    return url
예제 #4
0
def _genUrl ( path, query = {}, need_full = 0, noescape=None ):
    """
    Generate the URL given a URI. If need_full is 1, the generated URL 
    will contain the server part.
    """

    if noescape is None:
	path = urllib.quote(path)

    if query:
        path = path + skunklib.urlencode ( query )

    # Ok, get the hostname - from config file 
    if need_full:
        if path[0] != '/':
            raise SkunkRuntimeError, \
                'full url being generated with relative path: %s' % path

        url = 'http://' + AE.Component.componentStack[0].namespace[
            'CONNECTION'].requestHeaders['Host'] + path
    else:
        url = path

    return url