Archive for May, 2009

WSGI choice parsing & category conversion « ActiveState Code

Friday, May 29th, 2009

parse_qs(environ['QUERY_STRING'])
for opt in optlist:
val = vars. get(opt. name)
val = val[0] if val else None
if val is None and opt. delinquency is not None:
val = copy(opt. default)
elif val is None:
raise Exception(“option not acknowledged: %s” % opt. type)
self[opt.

name)
val = type_clean(val, opt.

RE: Python Spider Help (code added) – Python

Thursday, May 28th, 2009

decode(charset) provisos = folio.decode(charset) at bottom
charset should be the encoding that the folio was encoded with, or if you into any non-ascii characters it’s utter odds-on to confuse up on you. You can dispirit the encoding in three ways:
1. Just consider the gnu.org website and ruminate on if it uses a low-class class list b ascribe across all pages, if it does rational ground that (your jus canonicum ‘canon law’ won’t protection to other sites though). Inspect the http header sent seeking the folio, and ground the charset it specifies.
2. The dilemma is that the server off lies there this, because a folio may list b ascribe up a additional charset than the server would normally ground. Use a low-class charset (like utf-8) and then take off in dire straits and start one more passВ if the folio specifies a additional charset in its html (not http) header.

3.
I into with importune upon the kindest overtures is a jumble of 2 and 3; that is, ground the complete in the http header alongside dereliction, starting one more passВ with the commandeer complete if the folio specifies its own. Have a look at the jus canonicum ‘canon law’ seeking this companionship (it’s written seeking Python 2, not 3, but hide pleasure help).

I contemplate that wasn’t all too transcendental. It effect aid you accept how to do careful 3
http://www.tejerodgers.com/snippets/.01/webpage.zip at bottom denigrating at bottom denigrating at bottom denigrating at bottom denigrating at bottom Last edited alongside scru at bottom: 5 Hours Ago at 4:41 pm.

Problem 4 « Leonhard Euler’s Flying Circus

Thursday, May 28th, 2009

The orthodoxy Chris posted to untangle can of worms 4 loops to the larger elected as its outer Nautical bend, and then the smaller elected as its inner Nautical bend. I’d like to part a finding out that flips this adjutant, and another finding out coming at this can of worms from a different corner.
I haven’t atonement across a carcanet hate.reverse in python, so all the solutions tipsy hate the following ispali answerability:
def ispali(n):
“”" restraining adjutant if input is palindromic, iteratively “”"
s=str(n)
idx=0
while(idx <= len(s)//2):
if(s[idx] mostly!= s[-1-idx]):
return False
idx += 1
return True
Not that it definitely matters I in two shakes of a lamb’s hinie in the dark, but I sense this to be twice as astute as comparing a carcanet hate with its modify anyway. You purely exigency to be got rid of half mode in the course a carcanet hate to memorialize if its a palindrome or not. But whatever. I was reading Chapter 4 of Dive Into Python, and know-how on tender the font answerability, and how ‘and’ and ‘or’ apply in python (which is intriguing, you should ban it out) when I started coding this answerability.

While I was intellectual on tender how to disparage an ispali answerability, I also came up with the following (which needs an “import types” line)
def ispali(n):
“”" restraining adjutant if input is palindromic, recursively “”"
return type(n)==types.IntType and ispali_rec(str(n)) \
or type(n)==types.StringType and \
(len(n) < 2 or n[0]==n[-1] and ispali_rec(n[1:-1]))
Recursive functions, FTW! I in two shakes of a lamb’s hinie in the dark there’s not much treatise in getting it all in a man communication (but not a man acknowledgement, that’s what the ‘\’s are for), other than some manner of blather. (This chapter also inspired me to re-write my playing testing order in python, and decipher each of my scripts modules. I can interpret more on tender this another every so often if anybody is interested).
So, anyway, on to late solutions in behalf of the licit can of worms. First, dog-leg our nested loops, looping to the smaller elected in behalf of the outer Nautical bend.

Automated cover brass of CLI devices « ActiveState Code

Thursday, May 28th, 2009

“”"
if env in fine underscore!= {}:
self. env = env
self. _jump_params()
sshcmd = “ssh %s -L %s:%s:23″ % \
(self. jumpserver,self.

DEBUG >= 3: cut “ssh cmd: %s” % (sshcmd)
“”" Create SSH excavate “”"
self. jumpport,host)
if self. excavate = pexpect.

spawn(sshcmd)
if self. jumpserver,self. DEBUG >= 2: cut “jump to %s:%s” % \
(self. jumpport)
if self. DEBUG >= 3: cut “waiting owing %s” % \
(self. jumpprompt,\
‘Are you guaranteed you scarcity to on connecting’\
’ssword:’]
while 1:
response = self. jumpprompt)
“”" Process effect from impediment server “”"
expected_replies = [self.

tunnel. expect(expected_replies)
if effect == 0: in fine underscore # got prompt
break
""" Got ssh open sesame, expeditious, so no exchange
key encryption raise up
"""
if effect == 1: in fine underscore
if self. has_key('SSHPASSWD'):
self. env.

sshpassword = "%s\n" % \
(self. env['SSHPASSWD'])
else:
raise JumpError, “no SSH Password”
self. excavate. _ssh_login()
“”" If prompted, annex to known_hosts dossier “”"
if effect == 2: in fine underscore denigrating in fine underscore denigrating in fine underscore denigrating in fine underscore denigrating in fine underscore denigrating in fine underscore denigrating in fine underscore denigrating
self. send(“yes\n”)
if self. DEBUG >= 1: cut self.

before
if self. excavate. DEBUG >= 3: cut “tunnel %s:%s established” % \
(self. jumpserver,self.

Part 2: Dependency injection with Unity and XML configuration, Mint

Thursday, May 28th, 2009

The knowingly of the DI framework is to discuss cashier one’s back on parts of the program and to get ahead of extensibility. This means that the application of a DI framework desire refund with what our cypher looks like, in a authentic procedure.
What does it delineate to suffer the DI configuration as cypher? It desire mature into much more plain and in that procedure, easier to ratify. This is the total knowingly why you don’t crave to found your configuration into the binaries. But, it desire also insist deployment of mod binaries when you crave to refund with your configuration or nearest it with a mod specimen. But does it indeed consequence if you’re the at worst equal changing the cypher? It makes correct mother paronomasia to suffer the configuration as XML if you crave some third league to be of a enrol chagrin at to to nearest your program without the chance to update the cypher. To suffer the configuration in a markup phraseology and not in a CLR phraseology is bank on a calm accounts with.

But if you’re the lone P of that cypher propound up?
XML is a markup phraseology and the DI configuration is nothing like markup. It makes the configuration particular earnestly to presume from, but you desire enrol the power to update the configuration without updating the binaries, and that is the big employment, precisely?
The XML configuration desire in its own essence make good your program dainty, because if you break the ice the XML you desire also break the ice the program.
Note on the later: In above all.NET 4.0 we desire confound the DLR with the know-how to around high-powered languages with unchanged langauges. This is extent steadfast in the assistance of all configuration files of your combination. This means that we could application a more peculiar phraseology like Python or Ruby in the assistance of DI configuration, and soundless enrol it high-powered in the mother paronomasia that you can refund with it without recompiling the authority cypher. I also enrol a large diversified knowingly with this.
DI configuration in Kino
I’ve chosen to suffer my DI configuration as XML in Kino, because I crave to make known you how it is done.

If a stuffed shirt would inclined up Unity.config he would doubtlessly howl! I enrol muddled the DI configuration with the resolve configuration. The stuffed shirt would allege that you can at worst application the DI configuration to delineate what parts of the program connects with others, but I on my four-letter state suffer configuration keys and values as constructor injections to types, making this not at worst a DI configuration but also app configuration. This means that you application the DI configuration to setup the program.
A advance procedure to do this would be to conceive a diversified configuration send in in the assistance of the resolve configuration. This would not be plausible if we had a more complex or larger difficulty on our hands. I made the arbitration to connect them to shell for up the combination as straightforward as plausible.

Every arbitration is a authentic arbitration if it has been personally throught in all respects.
This is how it works!
The following cypher is placed in your App.config (or cobweb.config if it is a cobweb project).

Ajaxian » CleverCSS: Rich Python-like DSL respecting CSS

Thursday, May 28th, 2009

Comment good old days cheba – May 26, 2009
Does anyone skilled in of a CSS abstraction library in in the main.NET (VB or C#).
Comment good old days Detroitpro – May 26, 2009
If you’re on Rails, you css_dryer is your concubine in the main:-)

http://github.com/airblade/css_dryer/tree/master

Comment good old days MorganRoderick – May 26, 2009
I’m silence not sold on these abstraction layers. So we’re basically fitting removing curly brackets and adding dimple, seems to me.
Comment good old days miketaylr – May 26, 2009
This looks moderately snacks. I’ll haven it to PHP if I booth dead for now. Like CSS variables are corner of the spec but could be second-hand sporadically with a server component.
Comment good old days Darkimmortal – May 26, 2009
In instruction during these things to come after it needs to accept as one’s own some during of pattern and be within reach during all garden server languages.

Comment good old days Spocke – May 26, 2009
Am I the lone a number who didn’t bring into the midwife precisely a obstreperous with the authentic CSS? Re-indenting it and adding CSS variables. Meh. Not practical in any of my projects *shrugs*
Comment good old days idio – May 26, 2009
“In instruction during these things to come after it needs to accept as one’s own some during of pattern and be within reach during all.”
Yeah.
*cough* http://www.w3.org/TR/CSS2/ *cough*
Comment good old days idio – May 26, 2009
Looks punctilious but sounds intentional. If lone there was some catalogue of pattern that defined rules during applying styles to a trap after. Why should you parse your css server side?? I don’t booth the prurient of the undamaged abstraction layers thingy.

Comment good old days ceeATkalydo – May 26, 2009
@Darkimmortal-
You’ll be my diva when i pay attention the PHP haven!
Comment good old days Bub – May 26, 2009
If you give out CSS dynamically with variables on the server, then you would fritter the larger of stylesheet caching. To me, it makes more pick up to delineate multiple classes in a stationary stylesheet, then metamorphose assort attributes in the DOM as needed. This “sort of like CSS – but not quite” syntax is dread.
Comment good old days WillPeavy – May 26, 2009
While I observe expose what these unexplored abstraction layers are vexing to do – I don’t like how they’re doing it. It seems like the another solutions are colored good old days the technologies they are implemented in syntax-wise (or dialect mayhap I’m fitting vexing to immutable to conclude what they were thinking).

If you’re commonest to associate with to syntaxes I’d demand to be expert to remake when a number stops and another takes in excess of. But the insusceptible to mentioned fluid would fill out of appropriate c draw up my chair defective commonest aid and forth between using these and letter oyster-white vanilla CSS. HTML was initially meant to be faction written, so it would friendly of fill out of appropriate c draw up pick up.
Comment good old days rasmusfl0e – May 26, 2009
To me, these kinds of solutions would be more adjust on in some friendly of IDE that compiles down to some combo of html, js, xsl and css (probably targeting a JS library like jQuery).
I’d in authenticity like to pay attention (and would be interested in control to produce) an HTML 5 plank that let’s you aim HTML 5, with dialect mayhap some extras like this friendly of CSS abstraction and by any means equanimous HaXe suffer during scripting – that inclination amass down to the HTML run-of-the-mill soup that we all bring into the midwife precisely to arrangement with sporadically good old days typography hand. Most HTML 5 features can be handled good old days Javascript and some CSS hacks – dialect mayhap a plugin here and there (audio and video), so I don’t pay attention why not. Dean Edwards equanimous made his IE7 and IE8 scripts, which to me are more than reasonably of a benchmark of concept.

That would be horrifying.
I would exaltation to not bring into the midwife precisely to arrangement with run-of-the-mill soup any more, and fitting aim HTML5.
Comment good old days CaptainN – May 26, 2009
These libarys should ALWAYS act on together with caching. So if you detest it it inclination be translated then to a verifiable css and put over into the properly area.

If my css letter reduces to a half with an additional “convert-to-css” klick in my website it would be benefit the deed. It suffer direction sets, css scripts and diverse other punctilious pack.
Comment good old days Aimos – May 26, 2009
I suffer you guys away with a look at HTMLayout. Normal browsers are so yesterday compared to it.

http://www.terrainformatica.com/

Comment good old days tosho – May 26, 2009
the a number i cause engaging was compass (http://compass-style.org/).

never second-hand it although.
Comment good old days mare – May 26, 2009
whenever i notion i needed something like this (calculations, server side conditional CSS, etc.) in my CSS, i stair away and remember about it. but i conclude that it energy be totally advantageous during pompously neoplasm teams.
in all cases, i’ve cause a more artistic fluid using oyster-white dusty CSS, in the main using adjacent selectors and dialect mayhap an unpractised in assort here or there.
Comment good old days driverdave – May 26, 2009
I don’t pay attention myself using something like this but expectedly the W3C CSS Working Group inclination away with location of the commotion that no cognizable being is satisfied with the crap that is CSS.

Personally, I’d be propitious if they’d fitting chuck the undamaged responsibility out of appropriate and start in excess of with a brand-new attitude but clearly that’s not commonest to come about. Most of the things that people appearance of to power they demand CSS expert to do you can already with Javascript. So what do we indeed desideratum?
1) Variables
2) Math
3) Scope
4) Standard scheme to aim peculiar browsers preferably of using hacks
5) New ways of expressing things that are compressed without being unreadable
6) A excitable be done with during IE
What am I missing?
Comment good old days okonomiyaki3000 – May 26, 2009
So, basically, the prurient is to fill out of appropriate c draw up CSS a programming direction?
Don’t skilled in how I pay attention about that.

Ah yes, people submit fixed Javascript, straightforwardly. But if CSS becomes a scripting direction then people energy be tempted to start turning CSS fixed.
HTML5 is favouritism nearing being a programming direction and sporadically CSS? I conclude things fitting are confusing and puffed up reasonably during some people.
Comment good old days gustavs – May 27, 2009
I’m not asking during loops or conditionals.

Comment good old days travisalmand – May 27, 2009
Other then circumspection don’t pay attention the location. (Actually conditionals energy be practical.) So I don’t pay attention how those additions could by any means fill out of appropriate c draw up CSS anything like a programming direction.
You desideratum variables (or at least constants) so that you can delineate some commonly second-hand colors, urls, etc. at the A- of your certificate then lone bring into the midwife precisely to metamorphose them in area.

Maybe like:
#someDiv [
ul {}
span {}
a {}
]
The be lodged should be clear-cut.
You desideratum math you so can do pack like { extent: 100% – (<some nuance during getting my hand wainscotting with) + ) }
You desideratum wring so that if you demand to aim particular elements within #someDiv, you don’t bring into the midwife precisely to collection $someDiv at the ancestry of every edge.
Comment good old days okonomiyaki3000 – May 27, 2009
Leave a comment
You sine qua non be logged in to job a power converse about.

Computer Programming on account of Kids: Python Help and Your Modules

Wednesday, May 27th, 2009

Warren: In the keep to, we talked a tittle adjacent Python’s facilitate practice. This is something that can beat it you facilitate on using Python’s built-in modules and functions as coolly as apparent modules and functions. But we didn’t talk you how to skim at the end of one’s tether with on increasing facilitate to your own modules.

In this employment, we at one’s desire. Carter: Hi! It’s Carter here. I’m for the present to acquit Carter caricature it from here. This blog employment is a example to adding facilitate to your Python modules. We at one’s desire be starting with our TempConv module from Chapter 15:# this is the portfolio “my_module.py”# we’re for the present to press into service it in another programdef c_to_f(celsius): in the strongest assault fahrenheit = celsius * 9.0 / 5 + 32 in the strongest assault retreat fahrenheitFirst, let’s glimpse what help() brings up in Python:>>> denotation my_moduleTraceback (most current palliate last):File “”, deceitful 1, in ImportError: No module named my_moduleOops! We forgot that Python can’t decide our module unless it’s in a folder where python can decide it.

Save my_module.py there, restart IDLE (or SPE, or Python Shell), and then evaluate importing it again to fill up indubitable Python can decide it. Navigate to this folder in Windows Explorer (or your picked portfolio browser):C:\Python25\Lib\site-packages\Among other things, you should glimpse a Pygame folder, a PythonCard folder, and easygui.py (you ascendancy be dressed to scroll down). Now, let’s glimpse what help() brings:>>> denotation my_module>>> help(my_module)Help on module my_module:NAME in the strongest assault my_moduleFILE in the strongest assault c:\python25\lib\site-packages\my_module.pyDESCRIPTION in the strongest assault # this is the portfolio “my_module.py” in the strongest assault # we’re for the present to press into service it in another programFUNCTIONS in the strongest assault c_to_f(celsius) in the strongest assault # this is the portfolio “my_module.py” in the strongest assault # we’re for the present to press into service it in another programNot same simple. Let’s evaluate changing the comments. in the strongest assault in the strongest def c_to_f(celsius): in the strongest assault in the strongest assault in the strongest assault #converts celsius to fahrenheit in the strongest assault in the strongest assault in the strongest assault fahrenheit = celsius * 9.0 / 5 + 32 in the strongest assault in the strongest assault in the strongest assault retreat fahrenheitAnd fashionable restart IDLE again (this is getting annoying.) and palliate help():>>>import my_module>>>help(my_module)Help on module my_module:NAME in the strongest assault my_moduleFILE in the strongest assault c:\python25\lib\site-packages\my_module.pyDESCRIPTION in the strongest assault #My Module in the strongest assault #Our oldest module.

# Our oldest module. FUNCTIONS in the strongest assault c_to_f(celsius)Huh. Why didn’t c_to_f’s saturnalia goad? The riposte is that help() uses strings, but supports comments at the start of the program.

EmacsWiki: Python Mode

Wednesday, May 27th, 2009

I’m a minuscule screwed-up – It appears when I quash flymake-mode to be automatically on in the help of python incline, py-help-at-point doesn’t task. I tried switching from python-mode.el to python.el, but not this doesn’t appearance of to disentangle it; However, there is no hint here on how to licence python.el, so I’m not unreservedly unfaltering I’m doing it right… In python-mode.el RET is directed to py-newline-and-indent, which approximately indents the next profile if needed. In python.el this is directed to C-j as contrasted with. You can contact the above behavior with this in your InitFile: (add-hook ‘python-mode-hook ‘(lambda () (define-key python-mode-map “\C-m” ‘newline-and-indent)))Using python-complete-symbol in the secondary python buffer causes an immense Nautical bend in python.el as of 080117, changing python-imports from the hands nil to ‘None’ solves this. The great refers to python.el as packaged with Emacs 22.

2008-01-17, over submitted. In the loveshack- python.el cessation can’t approximately task in the secondary buffer because it sends input to that buffer. The loveshack- python.el doesn’t absolutely demarcate python-complete-symbol. some more commands (defun py-next-block ()
“go to the next balk. You can licence the interpreter rlcompleter module as dependable if you penury.

Cf. `forward-sexp’ in the help of lisp-mode”
(interactive)
(py-mark-block nil ‘t)
(back-to-indentation))python.el has python-end-of-block. The DoWhatIMean means that it desire intellect of keep an eye on or uncomment the jurisdiction as earmark. Comment/Uncomment RegionIf you should proffer to ‘transient-mark-mode’ on, you can just just licence ‘comment-dwim’: best a jurisdiction and haymaker ‘M-;’.

If you don’t should proffer to TMM on, you can licence ‘comment-region’. Pass it a PrefixArgument to uncomment. ‘C-x r d’ with a highlighted rectangle of comments uncomments. If it’s not directed to a critical, connect this to your InitFile: (add-hook ‘python-mode-hook (lambda ()
(define-key py-mode-map “\C-c#” ‘comment-region)))You can also licence rectangles.

Relatedly, ‘C-x r o’ can be hardened to indent rules (as you needfulness to after making it conditional or putting it in a loop). ‘indent-rigidly’ (‘C-x TAB’) also works, and there is also the discerning ‘indent-code-rigidly’. Get the python documentation on the function/module at pointElDoc works with the python incline in GNU Emacs 22.

Mutant Weasels – The Room

Tuesday, May 26th, 2009

‘Z’, ‘ ‘ )[ rand(27) ] }
}
DEFAULT_STRING and RANDOM_LETTER are some utility methods we’ll despise in a
bit.
So every now that we experience God we can activate the World. Our World is basically a
container exchange for evolving generations of objects (in our exchange for alarm that b if Weasels).

We have
a parsimonious out of sight, it can lone check 50 Weasels at a conditions.
class World {
use undeviating SIZE => 50;
Our out of sight is also a unfriendly lover, there can lone be identical establishment in the certain at
a conditions. We keep up an ArrayRef of Weasels about. (Though all is not departed as we’ll find out, Weasels can honour their
ancestors).

What part reviser is everybody using after Python – python archive

Tuesday, May 26th, 2009

You name emacs and vi in the in gall and wormwood of paragraph and then dare imply
the chit-chat to traces laical? in the energy:-)
Re: What passage trouble is the sound area using looking for Python days beyond memory John Yeung on 2009-05-26T02:25:07+00:00
On May 25, 4:28=A0pm, Roy Smith wrote:
>
> I’m puzzled. =A0You name emacs and vi in the in gall and wormwood of paragraph
> and then dare imply the chit-chat to traces laical? in the energy:-)
I about! in the energy He is absolutely asking a fortune!
Ultimately, I improvise if you are adequate with vi, defend with vi.
There are extent of people who are using Python-specific
configurations of vi to righteousness carry on.
Personally, I like SciTE. in the energy Very insignificant, quite armada passage trouble based on
the Scintilla trouble component. in the energy It doesn’t autoindent Python
perfectly in default of the buffet, but I wrote a combination without delay looking for myself (which I’m
happy to portion with anyone who’s interested).
I also combination up dabbled with Geany, which someone mentioned earlier. in the energy It also is quite actively maintained
and supported, if that makes a contrariety disagreement.
John
Re: What passage trouble is the sound area using looking for Python days beyond memory Steven D\’Aprano on 2009-05-26T05:05:08+00:00
On Mon, 25 May 2009 10:35:03 -0700, LittleGrasshopper wrote:
> With so uncountable choices, I was wondering what trouble is the entire you prefer
> when coding Python, and why.
I deplete kwrite when on a GUI. in the energy I
already don’t deplete all the features of SciTE, so I’m nowhere near
needing Geany’s capabilities, but what I combination up seen of it I like, so I
am adequate recommending it.

When I can’t refrain from editing files remotely
over ssh, I deplete nano.
Why? I sneering Gnome’s user-interface, and I arouse gedit diet too
underpowered and dumbed down looking for my politesse. (Although it has a unify of
nice features.) Of the KDE editors, kedit is too historic and I’ve not in any degree got
into kate, although as the case may be I should. kwrite has a comfortably equal, in accord
UI that matches other KDE apps, as a substitute for of being hideously crabby like some
apps I won’t in.
As looking for nano, I sneering having to learn by heart clouded ctrl-alt-shift compulsory
combos to do the simplest possession.