def statistics(post): """Print statistics about post.""" data = post["analysis"]["data"] lenfield = "Length: %i bytes " % len(data) if ((len(data) - 8) % 32) == 0: lenfield += "(= 8 + %i * 32)" % ((len(data) - 8) / 32) else: lenfield += "(does NOT match pattern!)" return html.ul( lenfield, "Statistical distribution: %s" % \ post["analysis"]["distribution"], "Entropy: %s" % \ post["analysis"]["entropy"], "Mean: %0.2f" % \ post["analysis"]["mean"], "Variance: %0.2f" % \ post["analysis"]["variance"], "Stdev: %0.2f" % \ post["analysis"]["sigma"], "Skewness: %0.2f" % \ post["analysis"]["sk"], "Kurtosis: %0.2f" % \ post["analysis"]["ex"], )
def as_actions(items): """ returns actions >>> as_actions(['New']) '<div class="actions"><ul><li><a class="action" id="new-action" href="/new">New</a></li></ul></div>' >>> as_actions(['New','Delete']) '<div class="actions"><ul><li><a class="action" id="delete-action" href="/delete">Delete</a></li><li><a class="action" id="new-action" href="/new">New</a></li></ul></div>' """ if not items: return '' result = [] for item in reversed(items): if hasattr(item, '__iter__'): if len(item) == 2: text, url = item else: #TODO: review to see if this is even useful text = item[0] url = '/'.join([''] + route + [item[1]]) else: text = item url = '/'.join([''] + route + [id_for(item)]) result.append('<a class="action" id="%s-action" href="%s">%s</a>' % (id_for(text), url, text)) return div(ul(result), Class='actions')
def as_actions(items): """ returns actions >>> as_actions(['New']) '<div class="actions"><ul><li><a class="action" id="new-action" href="/new">New</a></li></ul></div>' >>> as_actions(['New','Delete']) '<div class="actions"><ul><li><a class="action" id="delete-action" href="/delete">Delete</a></li><li><a class="action" id="new-action" href="/new">New</a></li></ul></div>' """ if not items: return "" result = [] for item in reversed(items): if hasattr(item, "__iter__"): if len(item) == 2: text, url = item else: # TODO: review to see if this is even useful text = item[0] url = "/".join([""] + route + [item[1]]) else: text = item url = "/".join([""] + route + [id_for(item)]) result.append('<a class="action" id="%s-action" href="%s">%s</a>' % (id_for(text), url, text)) return div(ul(result), Class="actions")
def time_data(post): timedata = post["analysis"]["time"] return html.ul( "Time in post title: %s" % timedata["title_time_str"], "Posted to Reddit: %s UTC" % timedata["post_time_str"], "Identified time zone: %s" % \ timezone_link(timedata["timezone"]), "Post delay: %i seconds" % timedata["post_delay"], )
def time_data(post): timedata = post["analysis"]["time"] if timedata is None: return "" return html.ul( "Time in post title: %s" % timedata["title_time_str"], "Posted to Reddit: %s UTC" % timedata["post_time_str"], "Identified time zone: %s" % \ timezone_link(timedata["timezone"]), "Post delay: %i seconds" % timedata["post_delay"], )
def show_list(): """ Show a list of all posts. """ posts = psblog.get_all_posts() ls_data = [] for p in posts: ls_data.append("".join([ p["meta"]["datetime"].strftime("%x")," - ", html.a("?page=single&id="+psblog.post_id(p["meta"]), p["meta"]["heading"]), " - ", str(len(p["comments"])), " comment(s)"])) print(html.render_admin(html.block(html.ul(ls_data))))
def html_page(title, *content, **arguments): head = html.head( html.link(rel="shortcut icon", href=config["favicon"]), html.title("{} - {}".format(title, config["title"])), html.style(style), ) nav = html.nav( html.ul( html.li(html.a("⚗", href=html.absolute())), html.li(html.a("Reviews", href=html.absolute("reviews"))), html.li(html.a("Commits", href=html.absolute("commits", repo.head.ref.name))), html.li(html.a("Tree", href=html.absolute("tree", repo.head.ref.name))), html.li(html.a("Refs", href=html.absolute("refs"))), ) ) return http.Html(html.html(head, html.body(*((nav,) + content + (html.script(script),)), **arguments)))
def format_post(post): id = post["data"]["id"] title = post["data"]["title"] url = post["data"]["url"] def formatted(x): name, callback = x return "%s: %s" % (name, callback(post)) items = map(formatted, decoders) + [html.a("Permalink", href="/?id=%s" % id)] return html.div(html.a(name=id), html.h3(html.a(html.escape(title), href=url)), html.ul(*items), id="post-%s" % id)
def format_post(post): id = post["data"]["id"] title = post["data"]["title"] url = post["data"]["url"] def formatted(x): name, callback = x return "%s: %s" % (name, callback(post)) items = map(formatted, decoders) + [ html.a("Permalink", href="/?id=%s" % id) ] return html.div(html.a(name=id), html.h3(html.a(html.escape(title), href=url)), html.ul(*items), id="post-%s" % id)
def app_menu(): """Returns the app menu.""" links = [] if hasattr(system.app,'menu'): items = system.app.menu selected = route[0]=='content' and len(route)>2 and route[2] or len(route)>1 and route[1] for (name,title,url) in items: if url == '': url = url_for('/'+route[0]) elif url[0]=='/': url = url_for(url) else: url = url_for('/'+route[0]+'/'+url) selector = name==selected and 'id="current"' or '' links.append('<a href="%s" %s>%s</a>' % (url,selector,title)) else: links = [] return html.ul(links)
def load_menu(name=None): """renders a menu""" if name: try: items = tools.get_menu(name) if not items: raise Exception('menu %s empty' % name) except: error('unable to read menu <b>"%s"</b>' % name) items = [] links = [] for item in items: title = item[0] url = item[1] groups = item[2] if groups==[] or [g for g in groups if g in user.groups]: links.append('<a href="%s">%s</a>' % (url_for(url), title)) return html.ul(links)
def load_menu(name=None): """renders a menu""" if name: try: items = tools.get_menu(name) if not items: raise Exception("menu %s empty" % name) except: error('unable to read menu <b>"%s"</b>' % name) items = [] links = [] for item in items: title = item[0] url = item[1] groups = item[2] if groups == [] or [g for g in groups if g in user.groups]: links.append('<a href="%s">%s</a>' % (url_for(url), title)) return html.ul(links)
def messages(): """Returns an unordered list of messages in HTML and clears the messages list.""" result = system.session.system_messages and html.ul(system.session.system_messages) or "" system.session.system_messages = [] return result
def flag_list(icon='star', n=None): links = [f.link for f in flags.flags.find(owner=user.username) if not icon or icon==f.icon] if n: links = links[:n] return html.ul(links)
def messages(): """Returns an unordered list of messages in HTML and clears the messages list.""" result = system.session.system_messages and html.ul(system.session.system_messages) or '' system.session.system_messages = [] return result
def errors(): """Returns an unordered list of errors in HTML and clears the errors list.""" result = system.session.system_errors and html.ul(system.session.system_errors) or '' system.session.system_errors = [] return result
def warnings(): """Returns an unordered list of warnings in HTML and clears the warning list.""" result = system.session.system_warnings and html.ul(system.session.system_warnings) or '' system.session.system_warnings = [] return result
def warnings(): """Returns an unordered list of warnings in HTML and clears the warning list.""" result = system.session.system_warnings and html.ul(system.session.system_warnings) or "" system.session.system_warnings = [] return result
def review_to_html_summary(r): hexsha, review = r commits = html.ul(*map(lambda c: html.li(*commit_to_html(repo.commit(c))), review["includedCommits"])) return html.div(html.h1(html.a(hexsha[0:12], href=html.absolute("review", hexsha))), commits, **{"class": "review"})
def errors(): """Returns an unordered list of errors in HTML and clears the errors list.""" result = system.session.system_errors and html.ul(system.session.system_errors) or "" system.session.system_errors = [] return result
def flag_list(icon="star", n=None): links = [f.link for f in flags.flags.find(owner=user.username) if not icon or icon == f.icon] if n: links = links[:n] return html.ul(links)