def handle(request): path = request.path[1:] if path == "favicon.ico" or path.endswith(".png"): return serve(request, path) if path.startswith("static"): return serve(request, request.path[len("/static/"):]) if path.startswith("theme"): return serve(request, request.path[len("/theme/"):]) if path == "" or path.endswith("/"): path = path + "index.html" if os.path.exists(dotslash(path)) and os.path.isfile(dotslash(path)): return path ajax = read_yaml_file(dotslash("ajax.yaml")) if ajax: if request.GET: path = request.path + "?" + request.META["QUERY_STRING"] # TODO: make it immune to order of GET params if path in ajax: return JSONResponse(ajax[path]) if request.path in ajax: return JSONResponse(ajax[request.path]) if not request.path.endswith("/"): return d.HttpResponseRedirect(request.path + "/") raise d.Http404("File not found.")
def process_response(self, request, response): if response is d.Http404: return response path = request.path[1:] if path == "favicon.ico" or path.endswith(".png"): return serve(request, path) if path.startswith("theme"): return serve(request, request.path[len("/theme/"):]) if path == "" or path.endswith("/"): path = path + "index.html" if os.path.exists(dotslash(path)) and os.path.isfile(dotslash(path)): return d.render_to_response( path, {}, d.RequestContext(request) ) ajax = read_yaml_file(dotslash("ajax.yaml")) if ajax: if request.GET: path = request.path + "?" + request.META["QUERY_STRING"] # TODO: make it immune to order of GET params if path in ajax: return JSONResponse(ajax[path]) if request.path in ajax: return JSONResponse(ajax[request.path]) if not request.path.endswith("/"): return d.HttpResponseRedirect(request.path + "/") return response
def process_response(self, request, response): if response is d.Http404: return response path = request.path[1:] if path == "favicon.ico" or path.endswith(".png"): return serve(request, path) if path.startswith("theme"): return serve(request, request.path[len("/theme/"):]) if path == "" or path.endswith("/"): path = path + "index.html" if os.path.exists(dotslash(path)) and os.path.isfile(dotslash(path)): return d.render_to_response(path, {}, d.RequestContext(request)) ajax = read_yaml_file(dotslash("ajax.yaml")) if ajax: if request.GET: path = request.path + "?" + request.META["QUERY_STRING"] # TODO: make it immune to order of GET params if path in ajax: return JSONResponse(ajax[path]) if request.path in ajax: return JSONResponse(ajax[request.path]) if not request.path.endswith("/"): return d.HttpResponseRedirect(request.path + "/") return response
def get_gs_file_list(path): if not path.startswith('gs://'): path = edxbigquery_config.GS_BUCKET + path print "Getting file list from %s" % path fnset = OrderedDict() for dat in os.popen('gsutil ls -l ' + path).readlines(): if dat.strip().startswith('TOTAL'): continue try: x = dat.strip().split() if len(x) == 1: continue (size, date, name) = x except Exception as err: print "oops, err=%s, dat=%s" % (str(err), dat) raise date = dateutil.parser.parse(date) size = int(size) fnb = os.path.basename(name) fnset[fnb] = { 'size': size, 'date': date, 'name': name, 'basename': fnb } return fnset
def concat_urls(url, path): url_begin, url_host = parse_url(url) if path.startswith('/'): return url_host + path else: if not url_begin.endswith('/'): url_begin = url_begin + '/' return url_begin + path
def invalid_path(self,path): """Check if the path is invalid for example the case of an absolute path, if it contains "..", etc...""" # if path is not a string, convert it: if not isinstance(path, str): path = str(path) # is the absolute path under Windows with a letterdrive ? if len(path) >= 2 and path[0].isalpha() and path[1] == ":": return True # is it an absolute path starting "/" or "\" ? if path.startswith("/") or path.startswith("\\"): return True # does it contain ".." ? if ".." in path: return True if "*" in path: #print len(RxQueue) #print len(packet) return True if "?" in path: return True # TODO: check if unicode is ok ?? # otherwise path is ok : return False
def get_gs_file_list(path): if not path.startswith('gs://'): path = edxbigquery_config.GS_BUCKET + path print "Getting file list from %s" % path fnset = OrderedDict() for dat in os.popen('gsutil ls -l ' + path).readlines(): if dat.strip().startswith('TOTAL'): continue try: x = dat.strip().split() if len(x)==1: continue (size, date, name) = x except Exception as err: print "oops, err=%s, dat=%s" % (str(err), dat) raise date = dateutil.parser.parse(date) size = int(size) fnb = os.path.basename(name) fnset[fnb] = {'size': size, 'date': date, 'name': name, 'basename': fnb} return fnset
def url(self, path): assert path.startswith('/') return 'http://%s%s' % (self.host, path)
def profile_for_path(path): if not path.startswith("unison:"): return None return path.split(":")[1]