def problem_init_view(request, problem): problem = get_object_or_404(Problem, code=problem) if not request.user.is_superuser and not problem.is_editable_by( request.user): raise Http404() try: with problem_data_storage.open(os.path.join(problem.code, 'init.yml'), 'rb') as f: data = utf8text(f.read()).rstrip('\n') except IOError: raise Http404() return render( request, 'problem/yaml.html', { 'raw_source': data, 'highlighted_source': highlight_code(data, 'yaml'), 'title': _('Generated init.yml for %s') % problem.name, 'content_title': mark_safe( escape(_('Generated init.yml for %s')) % (format_html('<a href="{1}">{0}</a>', problem.name, reverse('problem_detail', args=[problem.code])))), })
def get(self, request, *args, **kwargs): httpresp = super(UserPerformancePointsAjax, self).get(request, *args, **kwargs) httpresp.render() return JsonResponse({ 'results': utf8text(httpresp.content), 'has_more': self.has_more, })
def parse_proxy_protocol(self, line): words = line.split() if len(words) < 2: raise Disconnect() if words[1] == b'TCP4': if len(words) != 6: raise Disconnect() self.client_address = (utf8text(words[2]), utf8text(words[4])) self.server_address = (utf8text(words[3]), utf8text(words[5])) elif words[1] == b'TCP6': self.client_address = (utf8text(words[2]), utf8text(words[4]), 0, 0) self.server_address = (utf8text(words[3]), utf8text(words[5]), 0, 0) elif words[1] != b'UNKNOWN': raise Disconnect()
def problem_init_view(request, problem): problem = get_object_or_404(Problem, code=problem) if not request.user.is_superuser and not problem.is_editable_by(request.user): raise Http404() try: with problem_data_storage.open(os.path.join(problem.code, 'init.yml'), 'rb') as f: data = utf8text(f.read()).rstrip('\n') except IOError: raise Http404() return render(request, 'problem/yaml.html', { 'raw_source': data, 'highlighted_source': highlight_code(data, 'yaml'), 'title': _('Generated init.yml for %s') % problem.name, 'content_title': mark_safe(escape(_('Generated init.yml for %s')) % ( format_html('<a href="{1}">{0}</a>', problem.name, reverse('problem_detail', args=[problem.code])))) })
def __parse_proxy1(self, data): self.__buffer += data index = self.__buffer.find(b'\r\n') if 0 <= index < 106: proxy = data[:index].split() if len(proxy) < 2: return self.close() if proxy[1] == b'TCP4': if len(proxy) != 6: return self.close() self.client_address = (utf8text(proxy[2]), utf8text(proxy[4])) self.server_address = (utf8text(proxy[3]), utf8text(proxy[5])) elif proxy[1] == b'TCP6': self.client_address = (utf8text(proxy[2]), utf8text(proxy[4]), 0, 0) self.server_address = (utf8text(proxy[3]), utf8text(proxy[5]), 0, 0) elif proxy[1] != b'UNKNOWN': return self.close() self.__type = self.__DATA super(ProxyProtocolMixin, self)._recv_data(data[index+2:]) elif len(self.__buffer) > 107 or index > 105: self.close()
def get_result(self, formula): if self.type == 'tex': return hash = hashlib.sha1(utf8bytes(formula)).hexdigest() formula = utf8text(formula) if self.cache.has_file(hash, 'css'): result = self.query_cache(hash) else: result = self.query_mathoid(formula, hash) if not result: return None result['tex'] = formula result['display'] = formula.startswith(r'\displaystyle') return { 'mml': self.output_mml, 'msp': self.output_msp, 'svg': self.output_svg, 'jax': self.output_jax, 'png': self.output_png, 'raw': lambda x: x, }[self.type](result)