# Path: tiddlywebplugins/tiddlyspace/spaces.py
# def space_uri(environ, space_name):
#     """
#     Determine the uri of a space based on its name.
#     """
#     host = environ['tiddlyweb.config']['server_host']['host']
#     port = environ['tiddlyweb.config']['server_host']['port']
#     scheme = environ['tiddlyweb.config']['server_host']['scheme']
#     if not _alien_domain(environ, space_name):
#         if port is not '443' and port is not '80':
#             uri = '%s://%s.%s:%s/' % (scheme,
#                     urllib.quote(space_name.encode('utf-8')),
#                     host, port)
#         else:
#             uri = '%s://%s.%s/' % (scheme,
#                     urllib.quote(space_name.encode('utf-8')),
#                     host)
#     else:
#         if space_name == 'frontpage':
#             if port is not '443' and port is not '80':
#                 uri = '%s://%s:%s/' % (scheme, host, port)
#             else:
#                 uri = '%s://%s/' % (scheme, host)
#         else:
#             uri = '%s://%s/' % (scheme, space_name)
#     return uri


from tiddlywebplugins.tiddlyspace.spaces import space_uri
Test that space_uri generates the correct URI for a space.
This _does_not_ check for a correct space when an alien_domain
is involved, because we don't have support for that yet.
"""



def testspace_uri():
    environ = {}
    environ['tiddlyweb.config'] = {}
    environ['tiddlyweb.config']['server_host'] = {
            'host': 'example.com',
            'scheme': 'http',
            'port': '8080',
            }

    server_host = environ['tiddlyweb.config']['server_host']

    space_name = 'howdy'

    assert space_uri(environ, space_name) == 'http://howdy.example.com:8080/'

    server_host['port'] = '80'
    assert space_uri(environ, space_name) == 'http://howdy.example.com/'

    server_host['port'] = '443'
    server_host['scheme'] = 'https'
    assert space_uri(environ, space_name) == 'https://howdy.example.com/'

    server_host['port'] = '9443'

# Path: tiddlywebplugins/tiddlyspace/spaces.py
# def space_uri(environ, space_name):
#     """
#     Determine the uri of a space based on its name.
#     """
#     host = environ['tiddlyweb.config']['server_host']['host']
#     port = environ['tiddlyweb.config']['server_host']['port']
#     scheme = environ['tiddlyweb.config']['server_host']['scheme']
#     if not _alien_domain(environ, space_name):
#         if port is not '443' and port is not '80':
#             uri = '%s://%s.%s:%s/' % (scheme,
#                     urllib.quote(space_name.encode('utf-8')),
#                     host, port)
#         else:
#             uri = '%s://%s.%s/' % (scheme,
#                     urllib.quote(space_name.encode('utf-8')),
#                     host)
#     else:
#         if space_name == 'frontpage':
#             if port is not '443' and port is not '80':
#                 uri = '%s://%s:%s/' % (scheme, host, port)
#             else:
#                 uri = '%s://%s/' % (scheme, host)
#         else:
#             uri = '%s://%s/' % (scheme, space_name)
#     return uri


# Path: test/test_space_uri.py
from tiddlywebplugins.tiddlyspace.spaces import space_uri

Test that space_uri generates the correct URI for a space.
This _does_not_ check for a correct space when an alien_domain
is involved, because we don't have support for that yet.
"""



def testspace_uri():
    environ = {}
    environ['tiddlyweb.config'] = {}
    environ['tiddlyweb.config']['server_host'] = {
            'host': 'example.com',
            'scheme': 'http',
            'port': '8080',
            }

    server_host = environ['tiddlyweb.config']['server_host']

    space_name = 'howdy'

    assert space_uri(environ, space_name) == 'http://howdy.example.com:8080/'

    server_host['port'] = '80'
    assert space_uri(environ, space_name) == 'http://howdy.example.com/'

    server_host['port'] = '443'
    server_host['scheme'] = 'https'
    assert space_uri(environ, space_name) == 'https://howdy.example.com/'

    server_host['port'] = '9443'

    assert space_uri(environ, space_name) == 'https://howdy.example.com:9443/'