def highlight_code(request): """ hightlight sourcecode for copy&paste """ context = { "title": _("hightlight sourcecode"), "form_url": request.path, } # get the EditableHtmlHeadFile path to pygments.css (page_msg created, if not exists) pygments_css_path = get_pygments_css(request) context["pygments_css"] = pygments_css_path if request.method == "POST": form = HighlightCodeForm(request.POST) if form.is_valid(): sourcecode = form.cleaned_data["sourcecode"] source_type = form.cleaned_data["source_type"] highlighted = make_html(sourcecode, source_type, django_escape=True) context["highlighted"] = highlighted html_code = make_html(highlighted, "html", django_escape=True) context["html_code"] = html_code else: form = HighlightCodeForm() context["form"] = form return context
def show_internals(request): apps_info = [] for app in get_apps(): model_info = [] for model in get_models(app): model_info.append({ "name":model._meta.object_name, }) apps_info.append({ "app_name": app.__name__, "app_models": model_info, }) # from http://www.djangosnippets.org/snippets/1434/ # generate a list of (pattern-name, pattern) tuples resolver = urlresolvers.get_resolver(None) urlpatterns = sorted([ (key, value[0][0][0]) for key, value in resolver.reverse_dict.items() if isinstance(key, basestring) ]) context = { "title": "Show internals", "pid": os.getpid(), "cache_information": LocalSyncCache.get_cache_information(), "permissions": Permission.objects.all(), "urlpatterns": urlpatterns, "settings": hightlighter.make_html( pformat(get_safe_settings()), source_type="py", django_escape=True ), "db_backend_name": backend.Database.__name__, "db_backend_module": backend.Database.__file__, "db_backend_version": getattr(backend.Database, "version", "?"), "apps_info": apps_info, "db_table_names": sorted(connection.introspection.table_names()), "django_tables": sorted(connection.introspection.django_table_names()), "request_meta": hightlighter.make_html( pformat(request.META), source_type="py", django_escape=True ), "request_session": hightlighter.make_html( pformat(dict(request.session)), source_type="py", django_escape=True ), "sys_path": sys.path, "os_environ": os.environ, } return context
def show_internals(request): apps_info = [] for app in get_apps(): model_info = [] for model in get_models(app): model_info.append({ "name":model._meta.object_name, }) apps_info.append({ "app_name": app.__name__, "app_models": model_info, }) # Information about the current used url patterns urlpatterns = UrlPatternInfo().get_url_info() context = { "title": "Show internals", "pid": os.getpid(), "cache_information": LocalSyncCache.get_cache_information(), "permissions": Permission.objects.all(), "urlpatterns": urlpatterns, "settings": hightlighter.make_html( pformat(get_safe_settings()), source_type="py", django_escape=True ), "db_backend_name": backend.Database.__name__, "db_backend_module": backend.Database.__file__, "db_backend_version": getattr(backend.Database, "version", "?"), "apps_info": apps_info, "db_table_names": sorted(connection.introspection.table_names()), "django_tables": sorted(connection.introspection.django_table_names()), "request_meta": hightlighter.make_html( pformat(request.META), source_type="py", django_escape=True ), "request_session": hightlighter.make_html( pformat(dict(request.session)), source_type="py", django_escape=True ), "sys_path": sys.path, "os_environ": os.environ, } return context
def _render(request, content, path_or_url, markup, highlight, strip_html): markup_no = None if markup: if markup not in MARKUPS: return _error(request, "Include error.", "Can't include: Unknown markup %r (Available: %s)" % (markup, ", ".join(MARKUPS.keys())) ) markup_no = MARKUPS[markup] if markup_no: content = apply_markup(content, markup_no, request, escape_django_tags=False) # xxx: escape_django_tags if highlight == True: highlight = "html" if highlight == True: highlight = os.path.splitext(path_or_url)[1] if highlight is not None: content = make_html(content, highlight) if not (markup_no or highlight): if strip_html: content = strip_tags(content) content = escape(content) return content
def get_content_preview(self): content = self._get_fs_content() if not content: # Can't read the template content, page_msg was created. return ext = os.path.splitext(self.fs_path)[1] html = make_html(content, ext, django_escape=True) return html
def get_content_preview(self): content = self._get_fs_content() if not content: # Can't read the template content, page_msg was created. return ext = os.path.splitext(self.fs_path)[1] html = make_html(content, ext, django_escape=True) return html
def code(ext, text): """ Highlight sourcecode using Macro tag <<code ext=.EXT>>...<</code>> """ try: source_type = ext.rsplit("=", 1)[-1] except (ValueError, IndexError): source_type = "" source_html = make_html(sourcecode=text, source_type=source_type, django_escape=True) return source_html
def hightlight(self, source_type, code_lines): """ Display Sourcecode. Try to use pygments, if exists. """ # self.page_msg("Source type: '%s'" % source_type) code = "".join(code_lines) code = code.strip() from pylucid_project.apps.pylucid.markup.hightlighter import make_html html = make_html(code, source_type, django_escape=True) self.out.write(html)
def hightlight(self, source_type, code_lines): """ Display Sourcecode. Try to use pygments, if exists. """ # self.page_msg("Source type: '%s'" % source_type) code = "".join(code_lines) code = code.strip() from pylucid_project.apps.pylucid.markup.hightlighter import make_html html = make_html(code, source_type, django_escape=True) self.out.write(html)
def highlight_code(request): """ hightlight sourcecode for copy&paste """ context = { "title": _("hightlight sourcecode"), "form_url": request.path, } if request.method == "POST": form = HighlightCodeForm(request.POST) if form.is_valid(): sourcecode = form.cleaned_data["sourcecode"] source_type = form.cleaned_data["source_type"] highlighted = make_html(sourcecode, source_type, django_escape=True) context["highlighted"] = highlighted html_code = make_html(highlighted, "html", django_escape=True) context["html_code"] = html_code else: form = HighlightCodeForm() context["form"] = form return context
def code(ext, text): """ Highlight sourcecode using Macro tag <<code ext=.EXT>>...<</code>> """ try: source_type = ext.rsplit("=", 1)[-1] except (ValueError, IndexError): source_type = "" source_html = make_html( sourcecode=text, source_type=source_type, django_escape=True ) return source_html
def highlight_code(request): """ hightlight sourcecode for copy&paste """ context = { "title": _("hightlight sourcecode"), "form_url": request.path, } if request.method == "POST": form = HighlightCodeForm(request.POST) if form.is_valid(): sourcecode = form.cleaned_data["sourcecode"] source_type = form.cleaned_data["source_type"] highlighted = make_html(sourcecode, source_type, django_escape=True) context["highlighted"] = highlighted html_code = make_html(highlighted, "html", django_escape=True) context["html_code"] = html_code else: form = HighlightCodeForm() context["form"] = form return context
def form_generator(request, model_no=None): apps = models.get_apps() app_models = [] for app in apps: app_models += models.get_models(app) models_dict = {} for no, model in enumerate(app_models): models_dict[no] = model if model_no: model = models_dict[int(model_no)] sourcecode = _textform_for_model(model, request)#, debug=True) output = hightlighter.make_html(sourcecode, source_type="py") else: output = None context = { "title": "Form generator", "models_dict": models_dict, "output": output, } return context
def form_generator(request, model_no=None): apps = models.get_apps() app_models = [] for app in apps: app_models += models.get_models(app) models_dict = {} for no, model in enumerate(app_models): models_dict[no] = model if model_no: model = models_dict[int(model_no)] sourcecode = _textform_for_model(model, request) # , debug=True) output = hightlighter.make_html(sourcecode, source_type="py") else: output = None context = { "title": "Form generator", "models_dict": models_dict, "output": output, } return context
def hightlighted_pformat(obj): return hightlighter.make_html( pformat(obj, indent=4, width=120), source_type="py", django_escape=True )
duration = time.time() - start_time socket.setdefaulttimeout(old_timeout) feed_dict = { "feed": feed, "duration": duration, } cache.set(cache_key, feed_dict, preferences["cache_timeout"]) if debug and request.user.is_staff: messages.info(request, "RSS debug is on, see page content.") feed_code = pformat(feed_dict["feed"]) feed_html = hightlighter.make_html(feed_code, source_type="py", django_escape=True) return "<h1>RSS debug</h1><h2>Feed %r</h2>\n%s" % (url, feed_html) if max_entries: feed_dict["feed"].entries = feed_dict["feed"].entries[:max_entries] context = { "template_name": preferences["template_name"], "url": url, "max_entries": max_entries, "feed": feed_dict["feed"], "duration": feed_dict["duration"], "from_cache": from_cache, "preferences": preferences, }
def render(self, context): """ put head data into pylucid_plugin.head_files.context_middleware """ source_html = make_html(sourcecode=self.raw_content, source_type=self.source_type, django_escape=True) return source_html
def render(self, context): """ put head data into pylucid_plugin.head_files.context_middleware """ source_html = make_html(sourcecode=self.raw_content, source_type=self.source_type, django_escape=True) return source_html
duration = time.time() - start_time socket.setdefaulttimeout(old_timeout) feed_dict = { "feed": feed, "duration": duration, } cache.set(cache_key, feed_dict, preferences["cache_timeout"]) if debug and request.user.is_staff: messages.info(request, "RSS debug is on, see page content.") feed_code = pformat(feed_dict["feed"]) feed_html = hightlighter.make_html( feed_code, source_type="py", django_escape=True ) return "<h1>RSS debug</h1><h2>Feed %r</h2>\n%s" % (url, feed_html) if max_entries: feed_dict["feed"].entries = feed_dict["feed"].entries[:max_entries] context = { "template_name": preferences["template_name"], "url": url, "max_entries": max_entries, "feed": feed_dict["feed"], "duration": feed_dict["duration"], "from_cache": from_cache, "preferences": preferences, }
def show_internals(request): apps_info = [] for app in get_apps(): model_info = [] for model in get_models(app): model_info.append({ "name":model._meta.object_name, }) apps_info.append({ "app_name": app.__name__, "app_models": model_info, }) # Information about the current used url patterns urlpatterns = UrlPatternInfo().get_url_info() # Create a dict from RequestContext request_context = RequestContext(request) keys = set() for context_dict in request_context.dicts: keys = keys.union(set(context_dict.keys())) request_context_info = {} for key in keys: request_context_info[key] = request_context[key] try: cnonce_size = sys.getsizeof(CNONCE_CACHE) # New in version 2.6 except (AttributeError, TypeError): # PyPy raised a TypeError cnonce_size = None context = { "title": "Show internals", "pid": os.getpid(), "cache_information": LocalSyncCache.get_cache_information(), "permissions": Permission.objects.all(), "urlpatterns": urlpatterns, "request_context":hightlighted_pformat(request_context_info), "settings": hightlighted_pformat(get_safe_settings()), "db_backend_name": backend.Database.__name__, "db_backend_module": backend.Database.__file__, "db_backend_version": getattr(backend.Database, "version", "?"), "apps_info": apps_info, "db_table_names": sorted(connection.introspection.table_names()), "django_tables": sorted(connection.introspection.django_table_names()), "request_meta": hightlighter.make_html( pformat(request.META), source_type="py", django_escape=True ), "request_session": hightlighter.make_html( pformat(dict(request.session)), source_type="py", django_escape=True ), "sys_path": sys.path, "os_environ": os.environ, # Information of the cache usage # from FetchFromCacheMiddleware (if settings.COUNT_FETCH_FROM_CACHE != True: all values are None): "local_cache_requests": LOCAL_CACHE_INFO["requests"], "local_cache_request_hits": LOCAL_CACHE_INFO["request hits"], "global_cache_requests": cache.get(CACHE_REQUESTS), "global_cache_request_hits": cache.get(CACHE_REQUEST_HITS), # from UpdateCacheMiddleware (if settings.COUNT_UPDATE_CACHE != True: all values are None): "local_cache_responses": LOCAL_CACHE_INFO["responses"], "local_cache_response_hits": LOCAL_CACHE_INFO["response hits"], "global_cache_responses": cache.get(CACHE_RESPONSES), "global_cache_response_hits": cache.get(CACHE_RESPONSE_HITS), # Information about auth cnonce usage: "cnonce_count": len(CNONCE_CACHE), "cnonce_size": cnonce_size, "used_cnonces": tuple(sorted(CNONCE_CACHE.keys())), } return context