It’s just data

Genshi Filters for Venus

Joe Gregorio recently IM’ed me and asked me if I had looked into Genshi, suggesting that Genshi might interest me because it seemed to use XPath expressions in templates to manipulate templates.  I said that I had seen it, but it didn’t seem useful for most of my purposes.  But the more I thought about the XPath remark, the more obvious it became that I didn’t yet fully understand what Genshi could do.

Until this point, my impression that it was yet another templating engine that, given a dictionary and a template, would perform variable substitution for you, and also be able to do simple conditionals and loops, as well as provide a limited ability to shell out to the host language, much like Velocity or Cheetah.

Yes, Genshi can do all that.  But that doesn’t explain where XPath fits in.  Even when you factor in that the templating language has an XML grammar.

So, I took a look at Genshi again.  And this time it clicked.

Genshi markup templates are XML (there’s another, more Velocity/Cheetah kind of template too, but let’s not digress).  These XML documents are processed as a stream of what amounts to SAX events.

The first twist is that if the value of a variable to be substituted is a Genshi Stream object, then the stream itself gets injected into the template, not the string representation of the same.  This means that the events in the stream gets processed.

The second twist is that certain elements in the Genshi namespace, or elements that contain certain attributes in the that namespace, are treated as templates.  In other words, there is no strict separation between templates and documents, like there is XSLT, and both kinds of data can be mixed together.

By itself, that’s not all that useful, but when combined with the ability to inject in one or more streams, you have a text substitution based templating system that can do double duty as a rule based substitution markup language (like XSLT).  And to top it off, such a markup language can also provide you with access to the underlying host language (in this case, Python).  And in the process, this neatly explains where XPath fits in.

Sweet.

Once I got the concept, I set out to apply it.  I took an existing XSLT template that I use — one that would benefit from access to the richer library of functions that Python provides as compared to XSLT — and set out to convert it.

The original stylesheet has some pro-forma stuff at the top (and a line at the bottom) which declares namespaces and the like, and a total of five templates.

Here’s the Genshi equivalent.

The pro-forma stuff at the top is actually an idiom which declares the namespace then causes the element itself to be stripped.  There is no need for the identity catch-all in Genshi, but in its place, there is a need to inject the input document stream into the template.

In the remaining four templates, the translation from XSLT to Genshi markup is straightforward.  And generally, the Genshi markup is both more compact and more powerful.  Key points:

I’m sure that I’ve only scratched the surface of what Genshi can do, but it was enough to convince me to rough in the ability for people to use Genshi as a markup language for Venus filters and templates.

In the process, I added another function to Venus: template filters, i.e., filters that are used to post-process the output of a template.  The templates presented above to add a search form and autodiscovery to an properly constructed HTML page is but one such example of what can be done with a post processing template.  Ultimately, I hope to bang on my mememes logic until it too can be executed as a filter.

What I’ve done for Genshi templates is very limited.  For input filters, the input is an Atom element and the output is an Atom element, so XML in and XML out is appropriate.  For templates, input is an Atom feed, and output can be pretty much anything you want, so XML to XML may work, but other options are available: in particular a HTML serializer is a possibility.  But for filters that post process the output of a template, well the input can be pretty much anything you like.  For this case, an HTML parser may be handy — if for no other reason than it will allow you to post process the output of HTMLTmpl outputs.

Additionally, at the moment I’ve not done all I can to enable the “simple template” approach.  In the case of templates and input filters, parsing the data into dictionaries would be helpful.  I could make use of the the variables defined for htmltmpl usage; but those only expose a subset of the data and are engineered around some limitations of htmltmpl itself.  I’m inclined to simply pass the data through the feedparser and be done with it.

But these need to be filter options, and they need testcases.  If anybody is interested, here’s where the unit tests go, and here’s the interfacing code for Genshi.

Of course, you will need to install Genshi first.  But by now, you probably want to anyway, don’t you.  :-)


This is why I mention things in an off-hand manner to Sam in IM.

Posted by Joe at

It looks like I have some hacking to do this weekend.  This looks like fun!

Posted by Scott Johnson at

Wow, I’m glad you took a look at this, Sam. I’d been meaning to put a bug in your ear about it myself. Many of the concepts Genshi borrowed from Kid were conceived developing a system similar to Venus. It was called “Splice”. I was trying to build an aggregator that brought in different feed formats, normalized them to some common format (I think Atom was still called Echo), and then used XSLT to transform them. I kept on running into problems with XSLT and got a nasty itch for a simple alternative.

The aggregator project was a horrible mess. Looking at Venus, I can see now many of the problems in my approach. But I’ve always thought Kid, and especially the refinements added in Genshi (XPath!!), was something people ought to have a look at.

I wrote a piece a while back that goes into more detail on why Kid’s design is the way it is. I think you’d find it interesting: [link]

The first half is pretty blathering so skip down about half way or so and there’s some meat.

Posted by Ryan Tomayko at

Looking at Venus, I can see now many of the problems in my approach.

You know, there are two different ways to parse that statement.  Now, come to think about it, I won’t ask.  :-)

Posted by Sam Ruby at

Sam Ruby: Genshi Filters for Venus

“In the remaining four templates, the translation from XSLT to Genshi markup is straightforward. And generally, the Genshi markup is both more compact and more powerful.”...

Excerpt from del.icio.us/tag/python at

Yes. That was poorly stated. I don’t think you’re a cynic, so parse it the first way :)

Posted by Ryan Tomayko at

Interestingly enough, last night I did ‘easy_install Genshi’...

Posted by Ted Leung at

Neat!  Hadn’t seen Genshi before now, but I like Kid quite a bit.  I rather suspect I will end up stealing some of Genshi’s concepts in the future.

Posted by Bob Aman at

People loving Genshi and HTML5 might like genshihtml5.

I don’t think the “HTML5 Template Language” is really usable yet, but HTML5 input and output surely are (and serialization now omit optional tags to save some bytes on the wire).

Posted by Thomas Broyer at

Re: Genshi Filters for Venus; Genshi + Trac-AtomPP

This news is excellent. One of my side projects (although, it was pretty low on my list) was to figure out how to use Genshi templates in Venus. I started out by copying the Django template code/unit tests and adapted them for Genshi. However, I...

Excerpt from Egocity: Developer's Edition at

Genshi Templates for Venus

Earlier, I explored Genshi Filters for Venus, and compared them to XSLT. Today, I implemented Genshi Templates.  Lets compare them to htmltmpl. Excerpt from genshi_fancy: <h3 py:if="entry.new_feed"><a href="$entry.link" title="$entry.s... [more]

Trackback from Sam Ruby

at

Re: Genshi Filters for Venus; Genshi + Trac-AtomPP

This news is excellent. One of my side projects (although, it was pretty low on my list) was to figure out how to use Genshi templates in Venus. I started out by copying the Django template code/unit tests and adapted them for Genshi. However, I...

Excerpt from Egocity: Developer's Edition at

Hi! Thanks for the great information you have provided! You have touched on crucuial points!

Posted by banderas institucionales at

These are some great tools that i definitely use for SEO work. This is a great list to use in the future..

Posted by Sunshine Coast high tea at

This is really a nice and informative, containing all information and also has a great impact on the new technology. Thanks for sharing it

Posted by jadesara cups at

I am definitely enjoying your website. You definitely have some great insight and great stories.

Posted by $6.5 cheap eyeglasses at

Wonderful illustrated information. I thank you about that. No doubt it will be very useful for my future projects. Would like to see some other posts on the same subject!

Posted by Monkey Digital at

Thanks for sharing nice information with us. i like your post and all you share with us is uptodate and quite informative, i would like to bookmark the page so i can come here again to read you, as you have done a wonderful job.

Posted by Rem cua at

Thanks for sharing superb information. Your website is very cool. I am impressed by the details that you have on this site.

Posted by Mak at

This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information...

Posted by halong day tour at

Awesome and interesting article. Great things you’ve always shared with us. Thanks. Just continue composing this kind of post.

Posted by magento 2 custom options at

Its a great pleasure reading your post.Its full of information I am looking for and I love to post a comment that “The content of your post is awesome” Great work.

Posted by amycoz half framed glasses at

The information you have posted is very useful. The sites you have referred was good. Thanks for sharing...

Posted by Poke Guy at

Step out of the history that is holding you back. Step into the new story you are willing to create.

Vimax Price

Posted by Vimax in Pakistan at

I got what you mean  , thanks  for posting .Woh I am happy  to find this website through google.

Posted by https://www.topspeed.in at

If you set out to make me think today; mission accomplished!  I really like your writing style and how you express your ideas.  Thank you.

Posted by Rèm cửa at

This is actually the kind of information I have been trying to find. Thank you for writing this information.

Posted by Rèm cửa sổ at

Thanks for the post and great tips..even I also think that hard work is the most important aspect of getting success..

Posted by professional services at

There are no lines in the sand in the blogosphere except for those who draw those lines in an effort to get attention. black cobra tablets in Pakistan

Posted by Black Cobra in Pakistan at

The Internet destroyed most of the barriers to publication. The cost of being a publisher dropped to almost zero with two interesting immediate results: anybody can publish, and more importantly, you can publish whatever you want. hammer of thor original in pakistan

Posted by Hammer of Thor in Pakistan at

thanks for information

Posted by cialics tablets in Pakistan at

Blogging is just writing — writing using a particularly efficient type of publishing technology.   viga 60000 delay spray side effects

Posted by Viga Delay Spray in Pakistan at

Blogging is to writing what extreme sports are to athletics: more free-form, more accident-prone, less formal, more alive.  vigrx plus results in urdu

Posted by Vigrx Plus in Pakistan at

I am very happy to discover your post as it will become on top in my collection of favorite blogs to visit.

Posted by video converter youtube at

I’m glad I found this web site, I couldn’t find any knowledge on this matter prior to.Also operate a site and if you are ever interested in doing some visitor writing for me if possible feel free to let me know, i am always look for people to check out my web site.

Posted by chung cư BRG Sài Đồng at

great work thanks for information <a href="https://www.myetsymart.com/product/goji-whitening-cream-in-pakistan" >Goji Cream Benifits</a>

Posted by Goji Whitening Cream In Pakistan at

amazing web work

Posted by https://www.myetsymart.com/product/magic-delay-cre at

It’s not about how many years of experience you have. It’s about the quality of your years of experience.
Step Up Height Increaser Details

Posted by Step Up in Pakistan at

If you’ve got an idea, start today. There’s no better time than now to get going. That doesn’t mean quit your job and jump into your idea 100% from day one, but there’s always small progress that can be made to start the movement.
eco slim price

Posted by Eco Slim in Pakistan at

Traditional marketing talks ‘at’ people. Content marketing talks with them. breast enlargement homemade cream

Posted by Breast Cream in Pakistan at

I don’t have big ideas. I sometimes have small ideas, which seem to work out.
artificial hymen pills in islamabad

Posted by Hymen Pills in PAkistan at

The paradox is that the more information you give away, the more people will buy what you have to give. natural breast enlargement cream

Posted by Viagra Tablets in Pakistan at

thanks for information <a href="https://www.artificialhymenpills.com/Artificial-Hymen-Pills-in-Karachi.html" > hymen repair pills in pakistan</a>

Posted by Artificial Hymen Pills in Pakistan at

thanks for web

Posted by Titan Gel In Pakistan at

great web

Posted by Viagra Tablets In Pakistan at

I recently found many useful information in your website especially this blog page. Among the lots of comments on your articles. Thanks for sharing.

Posted by kangen k8 at

It works by expanding blood stream to the penis to help enhance erectile function

Posted by Levitra Tablets In Pakistan at

greater and thicker organ with shake hard erection and timing Largo King Size Cream is the best alternative for you

Posted by Largo Cream In Pakistan at

helping men accomplish more grounded and longer enduring erections

Posted by Vimax Pills In Pakistan at

Allhomeworkhelp.com is the best place where student can get online business marketing homework help easily and perfect assignment help of any subject at low price as the student requirement. Our assignment expert are ready for any time to give assignment.

Posted by business marketing assignment help at

Nice post! thanks for sharing with us. keep posting.

Posted by business marketing assignment help at

The casual conversational tone of a blog is what makes it particularly dangerous
Black Cobra 5 Tablets 125mg Pakistan

Posted by Black Cobra Tablets in Pakistan at

Don’t focus on having a great blog. Focus on producing a blog that’s great for your readers. Maximizer Plus Oil in Pakistan

Posted by Maximizer Oil at

Not only are bloggers suckers for the remarkable, so are the people who read blogs. Spanish Gold Fly Women Sex Drops in Pakistan

Posted by Spanish gold fly at

great web work

Posted by Cialis Tablets In Pakistan at

great and amazing web work

Posted by Montalin Capsule in Pakistan at

amazing web

Posted by Orthayu Balm in Pakistan at

informative web.

Posted by arthroneo spray online in Pakistan at

nice post:)

Posted by air lounge sofa online in Pakistan at

Nice post! thanks for sharing with us. keep posting.

Posted by eco slim in karachi pakistan at

great and amazing web work.

Posted by fat cutter in karachi pakistan at

There are a lot of rich people in the world. There are very few people who have the privilege of getting to invent things that billions of people use. how to use artificial hymen pills

Posted by how to use artificial hymen pills at

Every single person I know who is successful at what they do is successful because they love doing it. Price of Vigrx Plus in Pakistan

Posted by Vigrx Plus in Pakistan at

thanks for information

Posted by Magic Delay Cream In Pakistan at

amazing web work

Posted by Titan Gel In Pakistan at

This article contains some of the most informative content I’ve read in quite some time. The points of this content are clear-cut and engaging. I think much like this writer.
biomanix in lahore pakistan

Posted by biomanix in Lahore Pakistan at

Fantastic Blog! I agree completely with you here. It is a very valuable and helpful collection of blogs. I am trying to gain information from all these. Really helpful post. Thank you..!!

Posted by artificial hymen pills in lahore pakistan at

We led with our conviction rather than rational because rational said it was impossible. viagra Tablets in Pakistan

Posted by viagra tablets at

I think I was very naïve early on, but that also meant I didn’t know what couldn’t be done. Magica Organ Oil in Karachi Pakistan

Posted by Magica Organ Oil at

It’s not about how many years of experience you have. It’s about the quality of your years of experience. Climax Sex Drops In Karachi Pakistan

Posted by Climax Sex Drops at

thanks for information web

Posted by Slimming Capsules In Pakistan at

thanks for information

Posted by Rizer Xl In Pakistan at

Blogging is a conversation, not a code. Size Up Cream in Islamabad Pakistan

Posted by Size Up Cream at

Blogging is a communications mechanism handed to us by the long tail of the Internet. Green Coffee Beans in Islamabad Pakistan

Posted by Green Coffee Beans at

apply from the base of the breasts to the neck with firm and roundabout

Posted by Bio Breast Cream In Pakistan at

concerns arising out of your use of this product, consult your fitness care

Posted by Black Gorilla Pills In Pakistan at

I believe photos is one of the underlying things in every social network that becomes successful.  Body Up Creams in Lahore Pakistan

Posted by Body Up Creams at

We are competing against ourselves; we have no control over how other people perform.
Formula 41 Extreme In Lahore Pakistan

Posted by Formula 41 Extreme at

My number one piece of advice is: you should learn how to program.  Slimming Gold Capsule In Islamabad Pakistan

Posted by Slimming Gold Capsule at

If you make the Internet, live on the internet.  Vaginal Tightening Tablet In Islamabad Pakistan

Posted by Vaginal Tightening Tablet at

amazing web i like it

Posted by Herb Viagra In Pakistan at

thanks web work thanks for sharing

Posted by Maca Men Kinohimitsu In Pakistan at

thanks for web work

Posted by Artificial Hymen Pills at

thanks for web work

Posted by Biomanix at

very informative web

Posted by Body Buildo at

The first thing you need to decide when you build your blog is what you want to accomplish with it, and what it can do if successful. Dr James Lady Capsule In Pakistan

Posted by Dr.James Lady Capsules at

Nice blog and absolutely outstanding. You can do something much better but i still say this perfect. Keep trying for the best.

Posted by Hymen Repair Pills in Pakistan at

I think I have never seen such blogs ever before that has complete things with all details which I want. So kindly update this ever for us.

Posted by Black Cobra 125 Tablets Price in Pakistan at

Nice information, valuable and excellent design, as share good stuff with good ideas and concepts, lots of great information and inspiration, both of which I need, thanks to offer such a helpful information here.

Posted by Tadalafil Tablets in Pakistan at

The casual conversational tone of a blog is what makes it particularly dangerous  Orthayu Balm In Pakistan

Posted by Orthayu Balm at

If Google teaches you anything, it’s that small idea can be big. 
Sandhi Sudha Plus In Pakistan

Posted by Sandhi Sudha Plus at

great and amazing web work

Posted by Penegra Tablets In Pakistan at

amazing web work

Posted by Ecoslim Capsule In Pakistan at

If you start with nothing and end up with nothing, there’s nothing lost.
Body Buildo Reviews In Pakistan

Posted by Body Buildo at

Don’t make decisions based on fear.  Fat Cutter Reviews In Pakistan

Posted by Fat Cutter at

I believe photos is one of the underlying things in every social network that becomes successful.

Posted by Asthijivak Paste And Oil In Pakistan at

Building and hanging on to an audience is the biggest role of social media.

Posted by Ime 9 Tablets In Pakistan at

I got lucky because I never gave up the search. Are you quitting too soon

Posted by Joint Pain Capsule In Pakistan at

great and amazing web work thanks for sharing

Posted by Bio Oil Price In Pakistan at

Shopping Help Desk

Posted by Samer at

I am impressed with this site, real I am a big fan.

Posted by Vimax at

For many people this is important, so check out my profile:

Posted by Handsome Pump at

On this subject internet page, you’ll see my best information, be sure to look over this level of detail.

Posted by EverLong Tablets at

Don’t focus on having a great blog. Focus on producing a blog that’s great for your readers. Carrot Mask Cream Online In Pakistan

Posted by Carrot Mask Cream at

The secret of change is to focus all your energy not on fighting the old but on building the new. Easy Slim Tea Online In Pakistan

Posted by Easy Slim Tea at

My number one piece of advice is: you should learn how to program

Posted by Fair Look Cream In Pakistan at

If you make the Internet, live on the internet.

Posted by Hair Color Shampoo In Pakistan at

Forex deposit bonuses start from as low as 5% of the deposit amount to as high as 100% of the initial deposit. Some brokers also offer up to 200% or an even ...

Posted by Ann T. Galarza at

If you’re not making mistakes, then you’re not making decisions. Original Beard Growth Oil In Pakistan

Posted by Beard Growth Oil at

Always think outside the box and embrace opportunities that appear, wherever they might be.  Original Raspberry Ketones In Pakistan

Posted by Raspberry Ketones at

I’m glad to see the great detail here!.

Posted by gamemite at

Excellent article. Very interesting to read. I really love to read such a nice article. Thanks! keep rocking.

Posted by Online Shopping at

Find something you love and do it better than everyone else.

Posted by Vita White Capsule In Pakistan at

My number one piece of advice is: you should learn how to program.

Posted by Voox Dd Cream In Pakistan at

If you just work on stuff that you like and you’re passionate about, you don’t have to have a master plan with how things will play out.  Dr Slimming Tea Online In Pakistan

Posted by Dr Slimming tea at

Wonder what your customer really wants? Ask. Don’t tell.
Braun Epilator Online In Pakistan

Posted by Braun Epilator at

Made to measure curtains… [...]check out the sites listed below, worth a read for interiors and rugs enthusiasts[...]… Happy Mother’s Day 2020

Posted by Shah Jee at

Its most exceedingly awful piece was that the item just worked intermittently and the data was not exact. You plainly canot go up against anyone about what you have found if the information isn’t right.

Posted by Levitra 10 mg Available in Pakistan at

Every single person I know who is successful at what they do is successful

Posted by Ultra Wizzit In Pakistan at

Anything can be done, as long as you truly believe it.

Posted by Hot Shapers Belt In Pakistan at

Don’t try to be original, just try to be good. Original Ever Long Tablets In Pakistan

Posted by Ever Long Tablets at

Some people dream of success, while other people get up every morning and make it happen. Some people dream of success, while other people get up every morning and make it happen.

Posted by Vig Power Capsules at

Anything can be done, as long as you truly believe it.

Posted by Ultra Wizzit In Pakistan at

Wow!
This is really a nice and informative, containing all information and also has a great impact on the new technology. Thanks for sharing it..
https://youtubemp3converts.com/convert-youtube-to-mp3/

Posted by billorani40047 at

Reviews of the best binary options brokers and trading platforms. List of binary broker sites with payout, minimum deposit, regulation and bonus comparison.

Posted by Jose A. Propst at

AllAssignmentHelp is the best service that you are searching for where you will get help with assignment done perfectly as your requirements and level. We are offering the best quality assignment help to the students. We have well experienced and skilled online assignment experts that are available 24*7 times.
help with assignment online

Posted by hire assignment expert at

I found that site very usefull and this survey is very cirious. I ' ve never seen a blog that demand a survey for this actions. very curious...

Posted by Upsell Links at

Add your comment