Commits

Artur Barseghyan committed e7ecbb8 Draft

version bump

  • Participants
  • Parent commits 3aa4fdd
  • Tags 0.3

Comments (0)

Files changed (10)

+recursive-include  src/tld/res *
 except:
     readme = ''
 
-version = '0.2'
+version = '0.3'
+
+data_dir = "src/tld/res"
+data = [os.path.join(data_dir, f) for f in os.listdir(data_dir)]
 
 setup(
-    name='tld',
-    version=version,
-    description=("Extracts the top level domain (TLD) from the URL given."),
-    long_description=readme,
-    classifiers=[
+    name = 'tld',
+    version = version,
+    description = ("Extracts the top level domain (TLD) from the URL given."),
+    long_description = readme,
+    classifiers = [
         "Programming Language :: Python",
         "Environment :: Web Environment",
         'Intended Audience :: Developers',
         'Operating System :: OS Independent',
     ],
-    keywords='tld, top level domain names, python',
-    author='Artur Barseghyan',
-    author_email='artur.barseghyan@gmail.com',
-    url='https://bitbucket.org/barseghyanartur/tld',
-    package_dir={'':'src'},
-    packages=find_packages(where='./src'),
-    license='GPL 2.0/LGPL 2.1',
-    #download_url='https://bitbucket.org/barseghyanartur/tld/get/%s.tar.gz' % version
+    keywords = 'tld, top level domain names, python',
+    author = 'Artur Barseghyan',
+    author_email = 'artur.barseghyan@gmail.com',
+    url = 'https://bitbucket.org/barseghyanartur/tld',
+    package_dir = {'':'src'},
+    packages = find_packages(where='./src'),
+    package_data = {'tld': data},
+    include_package_data = True,
+    license = 'GPL 2.0/LGPL 2.1',
 )

File src/tld/__init__.py

-#!/usr/bin/env python
+__title__ = 'tld'
+__version__ = '0.2'
+__build__ = 0x000002
+__author__ = 'Artur Barseghyan'
+__all__ = ('get_tld',)
 
-from tld.utils import get_tld
+from tld.utils import get_tld

File src/tld/conf.py

-#!/usr/bin/env python
+__title__ = 'tld.conf'
+__version__ = '0.2'
+__build__ = 0x000002
+__author__ = 'Artur Barseghyan'
+__all__ = ('get_setting', 'settings',)
 
-# @package Tld
-# @author Artur Barseghyan (artur.barseghyan@gmail.com)
-# @version 0.1
-# @license MPL 1.1/GPL 2.0/LGPL 2.1
-# @link http://bitbucket.org/barseghyanartur/php-tld
-#
-# Tld conf
+class Settings(object):
+    def __init__(self):
+        self._settings = {
+            # Source path of Mozilla's effective TLD names file.
+            'NAMES_SOURCE_URL': 'http://mxr.mozilla.org/mozilla/source/netwerk/dns/src/effective_tld_names.dat?raw=1',
 
-from django.conf import settings
+            # Relative path to store the local copy of Mozilla's effective TLD names file.
+            'NAMES_LOCAL_PATH': 'res/effective_tld_names.dat.txt',
 
-from tld import defaults
+            # Debug flag.
+            'DEBUG': False
+        }
 
-def get_setting(setting, override=None):
-    """
-    Get a setting from tlds conf module, falling back to the default. If override is not None, it will be used instead
-    of the setting.
-    """
-    if override is not None:
-        return override
-    if hasattr(settings, 'TLD_%s' % setting):
-        return getattr(settings, 'TLD_%s' % setting)
-    else:
-        return getattr(defaults, setting)
+    def set(name, value):
+        self._settings[name] = value
+
+    def get(self, name, default=None):
+        if self._settings.has_key(name):
+            return self._settings[name]
+        else:
+            return default
+
+settings = Settings()
+
+get_setting = settings.get

File src/tld/defaults.py

-#!/usr/bin/env python
-
-# @package Tld
-# @author Artur Barseghyan (artur.barseghyan@gmail.com)
-# @version 0.1
-# @license MPL 1.1/GPL 2.0/LGPL 2.1
-# @link http://bitbucket.org/barseghyanartur/tld
-#
-# Tld defaults
-
-# Source path of Mozilla's effective TLD names file.
-NAMES_SOURCE_URL = 'http://mxr.mozilla.org/mozilla/source/netwerk/dns/src/effective_tld_names.dat?raw=1'
-
-# Relative path to store the local copy of Mozilla's effective TLD names file.
-NAMES_LOCAL_PATH = 'res/effective_tld_names.dat.txt'
-
-# Debug flag.
-DEBUG = False

File src/tld/exceptions.py

-#!/usr/bin/env python
+__title__ = 'tld.exceptions'
+__version__ = '0.2'
+__build__ = 0x000002
+__author__ = 'Artur Barseghyan'
+__all__ = ('TldIOError', 'TldDomainNotFound', 'TldBadUrl')
 
-# @package Tld
-# @author Artur Barseghyan (artur.barseghyan@gmail.com)
-# @version 0.1
-# @license MPL 1.1/GPL 2.0/LGPL 2.1
-# @link http://bitbucket.org/barseghyanartur/php-tld
-#
-# Tld package exceptions.
-
-from tld.conf import get_setting
-
-TLD_NAMES_LOCAL_PATH = get_setting('NAMES_LOCAL_PATH')
+from tld.settings import NAMES_LOCAL_PATH as TLD_NAMES_LOCAL_PATH
 
 _ = lambda x: x
 
     def __init__(self, msg=None):
         if msg is None:
             msg = _("Can't read from or write to the %s file!") % TLD_NAMES_LOCAL_PATH
-        super(get_tld, self).__init__(msg)
+        super(TldIOError, self).__init__(msg)
 
 class TldDomainNotFound(ValueError):
     """

File src/tld/settings.py

+__title__ = 'tld.settings'
+__version__ = '0.2'
+__build__ = 0x000002
+__author__ = 'Artur Barseghyan'
+__all__ = ('NAMES_SOURCE_URL', 'NAMES_LOCAL_PATH', 'DEBUG')
+
+from tld.conf import get_setting
+
+NAMES_SOURCE_URL = get_setting('NAMES_SOURCE_URL')
+
+NAMES_LOCAL_PATH = get_setting('NAMES_LOCAL_PATH')
+
+DEBUG = get_setting('DEBUG')

File src/tld/tests.py

-#!/usr/bin/env python
-
-# @package Tld
-# @author Artur Barseghyan (artur.barseghyan@gmail.com)
-# @version 0.1
-# @license MPL 1.1/GPL 2.0/LGPL 2.1
-# @link http://bitbucket.org/barseghyanartur/php-tld
-#
-# Tld tests/examples
+__title__ = 'tld.tests'
+__version__ = '0.2'
+__build__ = 0x000002
+__author__ = 'Artur Barseghyan'
 
 from tld.utils import get_tld
 

File src/tld/update.py

-#!/usr/bin/env python
-
-# @package Tld
-# @author Artur Barseghyan (artur.barseghyan@gmail.com)
-# @version 0.1
-# @license MPL 1.1/GPL 2.0/LGPL 2.1
-# @link http://bitbucket.org/barseghyanartur/php-tld
-#
-# Commands for updating the TLD names file from command line.
+__title__ = 'tld.update'
+__version__ = '0.2'
+__build__ = 0x000002
+__author__ = 'Artur Barseghyan'
 
 from tld.utils import update_tld_names
 

File src/tld/utils.py

-#!/usr/bin/env python
-
-# @package Tld
-# @author Artur Barseghyan (artur.barseghyan@gmail.com)
-# @version 0.1
-# @license MPL 1.1/GPL 2.0/LGPL 2.1
-# @link http://bitbucket.org/barseghyanartur/php-tld
-#
-# Extracts the top level domain (TLD) from the URL given. List of TLD names is taken from
-# http://mxr.mozilla.org/mozilla/source/netwerk/dns/src/effective_tld_names.dat?raw=1
+__title__ = 'tld.utils'
+__version__ = '0.2'
+__build__ = 0x000002
+__author__ = 'Artur Barseghyan'
+__all__ = ('update_tld_names', 'get_tld')
 
 from urlparse import urlparse
 import urllib2
 import os
 
-from tld.conf import get_setting
+from tld.settings import NAMES_SOURCE_URL as TLD_NAMES_SOURCE_URL, NAMES_LOCAL_PATH as TLD_NAMES_LOCAL_PATH, DEBUG
 from tld.exceptions import TldIOError, TldDomainNotFound, TldBadUrl
 
 PROJECT_DIR = lambda base : os.path.abspath(os.path.join(os.path.dirname(__file__), base).replace('\\','/'))
 
 _ = lambda x: x
 
-TLD_NAMES_SOURCE_URL = get_setting('NAMES_SOURCE_URL')
-TLD_NAMES_LOCAL_PATH = get_setting('NAMES_LOCAL_PATH')
-DEBUG = get_setting('DEBUG')
-
 tld_names = []
 
 def update_tld_names():