summaryrefslogtreecommitdiff
path: root/xstatic
diff options
context:
space:
mode:
authorThomas Waldmann <tw AT waldmann-edv DOT de>2011-06-26 07:23:14 +0200
committerThomas Waldmann <tw AT waldmann-edv DOT de>2011-06-26 07:23:14 +0200
commit04ef415fd1326d9749ad2d967015a46e6f1bd223 (patch)
tree0b1faf97b59cae918e8289133414dcd162f5e3f0 /xstatic
parent8939a2717b0f061171b5d287fbb2978cd2f43071 (diff)
downloadxstatic-04ef415fd1326d9749ad2d967015a46e6f1bd223.tar.gz
setup.py: make namespace packages work, add missing stuff
add url and namespaces_packages decl use 1-line __init__.py for xstatic and xstatic.pkg namespace packages move most of the code to xstatic.main
Diffstat (limited to 'xstatic')
-rw-r--r--xstatic/__init__.py55
-rw-r--r--xstatic/main.py51
-rw-r--r--xstatic/pkg/__init__.py1
3 files changed, 53 insertions, 54 deletions
diff --git a/xstatic/__init__.py b/xstatic/__init__.py
index d6066d7..de40ea7 100644
--- a/xstatic/__init__.py
+++ b/xstatic/__init__.py
@@ -1,54 +1 @@
-# Copyright: 2011 by the XStatic authors, see AUTHORS.txt for details.
-# License: MIT license, see LICENSE.txt for details.
-
-"""
-XStatic - main package with minimal support code to work with static file packages
-"""
-
-# http://remote_base/path
-# http://local_base/path
-
-class XStatic(object):
- """
- minimal support code to access resources from xstatic.pkg.* files
- or CDN locations.
- """
- name = None # lowercase short name
- base_dir = None # fs path to the files
- locations = {} # CDN/remote locations
-
- def __init__(self, root_url='/xstatic', provider='local', protocol='http'):
- """
- :arg root_url: the common root url path for all local xstatic
- resources
- :arg provider: 'local' to get it from local server or
- a name of another source (e.g. CDN)
- :arg protocol: 'http' (default) or 'https'
- """
- self.provider = provider
- if provider == 'local':
- self.base_url = "%s/%s" % (root_url, self.name)
- else:
- self.base_url = self.locations[(provider, protocol)]
-
- def get_mapping(self):
- """
- query the mapping url -> directory, use this to setup
- your own static file serving.
- """
- if self.provider == 'local':
- return self.base_url, self.base_dir
-
- def url_for(self, path):
- """
- compute the url for some resource.
-
- :arg path: a relative path into the data
- """
- loc = self.base_url
- if isinstance(loc, str):
- loc = "%s/%s" % (loc, path)
- elif isinstance(loc, dict):
- loc = loc[path]
- return loc
-
+__import__('pkg_resources').declare_namespace(__name__)
diff --git a/xstatic/main.py b/xstatic/main.py
new file mode 100644
index 0000000..1ea94bf
--- /dev/null
+++ b/xstatic/main.py
@@ -0,0 +1,51 @@
+# Copyright: 2011 by the XStatic authors, see AUTHORS.txt for details.
+# License: MIT license, see LICENSE.txt for details.
+
+"""
+XStatic - main package with minimal support code to work with static file packages
+"""
+
+class XStatic(object):
+ """
+ minimal support code to access resources from xstatic.pkg.* files
+ or CDN locations.
+ """
+ name = None # lowercase short name
+ base_dir = None # fs path to the files
+ locations = {} # CDN/remote locations
+
+ def __init__(self, root_url='/xstatic', provider='local', protocol='http'):
+ """
+ :arg root_url: the common root url path for all local xstatic
+ resources
+ :arg provider: 'local' to get it from local server or
+ a name of another source (e.g. CDN)
+ :arg protocol: 'http' (default) or 'https'
+ """
+ self.provider = provider
+ if provider == 'local':
+ self.base_url = "%s/%s" % (root_url, self.name)
+ else:
+ self.base_url = self.locations[(provider, protocol)]
+
+ def get_mapping(self):
+ """
+ query the mapping url -> directory, use this to setup
+ your own static file serving.
+ """
+ if self.provider == 'local':
+ return self.base_url, self.base_dir
+
+ def url_for(self, path):
+ """
+ compute the url for some resource.
+
+ :arg path: a relative path into the data
+ """
+ loc = self.base_url
+ if isinstance(loc, str):
+ loc = "%s/%s" % (loc, path)
+ elif isinstance(loc, dict):
+ loc = loc[path]
+ return loc
+
diff --git a/xstatic/pkg/__init__.py b/xstatic/pkg/__init__.py
new file mode 100644
index 0000000..de40ea7
--- /dev/null
+++ b/xstatic/pkg/__init__.py
@@ -0,0 +1 @@
+__import__('pkg_resources').declare_namespace(__name__)