tav (owner)

Revisions

gist: 227204 Download_button fork
public
Public Clone URL: git://gist.github.com/227204.git
Embed All Files: show embed
static.py #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
if DEBUG:
 
    STATIC_HOST = SITE_HTTP_URL
 
    def STATIC(path, minifiable=False, secure=False):
        return '/.static/%s?%s' % (path, time())
 
else:
 
    if STATIC_HOSTS is None:
        STATIC_HOST = 'http://static1.%s' % SITE_DOMAIN
        STATIC_HOSTS = [
            'http://static1.%s' % SITE_DOMAIN,
            'http://static2.%s' % SITE_DOMAIN,
            'http://static3.%s' % SITE_DOMAIN
            ]
    else:
        STATIC_HOST = STATIC_HOSTS[0]
 
    def STATIC(path, minifiable=False, secure=False, cache={}, len_hosts=len(STATIC_HOSTS)):
        if STATIC.ctx and STATIC.ctx.ssl_mode:
            secure = True
        if (path, minifiable, secure) in cache:
            return cache[(path, minifiable, secure)]
        if minifiable:
            path, filename = split_path(path)
            if (not path) or (path == '/'):
                path = '%smin.%s' % (path, filename)
            else:
                path = '%s/min.%s' % (path, filename)
        if secure:
            return cache.setdefault((path, minifiable, secure), "%s%s%s?%s" % (
                SITE_HTTPS_URL, STATIC_PATH, path, APPLICATION_TIMESTAMP
                ))
        return cache.setdefault((path, minifiable, secure), "%s%s%s?%s" % (
            STATIC_HOSTS[int('0x' + sha1(path).hexdigest(), 16) % len_hosts],
            STATIC_PATH, path, APPLICATION_TIMESTAMP
            ))
 
    STATIC.ctx = None