From bdced3edbc8d062ba5f0318ff195dbd9af2f1990 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Fri, 24 Jun 2011 01:47:04 +0200 Subject: add some first versions of setup / code (untested) --- xstatic/__init__.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 xstatic/__init__.py (limited to 'xstatic') diff --git a/xstatic/__init__.py b/xstatic/__init__.py new file mode 100644 index 0000000..1c362fa --- /dev/null +++ b/xstatic/__init__.py @@ -0,0 +1,47 @@ +# 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 + -- cgit v1.2.1