Commits

Artur Barseghyan committed 5c7463e Draft

version up

  • Participants
  • Parent commits c9cf640
  • Tags 0.7

Comments (0)

Files changed (6)

File CHANGELOG.rst

 Release history
 =====================================
+0.7
+-------------------------------------
+2014-08-14
+
+- Making it possible to obtain object instead of just extracting the TLD by
+  setting the ``as_object`` argument of ``get_tld`` function to True.
+
 0.6.4
 -------------------------------------
 2014-05-21
 
     from tld import get_tld
     print get_tld("http://www.google.co.uk")
-    'google.co.uk'
+    # 'google.co.uk'
+
     print get_tld("http://www.google.idontexist", fail_silently=True)
-    None
+    # None
+
+If you wish, you could get the result as an object:
+
+.. code-block:: python
+
+    from tld import get_tld
+    res = get_tld("http://some.subdomain.google.co.uk", as_object=True)
+    print res
+    # 'google.co.uk'
+
+    print res.subdomain
+    # 'some.subdomain'
+
+    print res.domain
+    # 'google'
+
+    print res.suffix
+    # 'co.uk'
+
+    print res.tld
+    # 'google.co.uk'
 
 To update/sync the tld names with the most recent version run the following from your terminal:
 

File docs/index.rst

 tld
 ===================================
 
-Description
-===================================
 Extracts the top level domain (TLD) from the URL given. List of TLD names is taken from
 Mozilla http://mxr.mozilla.org/mozilla/source/netwerk/dns/src/effective_tld_names.dat?raw=1
 
 ===================================
 Latest stable version on PyPI:
 
+.. code-block:: none
+
     $ pip install tld
 
 Latest development version:
 
+.. code-block:: none
+
     $ pip install -e hg+http://bitbucket.org/barseghyanartur/tld#egg=tld
 
 Usage example
 ===================================
 To get the top level domain name from the URL given:
 
-    >>> from tld import get_tld
-    >>> print get_tld("http://www.google.co.uk")
-    'google.co.uk'
-    >>> print get_tld("http://www.google.idontexist", fail_silently=True)
-    None
+.. code-block:: python
+
+    from tld import get_tld
+    print get_tld("http://www.google.co.uk")
+    # 'google.co.uk'
+
+    print get_tld("http://www.google.idontexist", fail_silently=True)
+    # None
+
+If you wish, you could get the result as an object:
+
+.. code-block:: python
+
+    from tld import get_tld
+    res = get_tld("http://some.subdomain.google.co.uk", as_object=True)
+    print res
+    # 'google.co.uk'
+
+    print res.subdomain
+    # 'some.subdomain'
+
+    print res.domain
+    # 'google'
+
+    print res.suffix
+    # 'co.uk'
+
+    print res.tld
+    # 'google.co.uk'
 
 To update/sync the tld names with the most recent version run the following from your terminal:
 
+.. code-block:: none
+
     $ python tld/update.py
 
-    or simply do:
+or simply do:
 
-    >>> from tld.utils import update_tld_names
-    >>> update_tld_names()
+.. code-block:: python
+
+    from tld.utils import update_tld_names
+    update_tld_names()
 
 License
 ===================================
 except:
     readme = ''
 
-version = '0.6.4'
+version = '0.7'
 
 data_dir = "src/tld/res"
 data = [os.path.join(data_dir, f) for f in os.listdir(data_dir)]

File src/tld/__init__.py

 __title__ = 'tld'
-__version__ = '0.6.4'
-__build__ = 0x000009
+__version__ = '0.7'
+__build__ = 0x00000A
 __author__ = 'Artur Barseghyan'
 __copyright__ = 'Copyright (c) 2013 Artur Barseghyan'
 __license__ = 'GPL 2.0/LGPL 2.1'

File src/tld/utils.py

 __title__ = 'tld.utils'
 __author__ = 'Artur Barseghyan'
-__copyright__ = 'Copyright (c) 2013 Artur Barseghyan'
+__copyright__ = 'Copyright (c) 2013-2014 Artur Barseghyan'
 __license__ = 'GPL 2.0/LGPL 2.1'
 __all__ = ('update_tld_names', 'get_tld', 'Result')
 
     """
     Container.
     """
-    __slots__ = ('subdomain', 'domain', 'suffix')
+    __slots__ = ('subdomain', 'domain', 'suffix', '__tld')
 
     def __init__(self, subdomain, domain, suffix):
         self.subdomain = subdomain
         self.domain = domain
         self.suffix = suffix
+        self.__tld = "{0}.{1}".format(self.domain, self.suffix)
 
     @property
     def tld(self):
-        return "{0}.{1}".format(self.domain, self.suffix)
+        return self.__tld
 
     def __str__(self):
-        return self.tld
+        return self.__tld
     __unicode__ = __str__
     __repr__ = __str__
 
     :param url: URL to get top level domain from.
     :param active_only: If set to True, only active patterns are matched.
     :param fail_silently: If set to True, no exceptions are raised and None is returned on failure.
-    :return: String with top level domain or None on failure.
+    :param as_object: If set to True, ``tld.utils.Result`` object is returned, which contains ``subdomain``,
+        ``domain``, ``suffix`` and ``tld`` properties.
+    :return mixed: String with top level domain (if ``as_object`` argument is set to False), a ``tld.utils.Result``
+        object or None on failure.
     """
     TLD_NAMES_LOCAL_PATH = get_setting('NAMES_LOCAL_PATH')