def get_minified(filename, filetype): # make the full url of the resource url = build_url(filename, filetype) # check if we have in memcache minified = memcache.get(url) if not minified: # not in memcache, so get the original result = urlfetch.fetch(url) if result.status_code == 200: # successful request, now choose which minifier to use if filetype == "css": minifiedstr = css.minify(result.content) elif filetype == "js": minifiedstr = js.minify(result.content) # and store a dict of the minified string, filetype and the etag of the original file minified = { "content":minifiedstr, "type":filetype, "etag":result.headers["etag"].replace("\"", "") } # then cache the dictionary in memcache for 60 minutes memcache.add(url, minified, 3600) # return the status code we got from urlfetch status_code = result.status_code else: # this is the file from the cache so the status code is always 200 status_code = 200 return minified, status_code
def loads(source): try: minified = minify(source) return json.loads(minified) except json.JSONDecodeError, e: s = minified.split('\n') context = s[e.lineno-1][max(0, e.colno-1):e.colno+30] msg = e.msg + ' at ' + context raise json.JSONDecodeError(msg, minified, e.pos)