Friday, November 8, 2013

comp.lang.python - 26 new messages in 8 topics - digest

comp.lang.python
http://groups.google.com/group/comp.lang.python?hl=en

comp.lang.python@googlegroups.com

Today's topics:

* OT: How to tell an HTTP client to limit parallel connections? - 7 messages,
5 authors
http://groups.google.com/group/comp.lang.python/t/a27aeccbb4cdfc08?hl=en
* chunking a long string? - 7 messages, 6 authors
http://groups.google.com/group/comp.lang.python/t/bfc1c8e53fafb268?hl=en
* pywin32 programming error on Win7 with shell.SHGetDesktopFolder, desktop.
BindToObject, desktop.GetDisplayNameOf - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/65acf69c88845011?hl=en
* To whoever hacked into my Database - 5 messages, 3 authors
http://groups.google.com/group/comp.lang.python/t/1459c9bdf9ab0ada?hl=en
* Algorithm that makes maximum compression of completly diffused data. - 1
messages, 1 author
http://groups.google.com/group/comp.lang.python/t/cf4b4e4ba592ec63?hl=en
* Count each unique element in list of lists - 3 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/b31b06b4e135aec3?hl=en
* Automate Google Drive SDK Authorization - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/903405986adb47b6?hl=en
* Programa no modo gráfico - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/60808e9c471c2c81?hl=en

==============================================================================
TOPIC: OT: How to tell an HTTP client to limit parallel connections?
http://groups.google.com/group/comp.lang.python/t/a27aeccbb4cdfc08?hl=en
==============================================================================

== 1 of 7 ==
Date: Fri, Nov 8 2013 9:39 am
From: Skip Montanaro


> What I really need is an HTTP header or meta-tag or something that I
> can use to tell clients to limit themselves to a single connection.
>
> I haven't been able to find such a thing, but I'm hoping I've
> overlooked something...

That will only go so far. Suppose you tell web browsers "no more than
3 connections", then get hit by 30 nearly simultaneous, but separate
clients. Then you still wind up allowing up to 90 connections.

There should be a parameter in your web server's config file to limit
the number of simultaneously active threads or processes. It's been a
long time for me, and you don't mention what brand of server you are
running, but ISTR that Apache has/had such parameters.

(Also, while this is off-topic for comp.lang.python, most people here
are a helpful bunch, and recognizing that it is off-topic, will want
to reply off-list. You don't give them that option with
"invalid@invalid.invalid" as an email address.)

Skip




== 2 of 7 ==
Date: Fri, Nov 8 2013 10:01 am
From: Grant Edwards


On 2013-11-08, Skip Montanaro <skip@pobox.com> wrote:
>> What I really need is an HTTP header or meta-tag or something that I
>> can use to tell clients to limit themselves to a single connection.
>>
>> I haven't been able to find such a thing, but I'm hoping I've
>> overlooked something...
>
> That will only go so far. Suppose you tell web browsers "no more than
> 3 connections", then get hit by 30 nearly simultaneous, but separate
> clients.

In practice, that doesn't happen. These servers are small, embedded
devices on internal networks. If it does happen, then those clients
are all going to have to queue up and wait.

> Then you still wind up allowing up to 90 connections.

The web server is single threaded. It only handles one connection at
a time, and I think the TCP socket only queues up a couple. But that
doesn't stop browsers from trying to open 8-10 https connections at a
time (which then eventually get handled serially).

> There should be a parameter in your web server's config file to limit
> the number of simultaneously active threads or processes.

The server is single-threaded by design, so it is not capable of
handling more than one connection at a time. The connections are
never actually in "parallel" except in the imagination of the browser
writers.

> It's been a long time for me, and you don't mention what brand of
> server you are running, but ISTR that Apache has/had such parameters.

FWIW, it's an old version of the GoAhead web server:

http://embedthis.com/products/goahead/

> (Also, while this is off-topic for comp.lang.python, most people here
> are a helpful bunch, and recognizing that it is off-topic, will want
> to reply off-list. You don't give them that option with
> "invalid@invalid.invalid" as an email address.)

Yea, trying to hide e-mail addresses from automated spammers is
probably futile these days. I'll have to dig into my slrn config
file.

--
Grant Edwards grant.b.edwards Yow! Somewhere in DOWNTOWN
at BURBANK a prostitute is
gmail.com OVERCOOKING a LAMB CHOP!!




== 3 of 7 ==
Date: Fri, Nov 8 2013 10:16 am
From: Chris Angelico


On Sat, Nov 9, 2013 at 4:25 AM, Grant Edwards <invalid@invalid.invalid> wrote:
> I've got a very feeble web server. The crypto handshaking involved in
> opening an https: connection takes 2-3 seconds. That would be fine if
> a browser opened a single connection and then sent a series of
> requests on that connection to load the various elements on a page.
>
> But that's not what browsers do. They all seem to open whole handful
> of connections (often as many as 8-10) and try to load all the page's
> elements in parallel.

Are you using HTTP 1.1 with connection reuse? Check that both your
client(s) and your server are happy to use 1.1, and you may be able to
cut down the number of parallel connections.

Alternatively, since fixing it at the browser seems to be hard, can
you do something ridiculously stupid like... tunnelling insecure HTTP
over SSH? That way, you establish the secure tunnel once, and
establish a whole bunch of connections over it - everything's still
encrypted, but only once. As an added bonus, if clients are requesting
several pages serially (user clicks a link, views another page), that
can be done on the same connection as the previous one, cutting crypto
overhead even further.

ChrisA




== 4 of 7 ==
Date: Fri, Nov 8 2013 11:20 am
From: Grant Edwards


On 2013-11-08, Chris Angelico <rosuav@gmail.com> wrote:
> On Sat, Nov 9, 2013 at 4:25 AM, Grant Edwards <invalid@invalid.invalid> wrote:
>> I've got a very feeble web server. The crypto handshaking involved in
>> opening an https: connection takes 2-3 seconds. That would be fine if
>> a browser opened a single connection and then sent a series of
>> requests on that connection to load the various elements on a page.
>>
>> But that's not what browsers do. They all seem to open whole handful
>> of connections (often as many as 8-10) and try to load all the page's
>> elements in parallel.
>
> Are you using HTTP 1.1 with connection reuse?

Yes. And several years ago when I first enabled that feature in the
server, I verified that some browsers were sending multiple requests
per connection (though they still often attempted to open multiple
connections). More recent browsers seem much more impatient and are
determined to open as many simultaneous connections as possible.

> Check that both your client(s) and your server are happy to use 1.1,
> and you may be able to cut down the number of parallel connections.

> Alternatively, since fixing it at the browser seems to be hard, can
> you do something ridiculously stupid like... tunnelling insecure HTTP
> over SSH?

Writing code to implement tunnelling via the ssh protocol is probably
out of the question (resource-wise).

If it were possible, how is that supported by browsers?

--
Grant Edwards grant.b.edwards Yow! I was making donuts
at and now I'm on a bus!
gmail.com




== 5 of 7 ==
Date: Fri, Nov 8 2013 11:39 am
From: Chris Angelico


On Sat, Nov 9, 2013 at 6:20 AM, Grant Edwards <invalid@invalid.invalid> wrote:
> On 2013-11-08, Chris Angelico <rosuav@gmail.com> wrote:
>> Are you using HTTP 1.1 with connection reuse?
>
> Yes. And several years ago when I first enabled that feature in the
> server, I verified that some browsers were sending multiple requests
> per connection (though they still often attempted to open multiple
> connections). More recent browsers seem much more impatient and are
> determined to open as many simultaneous connections as possible.

Yeah, but at least it's cut down from one connection per object to
some fixed number. But you've already done that.

>> Alternatively, since fixing it at the browser seems to be hard, can
>> you do something ridiculously stupid like... tunnelling insecure HTTP
>> over SSH?
>
> Writing code to implement tunnelling via the ssh protocol is probably
> out of the question (resource-wise).
>
> If it were possible, how is that supported by browsers?

You just set your hosts file to point the server's name to localhost
(or simply tell your browser to go to http://localhost/ if that's
easier), and have an SSH tunnel like:

ssh -L 80:localhost:80 user@some.server.whatever.it.is

Browser and server both think they're working with unencrypted HTTP on
loopback, but in between there's an encrypted link. Alternatively, if
you can point your browser to http://localhost:8000/ you can work with
a non-privileged port locally, which may be of value. The user at that
host needn't have much of interest as its shell - just something that
says "Press Enter to disconnect" and waits for a newline - as long as
it's configured to permit tunnelling (which is the default AFAIK). So
effectively, no browser support is needed.

The downside is that you need to consciously establish the secure
link. If you don't mind having the traffic travel the "last mile"
unencrypted, you could have a single long-term SSH tunnel set up, and
everyone connects via that; similarly, if your embedded server has a
trusted link to another box with a bit more grunt, you could end the
SSH tunnel there and run unencrypted for the last little bit. Anything
can be done, it's just a question of what'd be useful.

But like I said, it's a ridiculously stupid suggestion. Feel free to
discard it as such. :)

ChrisA




== 6 of 7 ==
Date: Fri, Nov 8 2013 11:42 am
From: Nick Cash


>What I really need is an HTTP header or meta-tag or something that I can use to tell clients to limit themselves to a single connection.

I don't think such a thing exists... but you may be able to solve this creatively:

A) Set up a proxy server that multiplexes all of the connections into a single one. A reverse proxy could even handle the SSL and alleviate the load on the embedded server. Although it sounds like maybe this isn't an option for you?

OR

B) Redesign the page it generates to need fewer requests (ideally, only one): inline CSS/JS, data: url images, etc. It's not the prettiest solution, but it could work.

-Nick Cash




== 7 of 7 ==
Date: Fri, Nov 8 2013 12:13 pm
From: Ian Kelly


On Fri, Nov 8, 2013 at 10:25 AM, Grant Edwards <invalid@invalid.invalid> wrote:
> Yes, this off-topic, but after a fair amount of Googling and searching
> in the "right" places, I'm running out of ideas.
>
> I've got a very feeble web server. The crypto handshaking involved in
> opening an https: connection takes 2-3 seconds. That would be fine if
> a browser opened a single connection and then sent a series of
> requests on that connection to load the various elements on a page.
>
> But that's not what browsers do. They all seem to open whole handful
> of connections (often as many as 8-10) and try to load all the page's
> elements in parallel. That turns what would be a 3-4 second page load
> time (using a single connection) into a 20-30 second page load time.
> Even with plaintext http: connections, the multi-connection page load
> time is slower than the single-connection load time, but not by as
> large a factor.
>
> Some browsers have user-preference settings that limit the max number
> of simultaneous connections to a single server (IIRC the RFCs suggest
> a max of 4, but most browsers seem to default to a max of 8-16).
>
> What I really need is an HTTP header or meta-tag or something that I
> can use to tell clients to limit themselves to a single connection.
>
> I haven't been able to find such a thing, but I'm hoping I've
> overlooked something...

No such header exists, that I'm aware of. The RFC simply recommends
limiting client connections to 2 per user, but modern browsers no
longer follow that recommendation and typically use 4-6 instead.

Do you really need to send all the page resources over HTTPS? Perhaps
you could reduce some of the SSL overhead by sending images and
stylesheets over a plain HTTP connection instead.





==============================================================================
TOPIC: chunking a long string?
http://groups.google.com/group/comp.lang.python/t/bfc1c8e53fafb268?hl=en
==============================================================================

== 1 of 7 ==
Date: Fri, Nov 8 2013 9:48 am
From: Roy Smith


I have a long string (several Mbytes). I want to iterate over it in manageable chunks (say, 1 kbyte each). For (a small) example, if I started with "this is a very long string", and I wanted 10 character chunks, I should get:

"this is a "
"very long "
"string"

This seems like something itertools would do, but I don't see anything. Is there something, or do I just need to loop and slice (and worry about getting all the edge conditions right) myself?

---
Roy Smith
roy@panix.com





== 2 of 7 ==
Date: Fri, Nov 8 2013 9:52 am
From: Mark Lawrence



On 08/11/2013 17:48, Roy Smith wrote:
> I have a long string (several Mbytes). I want to iterate over it in manageable chunks (say, 1 kbyte each). For (a small) example, if I started with "this is a very long string", and I wanted 10 character chunks, I should get:
>
> "this is a"
> "very long"
> "string"
>
> This seems like something itertools would do, but I don't see anything. Is there something, or do I just need to loop and slice (and worry about getting all the edge conditions right) myself?
>
> ---
> Roy Smith
> roy@panix.com
>

Any good to you http://pythonhosted.org/more-itertools/api.html ?

--
Python is the second best programming language in the world.
But the best has yet to be invented. Christian Tismer

Mark Lawrence





== 3 of 7 ==
Date: Fri, Nov 8 2013 9:59 am
From: Nick Cash


> I have a long string (several Mbytes). I want to iterate over it in manageable chunks

This is a weirdly common question. See http://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks-in-python for several solutions.

It's been proposed to be added to itertools before, but rejected: https://mail.python.org/pipermail/python-ideas/2012-July/015671.html and http://bugs.python.org/issue13095

- Nick Cash




== 4 of 7 ==
Date: Fri, Nov 8 2013 10:02 am
From: Peter Otten <__peter__@web.de>


Roy Smith wrote:

> I have a long string (several Mbytes). I want to iterate over it in
> manageable chunks (say, 1 kbyte each). For (a small) example, if I
> started with "this is a very long string", and I wanted 10 character
> chunks, I should get:
>
> "this is a "
> "very long "
> "string"
>
> This seems like something itertools would do, but I don't see anything.
> Is there something, or do I just need to loop and slice (and worry about
> getting all the edge conditions right) myself?

(x)range() can take care of the edges:

>>> s = "this is a very long string"
>>> def chunks(s, size):
... for start in xrange(0, len(s), size):
... yield s[start:start+size]
...
>>> list(chunks(s, 10))
['this is a ', 'very long ', 'string']
>>> list(chunks(s, 5))
['this ', 'is a ', 'very ', 'long ', 'strin', 'g']
>>> list(chunks(s, 100))
['this is a very long string']

Or you use StringIO:

>>> from functools import partial
>>> from StringIO import StringIO
>>> list(iter(partial(StringIO(s).read, 5), ""))
['this ', 'is a ', 'very ', 'long ', 'strin', 'g']

And no, this need not be a one-liner ;)





== 5 of 7 ==
Date: Fri, Nov 8 2013 10:04 am
From: Skip Montanaro


> I have a long string (several Mbytes). I want to iterate over it in manageable chunks (say, 1 kbyte each).

You don't mention if the string is in memory or on disk. If it's in memory:

>>> for i in range(0, len(s), 10):
... print repr(s[i:i+10])
...
'this is a '
'very long '
'string'

If your string is on disk, just loop over an open file object, reading
your chunk size every pass of the loop.

Skip




== 6 of 7 ==
Date: Fri, Nov 8 2013 10:09 am
From: Zero Piraeus


:

On Fri, Nov 08, 2013 at 12:48:12PM -0500, Roy Smith wrote:
> I have a long string (several Mbytes). I want to iterate over it in
> manageable chunks (say, 1 kbyte each).
>
> "this is a "
> "very long "
> "string"
>
> This seems like something itertools would do, but I don't see anything.

You could use io.StringIO (or StringIO.StringIO in Python 2.x):

from io import StringIO
big_str = 'x' * 10000000
stream = StringIO(big_str)
while True:
chunk = stream.read(1024)
if not chunk:
break
# process chunk

-[]z.

--
Zero Piraeus: ad referendum
http://etiol.net/pubkey.asc




== 7 of 7 ==
Date: Fri, Nov 8 2013 10:24 am
From: Roy Smith


Oh my, it turns out I don't really need to do this after all, due to previously undiscovered uber-coolness in the tools I'm using!

My use case is that from inside of a Django view, I needed to retrieve a large file via a HTTP GET, and serve that back up, with some time delays inserted into the data stream. Turns out, requests (uber-cool tool #1) provides a way to iterate over the content of a GET, and Django (uber-cool tool #2) provides a way to build a HttpResponse from the data in an iterator. Epiphany! I ended up with (essentially) this:

def stream_slow(request, song_id):
"""Streams a song, but does it extra slowly, for client testing
purposes.

"""
def _slow_stream(r, chunk_size):
for chunk in r.iter_content(chunk_size):
yield chunk
time.sleep(0.1)

url = get_url(song_id)
response = requests.get(url, stream=True)
return HttpResponse(_slow_stream(response, 1024))




On Nov 8, 2013, at 12:59 PM, Nick Cash wrote:

>> I have a long string (several Mbytes). I want to iterate over it in manageable chunks
>
> This is a weirdly common question. See http://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks-in-python for several solutions.
>
> It's been proposed to be added to itertools before, but rejected: https://mail.python.org/pipermail/python-ideas/2012-July/015671.html and http://bugs.python.org/issue13095
>
> - Nick Cash
>


---
Roy Smith
roy@panix.com








==============================================================================
TOPIC: pywin32 programming error on Win7 with shell.SHGetDesktopFolder,
desktop.BindToObject, desktop.GetDisplayNameOf
http://groups.google.com/group/comp.lang.python/t/65acf69c88845011?hl=en
==============================================================================

== 1 of 1 ==
Date: Fri, Nov 8 2013 9:51 am
From: MRAB


On 08/11/2013 03:30, iMath wrote:
>
> When running the following code on WinXP , all is fine ,
> --------------------------------------------------------------
> from win32com.shell import shell
>
> def launch_file_explorer(path, files):
>
> folder_pidl = shell.SHILCreateFromPath(path,0)[0]
> desktop = shell.SHGetDesktopFolder()
> shell_folder = desktop.BindToObject(folder_pidl, None,shell.IID_IShellFolder)
> name_to_item_mapping = dict([(desktop.GetDisplayNameOf(item, 0), item) for item in shell_folder])
> to_show = []
> for file in files:
> if file not in name_to_item_mapping:
> raise Exception('File: "{}" not found in "{}"'.format(file, path))
> to_show.append(name_to_item_mapping[file])
> shell.SHOpenFolderAndSelectItems(folder_pidl, to_show, 0)
> import os
>
>
> p=r'E:\aa'
> print(os.listdir(p))
> launch_file_explorer(p, os.listdir(p))
> --------------------------------------------------------------
>
> however ,when tested on Win7,I got the following error
>
> --------------------------------------------------------------
>
> ['b1', 'b2', 't.txt']
> Traceback (most recent call last):
> File "D:\g.py", line 21, in <module>
> launch_file_explorer(p, os.listdir(p))
> File "D:\g.py", line 13, in launch_file_explorer
> raise Exception('File: "{}" not found in "{}"'.format(file, path))
> Exception: File: "t.txt" not found in "E:\aa"
> --------------------------------------------------------------
> I nearly have no experience on pywin32 programming ,the above code is googled,anyone can help me fix this error ?thanks in advance !
>
It's building a dict where the key is the result of
desktop.GetDisplayNameOf(item, 0), and it's then not finding a given
name in that dict.

Try printing the keys to see what's there. It might be that
desktop.GetDisplayNameOf(item, 0) returns different strings in Win7
from those in WinXP.





==============================================================================
TOPIC: To whoever hacked into my Database
http://groups.google.com/group/comp.lang.python/t/1459c9bdf9ab0ada?hl=en
==============================================================================

== 1 of 5 ==
Date: Fri, Nov 8 2013 10:08 am
From: Chris Angelico


On Sat, Nov 9, 2013 at 4:11 AM, <rurpy@yahoo.com> wrote:
> On 11/08/2013 03:05 AM, Íßêïò Áëåîüðïõëïò wrote:
>> I never ignore advices.
>> I read all answers as carefully as i can.
>> But nevertheless sometimes i feel things should have been better
>> implemented using my way.
>>
>> Not of course that i know better, but thats better suited for me in the
>> level iam.
>
> Most of the "advice" I've seen posted here has, as far
> as I can tell, not intended to be useful but to serve
> as a way to telling you are incompetent are in other ways
> insulting or useless. I think you are quite right to
> ignore it (or tell the poster to get lost.)

Actually no; most of the advice has been genuine.

> Long before you showed up here, I noticed the tendency
> to not answer questions directly but to jerk people off
> by giving hints or telling them to do something other
> than they want to do.
>
> Often that is good because the original request was
> for something that the OP really didn't want to do.
> But sometimes the OP knows they want to do (but doesn't
> want or is unable to clearly explain why) and when
> they clearly state that, yes, they do want to do it
> their way, their question should be answered in good
> faith or, for those who just can't tell how to do
> something "wrong", ignored.

I disagree. If you go to a doctor and ask for a prescription for
<insert name of medication>, the doctor is quite right in refusing if
s/he believes that that won't help you. If the OP asks for a way to
stuff more into a single record in MySQL, then we're right to say "No,
don't do it that way".

Generally, people who ask for one thing and are advised another will
see that the advice is actually getting them to where they really
wanted to be. There's another thread now about calling from Python
into C, which I haven't been following closely, but I saw a comment
from its OP to the effect of "Oh right! Standard input/output would do
what I want!" - it may not have been specifically what was asked for,
but it was helpful. If it's not helpful, give a reason for that.

Do you (anyone) know better than all the people of this newsgroup? I
would think not, firstly because you're asking the question (why are
you asking if you already know better), and secondly because the
collective knowledge and skill is far greater than any individual's.
So why reject advice out of hand? If it's inapplicable for some
reason, _explain why_. Don't just go back and forth saying "But I want
it done like this" when all of us and conventional wisdom all say not
to do it.

ChrisA




== 2 of 5 ==
Date: Fri, Nov 8 2013 10:19 am
From: Denis McMahon


On Fri, 08 Nov 2013 01:28:19 +0200, Νίκος Αλεξόπουλος wrote:

> If i was completely incompetent i wouldn't had a working website and i
> wasn't able to design my customers' webpages.

If your website is working, why do you keep posting here asking us how to
fix it?

--
Denis McMahon, denismfmcmahon@gmail.com




== 3 of 5 ==
Date: Fri, Nov 8 2013 10:22 am
From: Denis McMahon


On Fri, 08 Nov 2013 01:10:37 +0000, Steve Simmons wrote:

> I must say that I kinda like the idea of Nick's computer gagging on his
> code and sending him messages pleading that he educated himself.

It's a more likely scenario that Nick learning to code properly.

--
Denis McMahon, denismfmcmahon@gmail.com




== 4 of 5 ==
Date: Fri, Nov 8 2013 11:18 am
From: Νίκος Αλεξόπουλος


Στις 8/11/2013 8:19 μμ, ο/η Denis McMahon έγραψε:
> On Fri, 08 Nov 2013 01:28:19 +0200, Νίκος Αλεξόπουλος wrote:
>
>> If i was completely incompetent i wouldn't had a working website and i
>> wasn't able to design my customers' webpages.
>
> If your website is working, why do you keep posting here asking us how to
> fix it?
>


Because at some parts i need some help, i'm a beginner and i
unexperienced what it comes to something more advance.




== 5 of 5 ==
Date: Fri, Nov 8 2013 11:23 am
From: Νίκος Αλεξόπουλος


Στις 8/11/2013 7:11 μμ, ο/η rurpy@yahoo.com έγραψε:
> On 11/08/2013 03:05 AM, Νίκος Αλεξόπουλος wrote:
>> I never ignore advices.
>> I read all answers as carefully as i can.
>> But nevertheless sometimes i feel things should have been better
>> implemented using my way.
>>
>> Not of course that i know better, but thats better suited for me in the
>> level iam.
>
> Most of the "advice" I've seen posted here has, as far
> as I can tell, not intended to be useful but to serve
> as a way to telling you are incompetent are in other ways
> insulting or useless. I think you are quite right to
> ignore it (or tell the poster to get lost.)
>
> Long before you showed up here, I noticed the tendency
> to not answer questions directly but to jerk people off
> by giving hints or telling them to do something other
> than they want to do.
>
> Often that is good because the original request was
> for something that the OP really didn't want to do.
> But sometimes the OP knows they want to do (but doesn't
> want or is unable to clearly explain why) and when
> they clearly state that, yes, they do want to do it
> their way, their question should be answered in good
> faith or, for those who just can't tell how to do
> something "wrong", ignored.
>
> Instead the response is typically a lot of hostility
> directed at them for not "taking advice". In other
> words, the advice here is not free advice, but come
> with the price that you are expected to except it
> gratefully whether it was what you asked for or not.
>
> I think you are quite right to reject advice that does
> not do what you want and ask again for advice that does.
>
> FWIW, I am quite sure there are other readers of this
> group who feel the same way, but most people aren't
> willing to subject themselves to the bullying that
> will be directed at anyone who publicly agrees with you.
> It is the same way in real life too as I'm sure
> you know.
>
> Just wanted to let you know that not everybody here
> is an asshole. It is just that assholes, by their
> nature, are the loudest.
>

Thank you for your support rurpy.
Not all ppl in this list are rude and insulting.

--
What is now proved was at first only imagined! & WebHost
<http://superhost.gr>





==============================================================================
TOPIC: Algorithm that makes maximum compression of completly diffused data.
http://groups.google.com/group/comp.lang.python/t/cf4b4e4ba592ec63?hl=en
==============================================================================

== 1 of 1 ==
Date: Fri, Nov 8 2013 10:48 am
From: Ian Kelly


On Fri, Nov 8, 2013 at 8:48 AM, <jonas.thornvall@gmail.com> wrote:
> 3^2-2^2=5

How do you intend to encode 3**2 - 2**2 in such a way that it is more
compact than simply encoding 5? If you actually have an algorithm,
you should share it instead of dropping these cryptic one-line
non-explanations and leaving us guessing about the details. But I'm
starting to think that you don't actually have an algorithm at all,
whereas my initial impression was that you did and were simply
mistaken about its effectiveness.





==============================================================================
TOPIC: Count each unique element in list of lists
http://groups.google.com/group/comp.lang.python/t/b31b06b4e135aec3?hl=en
==============================================================================

== 1 of 3 ==
Date: Fri, Nov 8 2013 11:28 am
From: Yaşar Arabacı


Hi,

I have a function that returns something like this;

[[[1, 5, 9], [2, 6, 7], [3, 4, 8]], [[1, 6, 8], [2, 4, 9], [3, 5, 7]]]

It is a list of list of lists. Each uppermost list is called a result.
I want to write a code that
shows that each elem in sublists of result on appears once in whole
sublist in order to add it to
my doctest. I am looking for something like this;

for result in results:
print sum(1 for group in result for item in group)

[1, 1, 1, 1, 1, 1, 1, 1, 1]
[1, 1, 1, 1, 1, 1, 1, 1, 1]

Above code gives me 9,9. but I want the example output above.

I prefer a one liner because this is supposed to go into a doctest.
--
http://ysar.net/




== 2 of 3 ==
Date: Fri, Nov 8 2013 11:38 am
From: yasar11732@gmail.com


This works;

>>> for result in results:
flat = list(item for group in result for item in group)
print [sum([1 for el in flat if el==current]) for current in flat]


[1, 1, 1, 1, 1, 1, 1, 1, 1]
[1, 1, 1, 1, 1, 1, 1, 1, 1]

But I am still open to suggestions if anyone thinks this can be improved.




== 3 of 3 ==
Date: Fri, Nov 8 2013 11:44 am
From: Chris Angelico


On Sat, Nov 9, 2013 at 6:28 AM, Yaşar Arabacı <yasar11732@gmail.com> wrote:
> I want to write a code that
> shows that each elem in sublists of result on appears once in whole
> sublist in order to add it to
> my doctest.

So, to clarify the problem: You want to ensure that every element
occurs exactly once, neither more nor less? And you have a guarantee
that the lists and sublists have a specific nesting depth? Try this:

[sorted((x for l in result for x in l)) for result in results]

Flattens and sorts the lists.

[sorted((x for l in result for x in l))==list(range(1,10)) for result
in results]

Flattens, sorts, and compares with a template list (which in this case
is [1, 2, 3, 4, 5, 6, 7, 8, 9] from range()).

ChrisA





==============================================================================
TOPIC: Automate Google Drive SDK Authorization
http://groups.google.com/group/comp.lang.python/t/903405986adb47b6?hl=en
==============================================================================

== 1 of 1 ==
Date: Fri, Nov 8 2013 11:36 am
From: Pratik Mehta


Guys,

I am stuck with a problem.

#!/usr/bin/python

import httplib2
import pprint

from apiclient.discovery import build
from apiclient.http import MediaFileUpload
from oauth2client.client import OAuth2WebServerFlow


# Copy your credentials from the console
CLIENT_ID = 'YOUR_CLIENT_ID'
CLIENT_SECRET = 'YOUR_CLIENT_SECRET'

# Check https://developers.google.com/drive/scopes for all available scopes
OAUTH_SCOPE = 'https://www.googleapis.com/auth/drive'

# Redirect URI for installed apps
REDIRECT_URI = 'urn:ietf:wg:oauth:2.0:oob'

# Path to the file to upload
FILENAME = 'document.txt'

# Run through the OAuth flow and retrieve credentials
flow = OAuth2WebServerFlow(CLIENT_ID, CLIENT_SECRET, OAUTH_SCOPE, REDIRECT_URI)
authorize_url = flow.step1_get_authorize_url()
print 'Go to the following link in your browser: ' + authorize_url
code = raw_input('Enter verification code: ').strip()
credentials = flow.step2_exchange(code)

# Create an httplib2.Http object and authorize it with our credentials
http = httplib2.Http()
http = credentials.authorize(http)

drive_service = build('drive', 'v2', http=http)

# Insert a file
media_body = MediaFileUpload(FILENAME, mimetype='text/plain', resumable=True)
body = {
'title': 'My document',
'description': 'A test document',
'mimeType': 'text/plain'
}

file = drive_service.files().insert(body=body, media_body=media_body).execute()
pprint.pprint(file)


The above code asks user to copy the url to the browser, and then authorize their account, and then again, copy-paste the code and paste it on the terminal. I know storing the credentials and using the refresh tokens, users will have to do this just for once.

But, I don't want so much of user-interactions. Is it possible that user authorizes by just logging in to their gmail account? As in, from my code itself, the authorization link should get open in a web browser without user doing it, and just signs in to his/her account, and that's it, authorization is done, and this login should also happen for just one time, as in, one time authorization, so that whatever is uploaded, gets uploaded on his Google Drive account and maintained. The authorization code should be directly retrieved, and these credentials should be stored as usual and be used and tokens should also be refreshed.

I came across Google Drive Service Account, good thing is that user-intervention is gone completely, but bad thing is that, it doesn't allow the account where the file is to be uploaded. It uploads the file on that drive who has created the app.

Can anyone pls help me out with this? If going with the above code, then what should I be doing to automate the task? If going with the Service Account, what should I be doing to make the app upload the data to the user's own drive account?

Any help would be appreciated.

Thanks!





==============================================================================
TOPIC: Programa no modo gráfico
http://groups.google.com/group/comp.lang.python/t/60808e9c471c2c81?hl=en
==============================================================================

== 1 of 1 ==
Date: Fri, Nov 8 2013 9:29 am
From: Guitar Men


Como faço para fazer um programa no modo gráfico sem usar o prompt?




==============================================================================

You received this message because you are subscribed to the Google Groups "comp.lang.python"
group.

To post to this group, visit http://groups.google.com/group/comp.lang.python?hl=en

To unsubscribe from this group, send email to comp.lang.python+unsubscribe@googlegroups.com

To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.python/subscribe?hl=en

To report abuse, send email explaining the problem to abuse@googlegroups.com

==============================================================================
Google Groups: http://groups.google.com/?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate