def __call__(self, env, start_response): """ env["enkel.reuse.admin.stylesheet"] must contain the URL to the XSLT stylesheet. """ path = env["SCRIPT_NAME"] + env["PATH_INFO"] appid = None if not path.endswith("start/"): match = self.patt.match(path) if match: appid, action = match.groups() app, label, args, kw = self.apps[appid] else: raise Http404() w = XmlWriter(pretty=self.pretty) w.pi("xml", version="1.0", encoding=self.encoding) w.pi("xml-stylesheet", type="text/xsl", href=self.stylesheet) w.start_element("admin", xmlns=XMLNS_ADMIN) w.raw_node(self.applist_xml) if appid: w.empty_element("selected", app=appid, action=action) w.start_element("section", xmlns=XMLNS_MARKUP) if appid: app(env, w, appid, action, label, *args, **kw) else: self.startpage(env, w) w.end_element() start_response( "200 OK", [("content-type", "text/xml; charset=%s" % self.encoding)]) yield w.create().encode(self.encoding)
def setUp(self): w = XmlWriter() w.pi("xml", version="1.0") w.pi_raw("pros", "shit") w.start_element("html") w.start_element("body") w.text_node(u"\u00e5ge") w.empty_element("div", attrdict={"class":"test"}) w.end_element(2) self.w = w self.b = w.create()
def setUp(self): w = XmlWriter() w.pi("xml", version="1.0") w.pi_raw("pros", "shit") w.start_element("html") w.start_element("body") w.text_node(u"\u00e5ge") w.empty_element("div", attrdict={"class": "test"}) w.end_element(2) self.w = w self.b = w.create()
def preprocess(postlist_filename, taglist_filename, posts_folder): """ Create a xml-file containing listing all the posts in the cms and a file containing all the tags is the cms. The format of the file output-files are defined in relax-ng/posts.rng and relax-ng/tags.rng. @param postlist_filename: The file where the post info is written. @param taglist_filename: The file where the tag info is written. @param posts_folder: The folder containing all the post-files. """ tags = {} w = XmlWriter(pretty=True) w.start_element("posts") for post_id in listdir(posts_folder): path = join(posts_folder, post_id) w.empty_element("post", id=str(post_id), src=abspath(path), mtime=strftime("%Y-%m-%d %H:%M", gmtime(getmtime(path)))) parser = make_parser() parser.setContentHandler(PostHandler(post_id, tags)) parser.parse(path) w.end_element() # write post list postslist = w.create().encode("utf-8") log.debug("%s: %s" % (postlist_filename, postslist)) open(postlist_filename, "wb").write(postslist) # write tag list w = XmlWriter(pretty=True) w.start_element("tags") for tag_id in tags: tag_name, posts = tags[tag_id] w.start_element("tag", id=tag_id, name=tag_name) for post_id in posts: path = abspath(join(posts_folder, post_id)) w.empty_element("post", id=post_id, src=path, mtime=strftime("%Y-%m-%d %H:%M", gmtime(getmtime(path)))) w.end_element() w.end_element() taglist = w.create().encode("utf-8") log.debug("%s: %s" % (taglist_filename, taglist)) open(taglist_filename, "wb").write(taglist)
def preprocess(postlist_filename, taglist_filename, posts_folder): """ Create a xml-file containing listing all the posts in the cms and a file containing all the tags is the cms. The format of the file output-files are defined in relax-ng/posts.rng and relax-ng/tags.rng. @param postlist_filename: The file where the post info is written. @param taglist_filename: The file where the tag info is written. @param posts_folder: The folder containing all the post-files. """ tags = {} w = XmlWriter(pretty=True) w.start_element("posts") for post_id in listdir(posts_folder): path = join(posts_folder, post_id) w.empty_element("post", id = str(post_id), src = abspath(path), mtime = strftime("%Y-%m-%d %H:%M", gmtime(getmtime(path))) ) parser = make_parser() parser.setContentHandler(PostHandler(post_id, tags)) parser.parse(path) w.end_element() # write post list postslist = w.create().encode("utf-8") log.debug("%s: %s" % (postlist_filename, postslist)) open(postlist_filename, "wb").write(postslist) # write tag list w = XmlWriter(pretty=True) w.start_element("tags") for tag_id in tags: tag_name, posts = tags[tag_id] w.start_element("tag", id=tag_id, name=tag_name) for post_id in posts: path = abspath(join(posts_folder, post_id)) w.empty_element("post", id = post_id, src = path, mtime = strftime("%Y-%m-%d %H:%M", gmtime(getmtime(path))) ) w.end_element() w.end_element() taglist = w.create().encode("utf-8") log.debug("%s: %s" % (taglist_filename, taglist)) open(taglist_filename, "wb").write(taglist)
def __call__(self, env, start_response): """ env["enkel.reuse.admin.stylesheet"] must contain the URL to the XSLT stylesheet. """ path = env["SCRIPT_NAME"] + env["PATH_INFO"] appid = None if not path.endswith("start/"): match = self.patt.match(path) if match: appid, action = match.groups() app, label, args, kw = self.apps[appid] else: raise Http404() w = XmlWriter(pretty=self.pretty) w.pi("xml", version="1.0", encoding=self.encoding) w.pi("xml-stylesheet", type="text/xsl", href=self.stylesheet) w.start_element("admin", xmlns=XMLNS_ADMIN) w.raw_node(self.applist_xml) if appid: w.empty_element("selected", app=appid, action=action) w.start_element("section", xmlns=XMLNS_MARKUP) if appid: app(env, w, appid, action, label, *args, **kw) else: self.startpage(env, w) w.end_element() start_response("200 OK", [ ("content-type", "text/xml; charset=%s" % self.encoding) ]) yield w.create().encode(self.encoding)
class Admin(object): """ A administration-panel interface using exml. """ def __init__(self, stylesheet, encoding=settings.encoding, pretty=False, startpage=default_startpage): """ @param stylesheet: The URL to a XSLT document to associate with the output. @param encoding: The encoding to output in. Defaults to L{enkel.settings.encoding}. @param pretty: Forwarded to L{enkel.xmlutils.writer.XmlWriter.__init__}. @param startpage: A function which creates the startpage. Defaults to L{default_startpage}. """ self.apps = {} self.pretty = pretty self.applist = XmlWriter(pretty=pretty) self.applist.start_element("applist") self.encoding = encoding self.stylesheet = stylesheet self.startpage = startpage def add(self, id, app, label, *args, **kw): """ @type id: str @param id: A unique indentifier for the app within this Admin object. @param app: A L{AdminApp} instance. @type label: unicode. @param label: The label to show to the user when referencing the app. @param args: Arguments to the app.__init__. @param kw: Keyword arguments to the app.__init__. """ self.apps[id] = app, label, args, kw self.applist.start_element("app", id=id, label=label) for action in app.INDEX: self.applist.empty_element("action", id=action, label=app.ACTIONS[action]) self.applist.end_element() def compile(self): """ Compile the route. Must be called once after all AdminApp's has been L{add}ed. """ ids = "|".join(self.apps.keys()) self.patt = compile(".*(?P<appid>(?:%s))/(?P<action>\w+)$" % ids) self.applist_xml = self.applist.create() del self.applist def __call__(self, env, start_response): """ env["enkel.reuse.admin.stylesheet"] must contain the URL to the XSLT stylesheet. """ path = env["SCRIPT_NAME"] + env["PATH_INFO"] appid = None if not path.endswith("start/"): match = self.patt.match(path) if match: appid, action = match.groups() app, label, args, kw = self.apps[appid] else: raise Http404() w = XmlWriter(pretty=self.pretty) w.pi("xml", version="1.0", encoding=self.encoding) w.pi("xml-stylesheet", type="text/xsl", href=self.stylesheet) w.start_element("admin", xmlns=XMLNS_ADMIN) w.raw_node(self.applist_xml) if appid: w.empty_element("selected", app=appid, action=action) w.start_element("section", xmlns=XMLNS_MARKUP) if appid: app(env, w, appid, action, label, *args, **kw) else: self.startpage(env, w) w.end_element() start_response("200 OK", [ ("content-type", "text/xml; charset=%s" % self.encoding) ]) yield w.create().encode(self.encoding)
class Admin(object): """ A administration-panel interface using exml. """ def __init__(self, stylesheet, encoding=settings.encoding, pretty=False, startpage=default_startpage): """ @param stylesheet: The URL to a XSLT document to associate with the output. @param encoding: The encoding to output in. Defaults to L{enkel.settings.encoding}. @param pretty: Forwarded to L{enkel.xmlutils.writer.XmlWriter.__init__}. @param startpage: A function which creates the startpage. Defaults to L{default_startpage}. """ self.apps = {} self.pretty = pretty self.applist = XmlWriter(pretty=pretty) self.applist.start_element("applist") self.encoding = encoding self.stylesheet = stylesheet self.startpage = startpage def add(self, id, app, label, *args, **kw): """ @type id: str @param id: A unique indentifier for the app within this Admin object. @param app: A L{AdminApp} instance. @type label: unicode. @param label: The label to show to the user when referencing the app. @param args: Arguments to the app.__init__. @param kw: Keyword arguments to the app.__init__. """ self.apps[id] = app, label, args, kw self.applist.start_element("app", id=id, label=label) for action in app.INDEX: self.applist.empty_element("action", id=action, label=app.ACTIONS[action]) self.applist.end_element() def compile(self): """ Compile the route. Must be called once after all AdminApp's has been L{add}ed. """ ids = "|".join(self.apps.keys()) self.patt = compile(".*(?P<appid>(?:%s))/(?P<action>\w+)$" % ids) self.applist_xml = self.applist.create() del self.applist def __call__(self, env, start_response): """ env["enkel.reuse.admin.stylesheet"] must contain the URL to the XSLT stylesheet. """ path = env["SCRIPT_NAME"] + env["PATH_INFO"] appid = None if not path.endswith("start/"): match = self.patt.match(path) if match: appid, action = match.groups() app, label, args, kw = self.apps[appid] else: raise Http404() w = XmlWriter(pretty=self.pretty) w.pi("xml", version="1.0", encoding=self.encoding) w.pi("xml-stylesheet", type="text/xsl", href=self.stylesheet) w.start_element("admin", xmlns=XMLNS_ADMIN) w.raw_node(self.applist_xml) if appid: w.empty_element("selected", app=appid, action=action) w.start_element("section", xmlns=XMLNS_MARKUP) if appid: app(env, w, appid, action, label, *args, **kw) else: self.startpage(env, w) w.end_element() start_response( "200 OK", [("content-type", "text/xml; charset=%s" % self.encoding)]) yield w.create().encode(self.encoding)