# Path: django_toolkit/url/shorten.py
# def shorten_url(url, length=32, strip_www=True, strip_path=True, ellipsis=False):
#     """
#     Shorten a URL by chopping out the middle.
# 
#     For example if supplied with http://subdomain.example.com.au and length 16
#     the following would be returned.
# 
#     sub...le.com.au
#     """
#     if '://' not in url:
#         # Ensure we have a protocol
#         url = 'http://%s' % url
# 
#     parsed_url = urlparse(url)
#     ext = tldextract.extract(parsed_url.netloc)
#     if ext.subdomain and (not strip_www or (strip_www and ext.subdomain != 'www')):
#         shortened = u'%s.%s' % (ext.subdomain, ext.domain)
#     else:
#         shortened = u'%s' % ext.domain
# 
#     if ext.tld:
#         shortened = u'%s.%s' % (shortened, ext.tld)
# 
#     if not strip_path:
#         if parsed_url.path:
#             shortened += parsed_url.path
# 
#     if len(shortened) <= length:
#         return shortened
#     else:
#         domain = shortened
#         i = length + 1 - 3
#         left = right = int(i/2)
#         if not i % 2:
#             right -= 1
#         if ellipsis:
#             shortened = u"%s\u2026%s" % (domain[:left], domain[-right:])
#         else:
#             shortened = '%s...%s' % (domain[:left], domain[-right:])
# 
#         return shortened
# 
# def netloc_no_www(url):
#     """
#     For a given URL return the netloc with any www. striped.
#     """
#     ext = tldextract.extract(url)
#     if ext.subdomain and ext.subdomain != 'www':
#         return '%s.%s.%s' % (ext.subdomain, ext.domain, ext.tld) 
#     else:
#         return '%s.%s' % (ext.domain, ext.tld)


from django.utils import unittest
from django_toolkit.url.shorten import shorten_url, netloc_no_www
        self.assertEquals(self.shorten_url('www.example.com.au/au/page/n/', 16, strip_www=False, strip_path=False, ellipsis=True), u'www.exa\u2026age/n/')
        self.assertEquals(self.shorten_url('http://www.example.com.au/au/page/n/', 32, strip_www=False, strip_path=False, ellipsis=True), u'www.example.com.au/au/page/n/')
        self.assertEquals(self.shorten_url('http://www.example.com.au/au/page/n/', 24, strip_www=False, strip_path=False, ellipsis=True), u'www.example\u2026au/page/n/')


class NetlocNoWwwTestCase(unittest.TestCase):

    @property
    def netloc_no_www(self):
        """
        Allow alternative method to be used so we can use the same tests for the templatetags.

        :return: netloc_no_www
        """
        return netloc_no_www

    def test_netloc_no_www(self):
        self.assertEqual(
            self.netloc_no_www('http://example.com'),
            'example.com'
        )
        self.assertEqual(
            self.netloc_no_www('http://www.example.com'),
            'example.com'
        )
        self.assertEqual(
            self.netloc_no_www('http://www.example.com/asdf'),
            'example.com'
        )
        self.assertEqual(

# Path: django_toolkit/url/shorten.py
# def shorten_url(url, length=32, strip_www=True, strip_path=True, ellipsis=False):
#     """
#     Shorten a URL by chopping out the middle.
# 
#     For example if supplied with http://subdomain.example.com.au and length 16
#     the following would be returned.
# 
#     sub...le.com.au
#     """
#     if '://' not in url:
#         # Ensure we have a protocol
#         url = 'http://%s' % url
# 
#     parsed_url = urlparse(url)
#     ext = tldextract.extract(parsed_url.netloc)
#     if ext.subdomain and (not strip_www or (strip_www and ext.subdomain != 'www')):
#         shortened = u'%s.%s' % (ext.subdomain, ext.domain)
#     else:
#         shortened = u'%s' % ext.domain
# 
#     if ext.tld:
#         shortened = u'%s.%s' % (shortened, ext.tld)
# 
#     if not strip_path:
#         if parsed_url.path:
#             shortened += parsed_url.path
# 
#     if len(shortened) <= length:
#         return shortened
#     else:
#         domain = shortened
#         i = length + 1 - 3
#         left = right = int(i/2)
#         if not i % 2:
#             right -= 1
#         if ellipsis:
#             shortened = u"%s\u2026%s" % (domain[:left], domain[-right:])
#         else:
#             shortened = '%s...%s' % (domain[:left], domain[-right:])
# 
#         return shortened
# 
# def netloc_no_www(url):
#     """
#     For a given URL return the netloc with any www. striped.
#     """
#     ext = tldextract.extract(url)
#     if ext.subdomain and ext.subdomain != 'www':
#         return '%s.%s.%s' % (ext.subdomain, ext.domain, ext.tld) 
#     else:
#         return '%s.%s' % (ext.domain, ext.tld)


# Path: django_toolkit/tests/url/shorten.py
from django.utils import unittest
from django_toolkit.url.shorten import shorten_url, netloc_no_www

        self.assertEquals(self.shorten_url('www.example.com.au/au/page/n/', 16, strip_www=False, strip_path=False, ellipsis=True), u'www.exa\u2026age/n/')
        self.assertEquals(self.shorten_url('http://www.example.com.au/au/page/n/', 32, strip_www=False, strip_path=False, ellipsis=True), u'www.example.com.au/au/page/n/')
        self.assertEquals(self.shorten_url('http://www.example.com.au/au/page/n/', 24, strip_www=False, strip_path=False, ellipsis=True), u'www.example\u2026au/page/n/')


class NetlocNoWwwTestCase(unittest.TestCase):

    @property
    def netloc_no_www(self):
        """
        Allow alternative method to be used so we can use the same tests for the templatetags.

        :return: netloc_no_www
        """
        return netloc_no_www

    def test_netloc_no_www(self):
        self.assertEqual(
            self.netloc_no_www('http://example.com'),
            'example.com'
        )
        self.assertEqual(
            self.netloc_no_www('http://www.example.com'),
            'example.com'
        )
        self.assertEqual(
            self.netloc_no_www('http://www.example.com/asdf'),
            'example.com'
        )
        self.assertEqual(

            self.netloc_no_www('http://wwwjd.example.com/asdf'),