Thread: Re: [Rest2web-develop] Section headers
Brought to you by:
mjfoord
From: martin f k. <ma...@ma...> - 2006-08-05 12:58:24
|
also sprach Michael Foord <mi...@pc...> [2006.08.05.1305 +0100]: > martin f krafft wrote: > >also sprach Michael Foord <mi...@pc...> [2006.08.05.1158 +0100]: > > =20 > >>Yes indextree['parent'] is always None. > >> =20 > > > >Ok. > > > > =20 > >>I *think* I see what you want to do. You want a single index page > >>which only shows pages from the selected section. I could probably > >>achieve that with javascript, but I wouldn't know how to do it > >>with CSS. :-) > >> =20 > > > >No no, much easier. I simply want a list of categories (let's not > >call them sections) as defined in the root, to show up on all pages > >of the site. I want one of those categories to be hilighted, > >depending on where we are in the site. > > > >Pseudocode: > > > > def current_url_matches_category(page, cat): > > // ... > > > > print '<ol id=3D"globalsect">' > > for cat in indextree['categories']: > > if current_url_matches_category(page, cat): > > print '<li class=3D"current">' + cat['link title'] + '</li>' > > else: > > print '<li><a href=3D"%s">%s</a></li>' % (cat['base_url'],=20 > > cat['link_title']) > > > > =20 > Hmm... on reading your pseudocode a bit more carefully.... :-) >=20 > You want every 'category' to have a 'base_url' as well. >=20 > This isn't something that is really directly available in rest2web - you= =20 > want global categories and information available to every page. >=20 > You could then set the category for each page in a uservalue. >=20 > How about if I add some 'globals' to rest2web that are available in=20 > every page? This would be a nice feature to have. Think site_title: <title><% title %> - <% site_title %></title> > You would set these in the top level, and could use them from every=20 > page. Your code would look something like (in your template) : >=20 > <# >=20 > # This code will only be executed once > # It could be kept in an external module and imported > if not categories in globalValues: > categories =3D {} > categories['category 1'] =3D {'base_url': '/url1', > 'link_title': 'link title 1'} > categories['category 2'] =3D {'base_url': '/url2', > 'link_title': 'link title=20 > 2'} =20 > globalValues['categories'] =3D categories >=20 > #> >=20 > Feel free to suggest a better name than globalValues. :-) >=20 > You could find a better way of setting up the categories than hardcoding= =20 > them into your code, based on the other values available to you. *You*=20 > still have to decide which is the base url for your categories though. Well, I think that subdirectories would make perfect sense. Now I have to figure out how to use the indextree structure: - how do I get a page's uservalues? In an earlier mail, you told me to use indextree['namespace']['myvalue'], but there is no item 'namespace' in the indextree structure. - how do I get at other restindex values? For instance, if I needed to read a page's page-title, how would I do that. > If you then set a 'category' uservalue in each page, your pseudocode=20 > becomes : >=20 > <# >=20 > print '<ol id=3D"globalsect">' > for (catName, cat) in globalValues['categories'].items(): > if category =3D=3D catName: > print '<li class=3D"current">' + cat['link_title'] + '</li>' > else: > print '<li><a href=3D"%s">%s</a></li>' % (cat['base_url'],=20 > cat['link_title']) >=20 > #> >=20 > How does that seem ? (I am not trimming the reply because this goes out to the mailing list). --=20 martin; (greetings from the heart of the sun.) \____ echo mailto: !#^."<*>"|tr "<*> mailto:" net@madduck =20 spamtraps: mad...@ma... =20 nasa spent 2 billion dollars on the research of a ballpoint pen that could write on everything, even upside down, under water, or at extreme temperatures; the russians used a pencil. (but see: http://www.snopes.com/business/genius/spacepen.asp) |
From: martin f k. <ma...@ma...> - 2006-08-05 12:58:35
|
also sprach Michael Foord <mi...@pc...> [2006.08.05.1245 +0100]: > martin f krafft wrote: > >also sprach Michael Foord <mi...@pc...> [2006.08.05.1158 +0100]: > > =20 > >>Yes indextree['parent'] is always None. > >> =20 > > > >Ok. > > > > =20 > >>I *think* I see what you want to do. You want a single index page > >>which only shows pages from the selected section. I could probably > >>achieve that with javascript, but I wouldn't know how to do it > >>with CSS. :-) > >> =20 > > > >No no, much easier. I simply want a list of categories (let's not > >call them sections) as defined in the root, to show up on all pages > >of the site. I want one of those categories to be hilighted, > >depending on where we are in the site. > > > > =20 > Does your site have many directories ? No. > >Pseudocode: > > > > def current_url_matches_category(page, cat): > > // ... > > > > print '<ol id=3D"globalsect">' > > for cat in indextree['categories']: > > if current_url_matches_category(page, cat): > > print '<li class=3D"current">' + cat['link title'] + '</li>' > > else: > > print '<li><a href=3D"%s">%s</a></li>' % (cat['base_url'],=20 > > cat['link_title']) > > > > =20 > By current URL you mean the current page being rendered I assume. Yes. > You can get the 'category' of the current page from : >=20 > thispage['section'] Well, I understand sections to be per directory. My "categories" need to be site-wide. > So assuming every directory has the same categories, your code above=20 > should be fairly simple... >=20 > Could you try again with the sourceforge mailing list ? Done. Thus not trimming. I am now running up against a new problem, testing: $ r2w [...] Building contact.html [...] Processing "sub" directory. $ mkdir foo $ cp contact.txt foo/bar.txt $ r2w [...] Building contact.html Skipping "contact.html". Identical file exists. [...] Processing "foo" directory. Processing "sub" directory. [...] It's just ignoring the foo/bar.txt file... --=20 martin; (greetings from the heart of the sun.) \____ echo mailto: !#^."<*>"|tr "<*> mailto:" net@madduck =20 spamtraps: mad...@ma... =20 philosophy: unintelligible answers to insoluble problems. |
From: Gael V. <gae...@no...> - 2006-08-05 13:04:54
|
On Sat, Aug 05, 2006 at 01:53:24PM +0100, martin f krafft wrote: > > How about if I add some 'globals' to rest2web that are available in=20 > > every page? > This would be a nice feature to have. Think site_title: > <title><% title %> - <% site_title %></title> Yes !! I like that. --=20 Ga=EBl |
From: Michael F. <fuz...@vo...> - 2006-08-05 13:09:08
|
Gael Varoquaux wrote: > On Sat, Aug 05, 2006 at 01:53:24PM +0100, martin f krafft wrote: > >>> How about if I add some 'globals' to rest2web that are available in >>> every page? >>> > > >> This would be a nice feature to have. Think site_title: >> > > >> <title><% title %> - <% site_title %></title> >> > > Yes !! I like that. > You can supply global uservalues in your config now. So you could define 'site_title' in your config file : [uservalues] site_title = 'A Sitewide Title' Fuzzyman http://www.voidspace.org.uk/python/index.shtml |
From: Michael F. <fuz...@vo...> - 2006-08-05 13:18:47
|
martin f krafft wrote: > > I am now running up against a new problem, testing: > > $ r2w > [...] > Building contact.html > [...] > Processing "sub" directory. > $ mkdir foo > $ cp contact.txt foo/bar.txt > $ r2w > [...] > Building contact.html > Skipping "contact.html". Identical file exists. > [...] > Processing "foo" directory. > > Processing "sub" directory. > [...] > > It's just ignoring the foo/bar.txt file... > A directory is *only* processed if it has an index.txt. rest2web is designed to create sites that are structured using directories. Each directory can optionally be divided into sections. It is expected that each directory has an index page (because they are rendered differently, and rest2web needs to know which one is the index page). If you *don't* want the main page in a directory to be called 'index.html' there are a couple of ways of achieving this. Index page is called index.txt : restindex target: bar.html /restindex You want the index page to be called something else. You will still need an index.txt for the directory to be processed : restindex index-file: bar.txt /restindex All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml |
From: martin f k. <ma...@ma...> - 2006-08-05 13:27:27
|
also sprach Michael Foord <fuz...@vo...> [2006.08.05.1422 +010= 0]: > A directory is *only* processed if it has an index.txt. Ouch. But at least the mailing list seems to be working. I will try to subscribe for the third time. --=20 martin; (greetings from the heart of the sun.) \____ echo mailto: !#^."<*>"|tr "<*> mailto:" net@madduck =20 spamtraps: mad...@ma... =20 the heineken uncertainty principle: you can never be sure how many beers you had last night. |
From: Michael F. <fuz...@vo...> - 2006-08-05 13:27:42
|
martin f krafft wrote: > also sprach Michael Foord <mi...@pc...> [2006.08.05.1305 +0100]: > >> martin f krafft wrote: >> >>> also sprach Michael Foord <mi...@pc...> [2006.08.05.1158 +0100]: >>> >>> >>>> Yes indextree['parent'] is always None. >>>> >>>> >>> Ok. >>> >>> >>> >>>> I *think* I see what you want to do. You want a single index page >>>> which only shows pages from the selected section. I could probably >>>> achieve that with javascript, but I wouldn't know how to do it >>>> with CSS. :-) >>>> >>>> >>> No no, much easier. I simply want a list of categories (let's not >>> call them sections) as defined in the root, to show up on all pages >>> of the site. I want one of those categories to be hilighted, >>> depending on where we are in the site. >>> >>> Pseudocode: >>> >>> def current_url_matches_category(page, cat): >>> // ... >>> >>> print '<ol id="globalsect">' >>> for cat in indextree['categories']: >>> if current_url_matches_category(page, cat): >>> print '<li class="current">' + cat['link title'] + '</li>' >>> else: >>> print '<li><a href="%s">%s</a></li>' % (cat['base_url'], >>> cat['link_title']) >>> >>> >>> >> Hmm... on reading your pseudocode a bit more carefully.... :-) >> >> You want every 'category' to have a 'base_url' as well. >> >> This isn't something that is really directly available in rest2web - you >> want global categories and information available to every page. >> >> You could then set the category for each page in a uservalue. >> >> How about if I add some 'globals' to rest2web that are available in >> every page? >> > > This would be a nice feature to have. Think site_title: > > <title><% title %> - <% site_title %></title> > > I have just added 'globalValues'. You could now do something like : try: site_title except NameError: site_title = globalValues['site_title'] else: globalValues['site_title'] = site_title Which is perhaps a little ugly. :-) The better way of achieving this is to provide uservalues in your site config file. These are already available to every page. >> You would set these in the top level, and could use them from every >> page. Your code would look something like (in your template) : >> >> <# >> >> # This code will only be executed once >> # It could be kept in an external module and imported >> if not categories in globalValues: >> categories = {} >> categories['category 1'] = {'base_url': '/url1', >> 'link_title': 'link title 1'} >> categories['category 2'] = {'base_url': '/url2', >> 'link_title': 'link title >> 2'} >> globalValues['categories'] = categories >> >> #> >> >> Feel free to suggest a better name than globalValues. :-) >> >> You could find a better way of setting up the categories than hardcoding >> them into your code, based on the other values available to you. *You* >> still have to decide which is the base url for your categories though. >> > > Well, I think that subdirectories would make perfect sense. > > Now I have to figure out how to use the indextree structure: > > - how do I get a page's uservalues? In an earlier mail, you told > me to use indextree['namespace']['myvalue'], but there is no > item 'namespace' in the indextree structure. > I thought I suggested (I should have done) : sections['section name']['pages'][pageIndex]['namespace'] or : for section in sections.values(): for page in section['pages']: namespace = page['namespace'] This only gives you access to pages in the current directory though., and index pages of the directories below. > - how do I get at other restindex values? For instance, if > I needed to read a page's page-title, how would I do that. > > You can't access the restindex or uservalues of pages through indextree. Every page in indextree has a 'link-title'. If this hasn't been explicitly set in the restindex of a page, it defaults to the page title. What other values do you need access to ? Fuzzyman http://www.voidspace.org.uk/python/index.shtml >> If you then set a 'category' uservalue in each page, your pseudocode >> becomes : >> >> <# >> >> print '<ol id="globalsect">' >> for (catName, cat) in globalValues['categories'].items(): >> if category == catName: >> print '<li class="current">' + cat['link_title'] + '</li>' >> else: >> print '<li><a href="%s">%s</a></li>' % (cat['base_url'], >> cat['link_title']) >> >> #> >> >> How does that seem ? >> > > (I am not trimming the reply because this goes out to the mailing > list). > > |
From: martin f k. <ma...@ma...> - 2006-08-05 13:56:24
|
also sprach Michael Foord <mi...@pc...> [2006.08.05.1426 +0100]: > Which is perhaps a little ugly. :-) >=20 > The better way of achieving this is to provide uservalues in your site=20 > config file. These are already available to every page. by site config file, you mean .ini file? > You can't access the restindex or uservalues of pages through > indextree. Mh, this is not what I wanted to hear... would it be possible to add this? I think it would just make it a whole lot more flexible, especially since indextree seems to be the structure representing the entire site and hence needs to be used for a lot of different functions. > Every page in indextree has a 'link-title'. If this hasn't been=20 > explicitly set in the restindex of a page, it defaults to the page title. >=20 > What other values do you need access to ? Well, the page-title if link-title has been set. :) But I guess I could also just name my /index.txt "Introduction" (which is the current link_title) and use site-wide uservalues to define the site title. Thanks again for your continued patience and support! --=20 martin; (greetings from the heart of the sun.) \____ echo mailto: !#^."<*>"|tr "<*> mailto:" net@madduck =20 spamtraps: mad...@ma... =20 SUSE: Soll Unix Sein, Eigentlich. |
From: Michael F. <fuz...@vo...> - 2006-08-05 15:05:34
|
martin f krafft wrote: > also sprach Michael Foord <mi...@pc...> [2006.08.05.1426 +0100]: > >> Which is perhaps a little ugly. :-) >> >> The better way of achieving this is to provide uservalues in your site >> config file. These are already available to every page. >> > > by site config file, you mean .ini file? > > Yes. >> You can't access the restindex or uservalues of pages through >> indextree. >> > > Mh, this is not what I wanted to hear... would it be possible to add > this? I think it would just make it a whole lot more flexible, > especially since indextree seems to be the structure representing > the entire site and hence needs to be used for a lot of different > functions. > Don't forget that rest2web is built top down. The indextree only contains information for pages/directories above the one currently being rendered, not for the whole site. I've now (experimentally) added the restindex and uservalues for each page into the indextree. Now checked in. Please let me know if this works for you. Fuzzyman http://www.voidspace.org.uk/python/index.shtml > >> Every page in indextree has a 'link-title'. If this hasn't been >> explicitly set in the restindex of a page, it defaults to the page title. >> >> What other values do you need access to ? >> > > Well, the page-title if link-title has been set. :) > > But I guess I could also just name my /index.txt "Introduction" > (which is the current link_title) and use site-wide uservalues to > define the site title. > > Thanks again for your continued patience and support! > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys -- and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > ------------------------------------------------------------------------ > > _______________________________________________ > Rest2web-develop mailing list > Res...@li... > https://lists.sourceforge.net/lists/listinfo/rest2web-develop > |
From: Michael F. <fuz...@vo...> - 2006-08-05 15:21:46
|
Michael Foord wrote: > martin f krafft wrote: > >> also sprach Michael Foord <mi...@pc...> [2006.08.05.1426 +0100]: >> >> >>> Which is perhaps a little ugly. :-) >>> >>> The better way of achieving this is to provide uservalues in your site >>> config file. These are already available to every page. >>> >>> >> by site config file, you mean .ini file? >> >> >> > Yes. > > >>> You can't access the restindex or uservalues of pages through >>> indextree. >>> >>> >> Mh, this is not what I wanted to hear... would it be possible to add >> this? I think it would just make it a whole lot more flexible, >> especially since indextree seems to be the structure representing >> the entire site and hence needs to be used for a lot of different >> functions. >> >> > > Don't forget that rest2web is built top down. The indextree only > contains information for pages/directories above the one currently being > rendered, not for the whole site. > > I've now (experimentally) added the restindex and uservalues for each > page into the indextree. Now checked in. > As this is experimental, encoding is not handled for this value. I think they are still in the source encoding. Michael > Please let me know if this works for you. > > Fuzzyman > http://www.voidspace.org.uk/python/index.shtml > > >> >> >>> Every page in indextree has a 'link-title'. If this hasn't been >>> explicitly set in the restindex of a page, it defaults to the page title. >>> >>> What other values do you need access to ? >>> >>> >> Well, the page-title if link-title has been set. :) >> >> But I guess I could also just name my /index.txt "Introduction" >> (which is the current link_title) and use site-wide uservalues to >> define the site title. >> >> Thanks again for your continued patience and support! >> >> >> ------------------------------------------------------------------------ >> >> ------------------------------------------------------------------------- >> Take Surveys. Earn Cash. Influence the Future of IT >> Join SourceForge.net's Techsay panel and you'll get the chance to share your >> opinions on IT & business topics through brief surveys -- and earn cash >> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV >> ------------------------------------------------------------------------ >> >> _______________________________________________ >> Rest2web-develop mailing list >> Res...@li... >> https://lists.sourceforge.net/lists/listinfo/rest2web-develop >> >> > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys -- and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Rest2web-develop mailing list > Res...@li... > https://lists.sourceforge.net/lists/listinfo/rest2web-develop > > |
From: martin f k. <ma...@ma...> - 2006-08-05 15:33:08
|
also sprach Michael Foord <fuz...@vo...> [2006.08.05.1609 +010= 0]: > Don't forget that rest2web is built top down. The indextree only=20 > contains information for pages/directories above the one currently being= =20 > rendered, not for the whole site. Well, uh, doesn't it contain the pages list which I could recurse to the leafs? In any case, I think it's okay to be top-down. I can't think of a use when a page needs to know about its children other than that they exist (for purpose of a table of contents or sidebar). > I've now (experimentally) added the restindex and uservalues for each=20 > page into the indextree. Now checked in. >=20 > Please let me know if this works for you. Looks exactly like what I had in mind! Thanks! --=20 martin; (greetings from the heart of the sun.) \____ echo mailto: !#^."<*>"|tr "<*> mailto:" net@madduck =20 spamtraps: mad...@ma... =20 remember, half the people you know are below average. |
From: Michael F. <fuz...@vo...> - 2006-08-05 15:38:38
|
martin f krafft wrote: > also sprach Michael Foord <fuz...@vo...> [2006.08.05.1609 +0100]: > >> Don't forget that rest2web is built top down. The indextree only >> contains information for pages/directories above the one currently being >> rendered, not for the whole site. >> > > Well, uh, doesn't it contain the pages list which I could recurse to > the leafs? > indextree is built specially. All encodings are turned into the encoding of the page being rendered and all links are made relative to the current page. It currently just goes up the tree - not into all the leafs (leaves ?). To do so would slow down site generation. All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml > In any case, I think it's okay to be top-down. I can't think of > a use when a page needs to know about its children other than that > they exist (for purpose of a table of contents or sidebar). > > >> I've now (experimentally) added the restindex and uservalues for each >> page into the indextree. Now checked in. >> >> Please let me know if this works for you. >> > > Looks exactly like what I had in mind! > > Thanks! > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys -- and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > ------------------------------------------------------------------------ > > _______________________________________________ > Rest2web-develop mailing list > Res...@li... > https://lists.sourceforge.net/lists/listinfo/rest2web-develop > |
From: Michael F. <fuz...@vo...> - 2006-08-05 15:45:54
|
martin f krafft wrote: > also sprach Michael Foord <fuz...@vo...> [2006.08.05.1609 +0100]: > >> Don't forget that rest2web is built top down. The indextree only >> contains information for pages/directories above the one currently being >> rendered, not for the whole site. >> > > Well, uh, doesn't it contain the pages list which I could recurse to > the leafs? > > In any case, I think it's okay to be top-down. I can't think of > a use when a page needs to know about its children other than that > they exist (for purpose of a table of contents or sidebar). > > If i ever get the time (and this release has taken longer than expected ;-), rest2web will be done in 'two passes'. It will cache generated pages and so be able to skip rebuilding pages that haven't changed. The whole site will be available to all pages. This will enable the auto-generation of contents pages/sitemaps etc... None of this is technically very difficult. Given my other priorities it may be many months before I can return to it though. :-( Fuzzyman http://ww.voidspace.org.uk/python/index.shtml >> I've now (experimentally) added the restindex and uservalues for each >> page into the indextree. Now checked in. >> >> Please let me know if this works for you. >> > > Looks exactly like what I had in mind! > > Thanks! > > |
From: martin f k. <ma...@ma...> - 2006-08-05 21:05:43
|
Michael, I see restutils.encode uses the string encode function. I don't think this is what you want. < madduck> so i am baffled < madduck> >>> type('bla'.encode('utf-8')) < madduck> <type 'str'> < cracki> encode returns 8 bit < madduck> or even worse, < madduck> >>> type(u'bla'.encode('utf-8')) < madduck> <type 'str'> < cracki> you want unicode("bla") < cracki> encode encodes to binary representations < madduck> what's the point of "encode('utf-8')" then? < cracki> unicode("foo", "utf-8") < cracki> encode(u"someunicodestr", "weirdencoding") transforms to a=20 binary representation < cracki> in memory, unicode strings are multibyte, constant width Please also see http://docs.python.org/tut/node5.html#SECTION005130000000000000000 http://www.reportlab.com/i18n/python_unicode_tutorial.html The reason I am posting this is because I am getting an error UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 2555: ordinal not in range(128) This is due to a file that says "Z=FCrich", and the file itself is UTF-8, as is the template: lapse:~/phd/web> head -15 imprint.txt = [390] restindex encoding: utf8 template-encoding:=20 /restindex [...] 8050 Z=FCrich The exception is thrown in line 75 of embedded_code.py: template =3D template.replace(occ, value) when template holds the template text just after body had been filled in with the result from the imprint.txt transformed to HTML. Template is a str, not a unicode object, which is the root of all evil. Am I doing something wrong? --=20 martin; (greetings from the heart of the sun.) \____ echo mailto: !#^."<*>"|tr "<*> mailto:" net@madduck =20 spamtraps: mad...@ma... =20 "violence is the last refuge of the incompetent" -- isaac asimov |
From: Michael F. <fuz...@vo...> - 2006-08-06 16:24:40
|
martin f krafft wrote: > Michael, > > I see restutils.encode uses the string encode function. I don't > think this is what you want. > > < madduck> so i am baffled > < madduck> >>> type('bla'.encode('utf-8')) > < madduck> <type 'str'> > < cracki> encode returns 8 bit > < madduck> or even worse, > < madduck> >>> type(u'bla'.encode('utf-8')) > < madduck> <type 'str'> > < cracki> you want unicode("bla") > < cracki> encode encodes to binary representations > < madduck> what's the point of "encode('utf-8')" then? > < cracki> unicode("foo", "utf-8") > < cracki> encode(u"someunicodestr", "weirdencoding") transforms to a > binary representation > < cracki> in memory, unicode strings are multibyte, constant width > > Please also see > http://docs.python.org/tut/node5.html#SECTION005130000000000000000 > http://www.reportlab.com/i18n/python_unicode_tutorial.html > > Another good tutorial on Unicode : http://www.pyzine.com/Issue008/Section_Articles/article_Encodings.html :-) > The reason I am posting this is because I am getting an error > > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in > position 2555: ordinal not in range(128) > > This is due to a file that says "Zürich", and the file itself is > UTF-8, as is the template: > > lapse:~/phd/web> head -15 imprint.txt [390] > restindex > encoding: utf8 > template-encoding: > /restindex > [...] > 8050 Zürich > > The exception is thrown in line 75 of embedded_code.py: > > template = template.replace(occ, value) > > when template holds the template text just after body had been > filled in with the result from the imprint.txt transformed to HTML. > Template is a str, not a unicode object, which is the root of all > evil. > > Am I doing something wrong? > I think it is the other way round, by the time they are rendered they should all be byte-strings rather than unicode. Anyway, I'm going round in circles trying to chase this one down. Can you try it with an explicit 'output-encoding' of 'utf-8' and see if you have the same problem. Thanks Michael http://www.voidspace.org.uk/python/index.shtml > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys -- and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > ------------------------------------------------------------------------ > > _______________________________________________ > Rest2web-develop mailing list > Res...@li... > https://lists.sourceforge.net/lists/listinfo/rest2web-develop > |
From: Michael F. <fuz...@vo...> - 2006-08-06 16:50:19
|
Michael Foord wrote: > martin f krafft wrote: > >> Michael, >> >> I see restutils.encode uses the string encode function. I don't >> think this is what you want. >> >> < madduck> so i am baffled >> < madduck> >>> type('bla'.encode('utf-8')) >> < madduck> <type 'str'> >> < cracki> encode returns 8 bit >> < madduck> or even worse, >> < madduck> >>> type(u'bla'.encode('utf-8')) >> < madduck> <type 'str'> >> < cracki> you want unicode("bla") >> < cracki> encode encodes to binary representations >> < madduck> what's the point of "encode('utf-8')" then? >> < cracki> unicode("foo", "utf-8") >> < cracki> encode(u"someunicodestr", "weirdencoding") transforms to a >> binary representation >> < cracki> in memory, unicode strings are multibyte, constant width >> >> Please also see >> http://docs.python.org/tut/node5.html#SECTION005130000000000000000 >> http://www.reportlab.com/i18n/python_unicode_tutorial.html >> >> >> > Another good tutorial on Unicode : > > http://www.pyzine.com/Issue008/Section_Articles/article_Encodings.html > > :-) > > >> The reason I am posting this is because I am getting an error >> >> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in >> position 2555: ordinal not in range(128) >> >> This is due to a file that says "Zürich", and the file itself is >> UTF-8, as is the template: >> >> lapse:~/phd/web> head -15 imprint.txt [390] >> restindex >> encoding: utf8 >> template-encoding: >> /restindex >> [...] >> 8050 Zürich >> >> The exception is thrown in line 75 of embedded_code.py: >> >> template = template.replace(occ, value) >> >> when template holds the template text just after body had been >> filled in with the result from the imprint.txt transformed to HTML. >> Template is a str, not a unicode object, which is the root of all >> evil. >> >> Am I doing something wrong? >> >> > I think it is the other way round, by the time they are rendered they > should all be byte-strings rather than unicode. > > Anyway, I'm going round in circles trying to chase this one down. > > Can you try it with an explicit 'output-encoding' of 'utf-8' and see if > you have the same problem. > Even worse - when I make a test case, it works ! I have two files (index.txt and imprint.txt). imprint.txt just has your 'Zürich' in it - but they both have the same restindexes... I took great pains to make sure it was *genuinely* encoded with utf-8 (for example, in the email you sent it was 'latin-1', but this is probably irrelevant). This means the problem is something to do with the template - possibly the uservalues are still in unicode or something. (If you try to mix unicode and byte-strings then Python will try to decode all the byte-strings to unicode using the ascii codec, this would cause the exception you saw.) I'm going to see if I can isolate the bug with the template... Michael > Thanks > > Michael > http://www.voidspace.org.uk/python/index.shtml > > >> >> ------------------------------------------------------------------------ >> >> ------------------------------------------------------------------------- >> Take Surveys. Earn Cash. Influence the Future of IT >> Join SourceForge.net's Techsay panel and you'll get the chance to share your >> opinions on IT & business topics through brief surveys -- and earn cash >> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV >> ------------------------------------------------------------------------ >> >> _______________________________________________ >> Rest2web-develop mailing list >> Res...@li... >> https://lists.sourceforge.net/lists/listinfo/rest2web-develop >> >> > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys -- and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Rest2web-develop mailing list > Res...@li... > https://lists.sourceforge.net/lists/listinfo/rest2web-develop > > |
From: Michael F. <fuz...@vo...> - 2006-08-06 16:51:18
|
Michael Foord wrote: > martin f krafft wrote: > >> Michael, >> >> I see restutils.encode uses the string encode function. I don't >> think this is what you want. >> >> < madduck> so i am baffled >> < madduck> >>> type('bla'.encode('utf-8')) >> < madduck> <type 'str'> >> < cracki> encode returns 8 bit >> < madduck> or even worse, >> < madduck> >>> type(u'bla'.encode('utf-8')) >> < madduck> <type 'str'> >> < cracki> you want unicode("bla") >> < cracki> encode encodes to binary representations >> < madduck> what's the point of "encode('utf-8')" then? >> < cracki> unicode("foo", "utf-8") >> < cracki> encode(u"someunicodestr", "weirdencoding") transforms to a >> binary representation >> < cracki> in memory, unicode strings are multibyte, constant width >> >> Please also see >> http://docs.python.org/tut/node5.html#SECTION005130000000000000000 >> http://www.reportlab.com/i18n/python_unicode_tutorial.html >> >> >> > Another good tutorial on Unicode : > > http://www.pyzine.com/Issue008/Section_Articles/article_Encodings.html > > :-) > > >> The reason I am posting this is because I am getting an error >> >> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in >> position 2555: ordinal not in range(128) >> >> This is due to a file that says "Zürich", and the file itself is >> UTF-8, as is the template: >> >> lapse:~/phd/web> head -15 imprint.txt [390] >> restindex >> encoding: utf8 >> template-encoding: >> /restindex >> [...] >> 8050 Zürich >> >> The exception is thrown in line 75 of embedded_code.py: >> >> template = template.replace(occ, value) >> >> when template holds the template text just after body had been >> filled in with the result from the imprint.txt transformed to HTML. >> Template is a str, not a unicode object, which is the root of all >> evil. >> >> Am I doing something wrong? >> >> > I think it is the other way round, by the time they are rendered they > should all be byte-strings rather than unicode. > > Anyway, I'm going round in circles trying to chase this one down. > > Can you try it with an explicit 'output-encoding' of 'utf-8' and see if > you have the same problem. > Even worse - when I make a test case, it works ! I have two files (index.txt and imprint.txt). imprint.txt just has your 'Zürich' in it - but they both have the same restindexes... I took great pains to make sure it was *genuinely* encoded with utf-8 (for example, in the email you sent it was 'latin-1', but this is probably irrelevant). This means the problem is something to do with the template - possibly the uservalues are still in unicode or something. (If you try to mix unicode and byte-strings then Python will try to decode all the byte-strings to unicode using the ascii codec, this would cause the exception you saw.) I'm going to see if I can isolate the bug with the template... By the way - I see your problem with uservalues. In r2w.ini, you need to put them into a uservalues section : [uservalues] site_title = Method diffusion in large open source projects site_subtitle = Ph.D. research by Martin F. Krafft Michael > Thanks > > Michael > http://www.voidspace.org.uk/python/index.shtml > > >> >> ------------------------------------------------------------------------ >> >> ------------------------------------------------------------------------- >> Take Surveys. Earn Cash. Influence the Future of IT >> Join SourceForge.net's Techsay panel and you'll get the chance to share your >> opinions on IT & business topics through brief surveys -- and earn cash >> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV >> ------------------------------------------------------------------------ >> >> _______________________________________________ >> Rest2web-develop mailing list >> Res...@li... >> https://lists.sourceforge.net/lists/listinfo/rest2web-develop >> >> > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys -- and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Rest2web-develop mailing list > Res...@li... > https://lists.sourceforge.net/lists/listinfo/rest2web-develop > > |
From: martin f k. <ma...@ma...> - 2006-08-06 00:20:19
|
also sprach Michael Foord <fuz...@vo...> [2006.08.05.1609 +010= 0]: > >>The better way of achieving this is to provide uservalues in your site= =20 > >>config file. These are already available to every page. > > > >by site config file, you mean .ini file? > > =20 > Yes. How do I read them? I tried for a while and reread the entire docs. Sorry, but I couldn't figure it out. --=20 martin; (greetings from the heart of the sun.) \____ echo mailto: !#^."<*>"|tr "<*> mailto:" net@madduck =20 spamtraps: mad...@ma... =20 "i hate vulgar realism in literature. the man who could call a spade a spade should be compelled to use one. it is the only thing he is fit for." -- oscar wilde |
From: Michael F. <fuz...@vo...> - 2006-08-06 13:02:52
|
martin f krafft wrote: > also sprach Michael Foord <fuz...@vo...> [2006.08.05.1609 +0100]: > >>>> The better way of achieving this is to provide uservalues in your site >>>> config file. These are already available to every page. >>>> >>> by site config file, you mean .ini file? >>> >>> >> Yes. >> > > How do I read them? I tried for a while and reread the entire docs. > Sorry, but I couldn't figure it out. > > You *should* be able to do the following : Put something like this in your config file : [uservalues] site_wide_title = 'A nice site title' Then in your templates/pages you should just be able to use the name ``site_wide_title`` directly, it should be in your namespace. Let me know if this doesn't work and I will fix it. Michael > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys -- and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > ------------------------------------------------------------------------ > > _______________________________________________ > Rest2web-develop mailing list > Res...@li... > https://lists.sourceforge.net/lists/listinfo/rest2web-develop > |
From: martin f k. <ma...@ma...> - 2006-08-06 21:10:15
|
If I run r2w with -w, I still get to see ---8<--- rest2web version 0.5.0 beta1 Running rest2web the Site Builder. Sun Aug 6 22:05:28 2006 Time taken to build site was 1.482 seconds. 5 files processed. ---8<--- The --help output says: -w Display warnings only. Somehow I think there's an inconsistency. :) Cheers, PS: Here's a good example docbook manpage: http://madduck.net/~madduck/scratch/__tmp__iptables-apply.dbk 4497 4c5e8829ba6c644d363dce0e51f25d3e --=20 martin; (greetings from the heart of the sun.) \____ echo mailto: !#^."<*>"|tr "<*> mailto:" net@madduck =20 spamtraps: mad...@ma... =20 "there are lots of reasons not to use linux. there just aren't any good ones." --steven j. vaughan-nichols |
From: Michael F. <fuz...@vo...> - 2006-08-06 21:58:59
|
martin f krafft wrote: > If I run r2w with -w, I still get to see > > ---8<--- > rest2web version 0.5.0 beta1 > Running rest2web the Site Builder. > Sun Aug 6 22:05:28 2006 > > > Time taken to build site was 1.482 seconds. > 5 files processed. > ---8<--- > > The --help output says: > > -w Display warnings only. > > Somehow I think there's an inconsistency. :) > > Ok - I'll move the level of those messages to INFO. > Cheers, > > PS: Here's a good example docbook manpage: > Youch... :-p Oh well, time to find a good tutorial somewhere. I'll write a manpage for r2w.py - but it will be a simple description and an overview of the command line options. All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml > http://madduck.net/~madduck/scratch/__tmp__iptables-apply.dbk > 4497 4c5e8829ba6c644d363dce0e51f25d3e > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys -- and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > ------------------------------------------------------------------------ > > _______________________________________________ > Rest2web-develop mailing list > Res...@li... > https://lists.sourceforge.net/lists/listinfo/rest2web-develop > |
From: martin f k. <ma...@ma...> - 2006-08-07 15:27:22
|
also sprach Michael Foord <fuz...@vo...> [2006.08.06.1852 +010= 0]: > I found the problem. The uservalues were going in as unicode. I have=20 > sorted that, and added an extra safeguard against similar problems. I can confirm that the problem does not exist in current SVN anymore. --=20 martin; (greetings from the heart of the sun.) \____ echo mailto: !#^."<*>"|tr "<*> mailto:" net@madduck =20 spamtraps: mad...@ma... =20 a c programmer asked whether computers have buddha's nature. as the answer, the master did "rm -rf" on the programmer's home directory. and then the c programmer became enlightened... |