def get(self): uagent = UAgentInfo(str(self.request.user_agent), str(self.request.accept)) isMobile = uagent.detectMobileLong() or uagent.detectTierTablet() mainPage = 'mobile.html' if isMobile else 'index.html' if self.request.uri.find("try.dartlang.org") > 0: self.redirect("https://dartpad.dartlang.org") parsedURL = urlparse(self.request.uri) path = parsedURL.path targetSplits = path.split('/') if os.path.isfile(path): _serve(self.response, path) return # If it is a request for a file in the TLD, serve as is. if targetSplits[1].find('.') > 0: newPath = "/".join(targetSplits[1:]) if newPath == '': _serve(self.response, mainPage) else: _serve(self.response, newPath) return # If it is a request for a TLD psuedo-item, serve back the main page if len(targetSplits) < 3: _serve(self.response, mainPage) return # If it is a request for something in the packages folder, serve it if targetSplits[1] == 'packages': newPath = "/".join(targetSplits[1:]) if newPath == '': _serve(self.response, mainPage) else: _serve(self.response, newPath) return # Otherwise it's a request for a item after the gist psudeo path # drop the gist and serve it. if len(targetSplits) >= 3: newPath = "/".join(targetSplits[2:]) if newPath == '': _serve(self.response, mainPage) else: _serve(self.response, newPath) return
def get(self): uagent = UAgentInfo(str(self.request.user_agent), str(self.request.accept)) isMobile = uagent.detectMobileLong() or uagent.detectTierTablet() mainPage = 'mobile.html' if isMobile else 'index.html' if self.request.uri.find("try.dartlang.org") > 0: self.redirect("https://dartpad.dartlang.org") parsedURL = urlparse(self.request.uri) path = parsedURL.path; targetSplits = path.split('/') if os.path.isfile(path): _serve(self.response, path) return # If it is a request for a file in the TLD, serve as is. if targetSplits[1].find('.') > 0: newPath = "/".join(targetSplits[1:]) if newPath == '': _serve(self.response, mainPage) else: _serve(self.response, newPath) return # If it is a request for a TLD psuedo-item, serve back the main page if len(targetSplits) < 3: _serve(self.response, mainPage) return # If it is a request for something in the packages folder, serve it if targetSplits[1] == 'packages': newPath = "/".join(targetSplits[1:]) if newPath == '': _serve(self.response, mainPage) else: _serve(self.response, newPath) return # Otherwise it's a request for a item after the gist psudeo path # drop the gist and serve it. if len(targetSplits) >= 3: newPath = "/".join(targetSplits[2:]) if newPath == '': _serve(self.response, mainPage) else: _serve(self.response, newPath) return
def get(self): user_agent = str(self.request.headers['User-Agent']) http_accept = str(self.request.headers['Accept']) ua_info = UAgentInfo(user_agent, http_accept) capabilities = {} capabilities['Is Smartphone'] = ua_info.detectSmartphone() capabilities['Is iOS'] = ua_info.detectIos() capabilities['Is IPad'] = ua_info.detectIpad() capabilities['Is Android'] = ua_info.detectAndroid() data = {} data['capabilities'] = capabilities data['user_agent'] = user_agent data['http_accept'] = http_accept template = JINJA_ENVIRONMENT.get_template('index.html') self.response.write(template.render(data))