[issue33342] urllib IPv6 parsing fails with special characters in passwords
Terrence Brannon added the comment: Also note, if SQLAlchemy gives any guidance, then note that SA unquotes both the username and password of the URL: https://github.com/sqlalchemy/sqlalchemy/blob/master/lib/sqlalchemy/engine/url.py#L274 -- ___ Python tracker <https://bugs.python.org/issue33342> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue33342] urllib IPv6 parsing fails with special characters in passwords
Terrence Brannon added the comment: Regarding "RFC 2396 explicitly excludes the use of [ and ] in URLs. RFC 2732 <https://www.ietf.org/rfc/rfc2732.txt> defines the syntax for IPv6 URLs, and allows [ and ] ONLY in the host part. So I'd say that the behaviour is arguably correct (if somewhat unfortunate)" I would say that a square bracket CAN be used in the password, but that it should be urlencoded and that this library should perform a urldecode for both username and password, just as SQLAlchemy does. -- ___ Python tracker <https://bugs.python.org/issue33342> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue33342] urllib IPv6 parsing fails with special characters in passwords
Terrence Brannon added the comment: I would like to add to this bug - the password field on the URL cannot contain a pound sign or question mark or the parser incorrectly parses the URL, as this gist demonstrates - https://gist.github.com/metaperl/fc6f43bf6b9a9f874b8f27e29695e68c -- nosy: +metaperl ___ Python tracker <https://bugs.python.org/issue33342> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: push-style templating - an xml-like way to process xhtml
On Nov 2, 6:19 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote: Learning the handful of constructs is the same as learning a handful of API calls. The same goes for idiosyncrasies of e.g. inserting sub-templates or dealing with repeating content. I'm not sure I agree with you. 1 - the constructs probably call an internal API. that's two levels of complexity to implement 2 - the API is based directly on Python. Python has a much larger userbase and test suite than any template language 3 - the Python language has 15 years of refinement in what it offers as language constructs. Most of these template language are ad hoc products fashioned and re-fashioned over at most a 3 year period. -- http://mail.python.org/mailman/listinfo/python-list
Re: is this a good way to do imports ?
On Nov 5, 2:14 pm, Stef Mientki [EMAIL PROTECTED] wrote: Now I want to be able to use functions of file2 in file1, and vice-versa. It sounds like __all__ in __init__.py would work: http://www.python.org/doc/2.5.2/tut/node8.html#SECTION00840 If not, then pkgutil might of use? http://docs.python.org/library/pkgutil.html -- http://mail.python.org/mailman/listinfo/python-list
Re: push-style templating - an xml-like way to process xhtml
On Nov 5, 6:03 am, lkcl [EMAIL PROTECTED] wrote: * pyjamas (http://pyjs.org) - this is treating the web page and the wow. I had never heard of it, but it is _damned_ impressive. THANK YOU. I'm joining the club for my next webdev project! rock on. -- http://mail.python.org/mailman/listinfo/python-list
push-style templating - an xml-like way to process xhtml
Hello, The most common way of dynamically producing HTML is via template engines like genshi, cheetah, makotemplates, etc. These engines are 'inline' --- they intersperse programming constructs with the HTML document itself. An opposite approach to this form of dynamic HTML production is called push-style templating, as coined by Terence Parr: http://www.cs.usfca.edu/~parrt/papers/mvc.templates.pdf I keep a list of push-style templating solutions for all languages here: http://www.perlmonks.org/?node_id=674225#python And wanted to update the list of Python ones. Notes: - nagare has updated meld3 so the replace method can replace with entire HTML trees, not just plain text node. the author of meld3 (chrism) seems to be out of touch: he hasnt responded to my last 2 emails - basic xml processors are typically a bit too low level for convenient xhtml processing. for example, lxml and elementtree are both powerful xml processors, but webstring makes them much more useable for xhtml processing - the amara xml toolkit is very attractive. It shows how to climb on top of a low-level XML processing suite (the 4suite tools) and dynamically produce XHTML with Pythonic idioms. But I get the willies when the quickref tutorial is a broken link - http://uche.ogbuji.net/tech/4suite/amara/quickref - if there are any other new solutions in Python for this, I would like to know about them. -- http://mail.python.org/mailman/listinfo/python-list
Re: push-style templating - an xml-like way to process xhtml
Tino Wildenhain wrote: An opposite approach to this form of dynamic HTML production is called push-style templating, as coined by Terence Parr: Hm. a href=$attr.url$$attr.title$/a $if(attr.active)$ $attr.submenu:menuItem()$ $endif$ This looks ugly to me. It looks ugly to me too. Why not just using well tested TAL, which is also available for a number of languages? well, to me, TAL has to be learned. It is a language. Why is this an issue? Let me answer: I already know Python. I already know the XHTML standard. I do not wish to learn TAL. If you know Python, and can read the API to a high-quality XML processing toolkit, then you are done. TAL introduces another language and I have to learn its conventions and idiosyncrasies. Now, the same would be true of Terence Parr's StringTemplate engine. It is small, only 4 commands, but it litters the template with too much if you ask me. I like the approach of my own HTML::Seamstress --- object-oriented Perl and knowledge of an object-oriented tree-rewriting library is all you need: http://search.cpan.org/~tbone/HTML-Seamstress-5.0b/lib/HTML/Seamstress.pod#Text_substitution_via_replace_content()_API_call. http://en.wikipedia.org/wiki/Template_Attribute_Language In contrast there would be something like TSSL, which unfortunately never saw the light of the day yet :-) http://mail.zope.org/pipermail/zpt/2002-May/003304.html (This solution would not even touch the HTML directly) just remember: XHTML is a subset of XML and no one ever touches XML directly. There really is no reason for HTML to be handled any differently than XML. That TSSL is a nightmare. It's trying to be a programming language. And again, we already have Perl/Python, so why bother? You can avoid touching HTML by using Python. Thank you for writing. I enjoyed the discussion. -- http://mail.python.org/mailman/listinfo/python-list
Re: push-style templating - an xml-like way to process xhtml
Tino Wildenhain wrote: Terrence Brannon wrote: Tino Wildenhain wrote: An opposite approach to this form of dynamic HTML production is called push-style templating, as coined by Terence Parr: Hm. a href=$attr.url$$attr.title$/a $if(attr.active)$ $attr.submenu:menuItem()$ $endif$ This looks ugly to me. It looks ugly to me too. Why not just using well tested TAL, which is also available for a number of languages? well, to me, TAL has to be learned. It is a language. Why is this an issue? Let me answer: I already know Python. I already know the XHTML standard. I do not wish to learn TAL. If you know Python, and can read the API to a high-quality XML processing toolkit, then you are done. TAL introduces another language and I have to learn its conventions and idiosyncrasies. Your templating engine you have in your paper has yet another language. So where is the difference? if you are talking about StringTemplate, yes, that is a weakness of its approach. It is another language and it must be learned. Now, the same would be true of Terence Parr's StringTemplate engine. It is small, only 4 commands, but it litters the template with too much if you ask me. TAL's core has also only a few commands. So not much to learn. If thats to much, development is not for you I fear ;) no, Python is for me. Python handles all external data formats (csv, xml, imap, rdbms) without those formats requiring an embedded language. Dynamically unwinding HTML need be no different. if I am provided a high quality API for processing all those formats, I only need one for XHTML as well... meld3 is pretty good for example. TAL does not have as large a userbase or robust testing as Python does. I only want robust languages with large numbers of users. Language with quality libraries. Not language + mini-language. I like the approach of my own HTML::Seamstress --- object-oriented Perl and knowledge of an object-oriented tree-rewriting library is all you need: http://search.cpan.org/~tbone/HTML-Seamstress-5.0b/lib/HTML/Seamstress.pod#Text_substitution_via_replace_content()_API_call. Still you need to learn. There is no way out. Seamstress only requires learning an *API* --- that is not the same as learning another language and its limitations and idiosyncrasies. just remember: XHTML is a subset of XML and no one ever touches XML directly. There really is no reason for HTML to be handled any differently than XML. That TSSL is a nightmare. It's trying to be a programming language. And again, we already have Perl/Python, so why bother? You can avoid touching HTML by using Python. Mini languages is the correct term. And yes they have their purpose. (Think of SQL for example). yes mini-language. But let's look at SQL. SQL is pure. You dont stick Python in your database and unroll the database with it. You dont stick Python in SQL. And you dont put SQL in your tables. the keyword is *orthogonal* --- things may interact, but they should not mix. -- http://mail.python.org/mailman/listinfo/python-list
Re: code critique requested - just 60 lines
On Oct 2, 11:56 am, [EMAIL PROTECTED] wrote: Terrence Brannon, I suggest you to shorten a lot some of those very long lines. yes, I wanted to, but was not sure how to continue a line on the next line in Python. -- http://mail.python.org/mailman/listinfo/python-list
Re: code critique requested - just 60 lines
On Oct 2, 11:09 am, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: On Thu, 02 Oct 2008 07:51:30 -0700, Terrence Brannon wrote: Basically, using non-strict dictionary keys can lead to bugs, so that worried me. What's a non-strict dictionary key? In Perl, you can pre-define what keys are allowed in a dictionary. That way, mis-spelling the dict key doesnt lead to accessing something didnt mean to. -- http://mail.python.org/mailman/listinfo/python-list
how best to use a dictionary in this function?
Ok, here is some code: def calc_profit(std_clicks, vip_clicks, ad_rate=200, upline_status=None): payout = {} payout_std = std_clicks * rates['std'].per_click payout_vip = vip_clicks * rates['vip'].per_click ... now note that std_clicks and vip_clicks are passed to the function. Now, I improved this function this way: def calc_profit(std_clicks, vip_clicks, ad_rate=200, upline_status=None): clicks = {} clicks['std'] = std_clicks clicks['vip'] = vip_clicks payout = {} for member_type in rates: payout[member_type] = clicks[member_type] * rates[member_type].per_click But it seems wasteful to have to re-bind the passed-in function args to a dictionary in the function. I think there must be some way to improve this code and get the dictionary built without me manually doing it... I know there is something like *args, or **args, but since docs.python.org is down, I cant check. -- http://mail.python.org/mailman/listinfo/python-list
code critique requested - just 60 lines
Hi, I would like some feedback on how you would improve the following program: http://www.bitbucket.org/metaperl/ptc_math/src/21979c65074f/payout.py Basically, using non-strict dictionary keys can lead to bugs, so that worried me. Also, I'm not sure that my code is as crisp and concise as it could be. I also did not like the long string representation in the Scenerio class. It is hard to read and error-prone to code. Any feedback on how you would've written this differently is welcome, either by commenting below, or by checking out the repo and checking it back in! class Rates: def __init__(self, per_click, per_ref_click): self.per_click = per_click self.per_ref_click = per_ref_click def __str__(self): return 'per_click: %.2f per_ref_click: %.2f' % (self.per_click, self.per_ref_click) ad_rate = 200 # 2 dollars for 100 clicks # http://code.activestate.com/recipes/278259/ def sumDict(d): return reduce(lambda x,y:x+y, d.values()) rates = {} rates['std'] = Rates(per_click=1,per_ref_click=0.5) rates['vip'] = Rates(per_click=1.25, per_ref_click=1.25) class Scenario: def __init__(self, std_clicks, vip_clicks, upline_status): self.clicks = {} self.payout = {} self.ad_rate = 200 self.clicks['std'] = std_clicks self.clicks['vip'] = vip_clicks self.upline_status = upline_status def calc_profit(self): for member_type in rates: self.payout[member_type] = self.clicks[member_type] * rates[member_type].per_click if self.upline_status is None: self.payout['upline'] = 0 else: self.payout['upline'] = sumDict(self.clicks) * rates[upline_status].per_ref_click #print rates: %s self.clicks: %d upline payout: %.1f\n % (rates[upline_status], sumDict(self.clicks), self.payout['upline']) return ad_rate - sumDict(self.payout) def __str__(self): profit = self.calc_profit() return 'upline_status: %s upline_payout: %.1f\n\tstd_clicks: %d std_payout %.1f vip_clicks: %d vip_payout: %.1f\n\t\tProfit: %.1f \n' % (self.upline_status, self.payout['upline'], self.clicks['std'], self.payout['std'], self.clicks['vip'], self.payout['vip'], profit) scenario = [] for upline_status in [None, 'std', 'vip']: for vip_clicks in [0, 25, 50, 75, 100]: std_clicks = 100 - vip_clicks scenario.append(Scenario(std_clicks, vip_clicks, upline_status)) # really, we could've printed the objects as they were made, but for debugging, I kept creation and # printing as separate steps for s in scenario: print s -- http://mail.python.org/mailman/listinfo/python-list
re.compile versus r''
Hello, I'm using a tool (PLY) which apparently expects the tokens to be created using r'' But because one token is a rather complex regular expression, I want to create the regular expression programmatically. How can I generate a string and then create something of the same type that the r'' function does? Concretely, in the program below, consonant is not the same type as t_NAME, but I assume that it needs to be for PLY to use it for tokenizing: import re t_NAME = r'[a-zA-Z_][a-zA-Z0-9_]*' guttural = 'kh?|gh?|\n' palatal= '(?:chh?|jh?|\~n)' cerebral = '\.(?:th?|dh?|n)' dental = '(?:th?|dh?|n)' semivowel = '[yrlv]' sibilant = '[\\.]?s' aspirant = 'h' consonant = re.compile('|'.join([guttural , palatal , cerebral , dental , semivowel , sibilant , aspirant])) print consonant print t_NAME -- http://mail.python.org/mailman/listinfo/python-list
Re: re.compile versus r''
Oh my god, how embarrassing. the r'' notation is to create raw string http://www.swc.scipy.org/lec/glossary.html#gdef-raw_string I thought it was some form of blessing a string into a regular expression class. -- http://mail.python.org/mailman/listinfo/python-list
Re: 2d graphics - drawing a vescica piscis in Python
On Jun 17, 3:45 pm, Terrence Brannon [EMAIL PROTECTED] wrote: Hello, I have written a program to draw a vescica piscis http:// en.wikipedia.org/wiki/Vesica_piscis actually, I mis-spelled the term. It should be vesica piscis or vesica pisces. I put a c after the s -- vescica --- and that is wrong and made it hard for me to find this post the next day. now others will be able to search the archives and find it. -- http://mail.python.org/mailman/listinfo/python-list
2d graphics - drawing a vescica piscis in Python
Hello, I have written a program to draw a vescica piscis http:// en.wikipedia.org/wiki/Vesica_piscis from turtle import * def main(): setup(width=400, height=400) r = 50 color(black) circle(r) color(white) forward(r) color(black) circle(r) x = raw_input('please enter a string:') if __name__ == '__main__': main() ... but I would like the following: 1 - I dont like how the bottom of the first circle is not complete 2 - I would like for the left circle to be filled with verticle lines and the right circle to be filled with horizontal lines, so that the vescica piscis is cross-hatched. And finally, is turtle the best option for what I'm doing? pyCairo looked a bit hard to get going with, but very powerful. sping looked a bit alpha/beta. -- http://mail.python.org/mailman/listinfo/python-list
Incremental Progress Report object/closure?
'lo all, I'm looking for something that gives feedback to the screen every X iterations, reporting Time elapsed: 0:00:00 X,XXX,XXX records done. speed /second. [Action Label] Such a thingy is useful when one is cranking away at million record flat files and one wants to provide feedback to the user lest he bash away at the interrupt key in fear of his machine being locked up. All the best mates, -- meta -- http://mail.python.org/mailman/listinfo/python-list