[Tutor] retrieving httponly cookies on accessing webpage with urllib2

2008-10-16 Thread xbmuncher
I'm trying to mimic my firefox browser in requesting a webpage with python.
Here are the headers obtained by wireshark when I accessed it with firefox:
GET /dirName/ HTTP/1.1
Host: www.website.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3)
Gecko/2008092417 Firefox/3.0.3
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive


the website responds with this header:
HTTP/1.1 200 OK
Date: Fri, 17 Oct 2008 03:16:19 GMT
Server: Apache/2.0.59 (FreeBSD) PHP/4.4.7 with Suhosin-Patch
X-Powered-By: PHP/4.4.7
Set-Cookie: bbsessionhash=1c9eacae7c56fefc79e627b07a9af8ae; path=/; HttpOnly
Set-Cookie: bblastvisit=1224613379; expires=Sat, 17 Oct 2009 03:16:19 GMT;
path=/
Set-Cookie: bblastactivity=0; expires=Sat, 17 Oct 2009 03:16:19 GMT; path=/
Cache-Control: private
Pragma: private
X-UA-Compatible: IE=7
Content-Encoding: gzip
Content-Length: 7099
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=ISO-8859-1



So I tried trusty ol' urllib2 to request it in python:
import urllib2


url = 'http://www.website.com'

#headers
h = {
'User-Agent' : 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3)
Gecko/2008092417 Firefox/3.0.3',
'Accept' :
'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language' : 'en-us,en;q=0.5',
'Accept-Encoding' : 'gzip,deflate',
'Accept-Charset' : 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
'Keep-Alive' : '300',
'Connection' : 'keep-alive'
}
#request page
reqObj = urllib2.Request(url, None, h)
urlObj = urllib2.urlopen(reqObj)

#read response
print urlObj.read()
print urlObj.geturl()
print urlObj.info()

#close urlObj
urlObj.close()

raw_input('press a key...')


it returns these headers:
Date: Fri, 17 Oct 2008 03:39:20 GMT
Server: Apache/2.0.59 (FreeBSD) PHP/4.4.7 with Suhosin-Patch
X-Powered-By: PHP/4.4.7
Content-Length: 1311
Connection: close
Content-Type: text/html


Notice the content length is considerably smaller, and no cookies are sent
to me like they were in firefox. I know only a little about httpOnly
cookies, but that it is some kind of special cookie that I suppose has
something to do with python not being able to access it like firefox. All I
want to do is have python receive the same cookies that firefox did, how can
I do this? I read somewhere that httpOnly cookies were implemented in the
python cookie module:
http://glyphobet.net/blog/blurb/285
yet the other cookies aren't being sent either...
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Convert a Sequence of Images into an AVI file

2008-10-16 Thread Wayne Watson
Title: Signature.html




I have a file of images shot at a frame rate of 1/30th of a second.
They are 640 by 480 bytes followed immediately by up to 200 smaller
images 128x128 pixels. The software I'm using will convert this into a
mov file. I'd like to simply take the large images out of the file and
make an avi file from them. What in Python will help me do that?
-- 


   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)

 "If Stupidity got us into this mess, then why can't 
  it get us out?" -- Will Rogers

Web Page: 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [Edu-sig] school physics/math courses

2008-10-16 Thread michel paul
This would be a great text for a high school math/CS class:  Math for the
Digital Age .

- Michel

On Thu, Oct 16, 2008 at 4:15 AM, roberto <[EMAIL PROTECTED]> wrote:

> hello
> (i am rather new in python ...)
>
> i am about to start a course of physics and math for students aged
> 14-17 (high school)
> and i am deeply interested in the possibilty of teaching fundamental
> concepts of these subjects via teaching programming;
> i chose python (i won't change my mind ...)
>
> so i am looking for resources on how to deal with these topics via
> this great programming language;
>
> i need some help from you and moreover if you are aware of books
> already covering these need
>
> thank you in advance
> --
> roberto
> OS: GNU/Linux, Debian
> ___
> Edu-sig mailing list
> [EMAIL PROTECTED]
> http://mail.python.org/mailman/listinfo/edu-sig
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] school physics/math courses

2008-10-16 Thread greg whittier
On Thu, Oct 16, 2008 at 7:15 AM, roberto <[EMAIL PROTECTED]> wrote:

> hello
> (i am rather new in python ...)
>
> i am about to start a course of physics and math for students aged
> 14-17 (high school)
> and i am deeply interested in the possibilty of teaching fundamental
> concepts of these subjects via teaching programming;
> i chose python (i won't change my mind ...)
>
> so i am looking for resources on how to deal with these topics via
> this great programming language;
>

You might take a look at VPython.  I've used it before, but not for
educational purposes.  There are some interesting looking videos at
http://showmedo.com/videos/series?name=pythonThompsonVPythonSeries
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] school physics/math courses

2008-10-16 Thread Alan Gauld


"Kent Johnson" <[EMAIL PROTECTED]> wrote in message 


Oops, I see you cross-posted. Apologies to edu-sig!

Kent


If it makes you feel better I didn't notice either. :-)
And I also didn't notice the other emails...

Alan G

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] school physics/math courses

2008-10-16 Thread Alan Gauld


"roberto" <[EMAIL PROTECTED]> wrote


i am about to start a course of physics and math for students aged
14-17 (high school)
and i am deeply interested in the possibilty of teaching fundamental
concepts of these subjects via teaching programming;
i chose python (i won't change my mind ...)

so i am looking for resources on how to deal with these topics via
this great programming language;


Try the Python edu-sig mailing list.
It is for those using Python in education.

There are probably others there who have done this already.

Alan G 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] school physics/math courses

2008-10-16 Thread Wayne Watson
Title: Signature.html




I posted a query on sci.physics (newsgroup) on this question. I'll get
back if anything useful pops up.

Try Amazon with a search on python science, or whatever, as a title. 

You might try Google and search for high school physics python. There
are some pretty advanced HS around the country that might have
attempted something like you propose. My guess though is that you will 
have to construct a course pretty much from scratch. It should be
interesting.

Personally, I think technology should be left out, and one should
concentrate on physics without math or technology. However, that's not
easy. I think a famous physicist said something like think about
physics not math. (Perhaps he was thinking about energy. We really
don't know what it is, but the concept and math works. It's important
to understand the abstraction.)  I suspect the real motivation of the
physicist was to create a concept, and then turn it into a new kind of
math, for example, as Feynman did. Just an opinion.

In any case, good luck.

Ken Oliver wrote:

  For a starting place, you may want to look at "Mathematics for the Digital Age and Programming in Python" by Maria and Gary Litvin.  ISBN 978-0-9727055-8-5

Both authors are very helpful and often contribute to math and CS electronic discussion groups. Communications possible through information below:

Skylight Publishing
9 Bartlet Street, Suite 70
Andover, MA 01810

web: http://www.skylit.com
e-mail: [EMAIL PROTECTED]
[EMAIL PROTECTED]


-Original Message-
  
  
From: roberto <[EMAIL PROTECTED]>
Sent: Oct 16, 2008 7:15 AM
To: "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
Cc: tutor@python.org
Subject: [Tutor] school physics/math courses

hello
(i am rather new in python ...)

i am about to start a course of physics and math for students aged
14-17 (high school)
and i am deeply interested in the possibilty of teaching fundamental
concepts of these subjects via teaching programming;
i chose python (i won't change my mind ...)

so i am looking for resources on how to deal with these topics via
this great programming language;

i need some help from you and moreover if you are aware of books
already covering these need

thank you in advance
-- 
roberto
OS: GNU/Linux, Debian
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

  
  
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

  


-- 


   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)

 "If Stupidity got us into this mess, then why can't 
  it get us out?" -- Will Rogers

Web Page: 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Difficult loop?

2008-10-16 Thread bob gailer

Last post for this assignment for now - simplified even more.

word = "Almuta$r~id"
window = position = 5
shortAndOmit = "aiou+~"
rest = "_" * window + "".join(letter for letter in word
if letter not in shortAndOmit) + "_" * window
word = iter(word)
for letter in word:
  if letter not in shortAndOmit:
position += 1
print rest[position-window:position+window+1] + "_"
  elif letter in shortAndOmit[:4]:
print rest[position-window:position+window+1] + letter
  elif letter == "~":
print rest[position-window:position+window+1] + "~" + word.next()


--
Bob Gailer
Chapel Hill NC
919-636-4239

When we take the time to be aware of our feelings and
needs we have more satisfying interactions with others.

Nonviolent Communication provides tools for this awareness.

As a coach and trainer I can assist you in learning this process.

What is YOUR biggest relationship challenge?


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Difficult loop?

2008-10-16 Thread bob gailer

I just can't leave well enough alone. Down to 14 lines.
More names, less magic numbers.

word = "Almuta$r~id"
window = position = 5
shortAndOmit = "aiou+~"
rest = "_" * window + "".join(letter for letter in word
if letter not in shortAndOmit) + "_" * window
word = iter(word + "+")
for letter in word:
  while letter not in shortAndOmit:
position += 1
print rest[position-window:position+window+1] + "_"
letter = word.next()
  if letter in shortAndOmit[:4]:
print rest[position-window:position+window+1] + letter
  elif letter == "~":
print rest[position-window:position+window+1] + "~" + word.next()


--
Bob Gailer
Chapel Hill NC
919-636-4239

When we take the time to be aware of our feelings and
needs we have more satisfying interactions with others.

Nonviolent Communication provides tools for this awareness.

As a coach and trainer I can assist you in learning this process.

What is YOUR biggest relationship challenge?


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Difficult loop?

2008-10-16 Thread bob gailer

How about:

word = "Almuta$r~id"
predecessors = "_" * 5
successors = "".join(letter for letter in word if letter not in "aiou+~")
for index, letter in enumerate(word):
 if letter not in "aiou~+":
   next = word[index+1] if index < len(word) - 1 else ""
   if next in "aiou":
 tail = next
   elif next == "~":
 next = word[index+2] # bold assumption that a short vowel will 
follow ~

 tail = "~" + next
   else:
 tail = "_"
   print predecessors + successors + tail
   predecessors = predecessors[1:] + letter
   successors = successors[1:] + ("_" if len(successors) <= 5 else "")

Simple - procedural - no functions. 16 lines of code. Easy to read and 
maintain.


--
Bob Gailer
Chapel Hill NC 
919-636-4239


When we take the time to be aware of our feelings and 
needs we have more satisfying interatctions with others.


Nonviolent Communication provides tools for this awareness.

As a coach and trainer I can assist you in learning this process.

What is YOUR biggest relationship challenge?

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] school physics/math courses

2008-10-16 Thread Ken Oliver
For a starting place, you may want to look at "Mathematics for the Digital Age 
and Programming in Python" by Maria and Gary Litvin.  ISBN 978-0-9727055-8-5

Both authors are very helpful and often contribute to math and CS electronic 
discussion groups. Communications possible through information below:

Skylight Publishing
9 Bartlet Street, Suite 70
Andover, MA 01810

web: http://www.skylit.com
e-mail: [EMAIL PROTECTED]
[EMAIL PROTECTED]


-Original Message-
>From: roberto <[EMAIL PROTECTED]>
>Sent: Oct 16, 2008 7:15 AM
>To: "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
>Cc: tutor@python.org
>Subject: [Tutor] school physics/math courses
>
>hello
>(i am rather new in python ...)
>
>i am about to start a course of physics and math for students aged
>14-17 (high school)
>and i am deeply interested in the possibilty of teaching fundamental
>concepts of these subjects via teaching programming;
>i chose python (i won't change my mind ...)
>
>so i am looking for resources on how to deal with these topics via
>this great programming language;
>
>i need some help from you and moreover if you are aware of books
>already covering these need
>
>thank you in advance
>-- 
>roberto
>OS: GNU/Linux, Debian
>___
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] school physics/math courses

2008-10-16 Thread Kent Johnson
On Thu, Oct 16, 2008 at 9:07 AM, Kent Johnson <[EMAIL PROTECTED]> wrote:

> You should ask on the edu-sig list:
> http://www.python.org/community/sigs/current/edu-sig/

Oops, I see you cross-posted. Apologies to edu-sig!

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] school physics/math courses

2008-10-16 Thread Kent Johnson
On Thu, Oct 16, 2008 at 7:15 AM, roberto <[EMAIL PROTECTED]> wrote:
> hello
> (i am rather new in python ...)
>
> i am about to start a course of physics and math for students aged
> 14-17 (high school)
> and i am deeply interested in the possibilty of teaching fundamental
> concepts of these subjects via teaching programming;
> i chose python (i won't change my mind ...)

You should ask on the edu-sig list:
http://www.python.org/community/sigs/current/edu-sig/

Also see
http://www.4dsolutions.net/ocn/cp4e.html

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] school physics/math courses

2008-10-16 Thread roberto
hello
(i am rather new in python ...)

i am about to start a course of physics and math for students aged
14-17 (high school)
and i am deeply interested in the possibilty of teaching fundamental
concepts of these subjects via teaching programming;
i chose python (i won't change my mind ...)

so i am looking for resources on how to deal with these topics via
this great programming language;

i need some help from you and moreover if you are aware of books
already covering these need

thank you in advance
-- 
roberto
OS: GNU/Linux, Debian
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] newbie question about list element manipulation after split()

2008-10-16 Thread Kent Johnson
2008/10/16 Emad Nawfal (عماد نوفل) <[EMAIL PROTECTED]>:

> It works fine. It seems that in the file you have there are lines whose
> length is less than you should expect

Yes, my guess is there is a blank line in the file.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] newbie question about list element manipulation after split()

2008-10-16 Thread Emad Nawfal (عماد نوفل)
On Thu, Oct 16, 2008 at 4:25 AM, Visvaldas K. <[EMAIL PROTECTED]>wrote:

> Hi,
>
> I feel very stupid, but I am stuck. I could try some workaround, but I want
> to understand what I am doing wrong.
>
> The line:
>
> for line in open("parameterfile").readlines( ):
>print line.split()# trouble line
>
>
> The "trouble line" works fine in this example. It prints
> what I want, something which looks like lists of words:
>
> ['CT', 'CT', '268.0', '1.529']...  etc.
>
> However, if I want to manipulate the individual list elements, I run into
> trouble. While
>
> print line.split()[0]
>
> still works, (it yields CT  - first element),
>
> however,
>
> print line.split()[1]
>
> gives error:
>
> File "readatoms.py", line 103, in 
>print line.split()[1]
> IndexError: list index out of range
>
> Could you please tell me what's wrong. (I come from Perl background so
> Python seems out-of-the-body experience to me).
>
> Sincerely,
>
> Vis
>

Here is a solution:
>>> for line in open('DBAN1001.txt').readlines():
... line = line.split()
... if len(line) > 1: # This is what makes it work for me.
... print line[1]
...
it's
have
the
way
that
is
is
prison
we


It works fine. It seems that in the file you have there are lines whose
length is less than you should expect, or maybe a more experienced Python
programmer can give you a better answer.


>
>
>
>
>
>
>
>
>
>
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
لا أعرف مظلوما تواطأ الناس علي هضمه ولا زهدوا في إنصافه كالحقيقة.محمد
الغزالي
"No victim has ever been more repressed and alienated than the truth"

Emad Soliman Nawfal
Indiana University, Bloomington
http://emnawfal.googlepages.com

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] newbie question about list element manipulation after split()

2008-10-16 Thread Emad Nawfal (عماد نوفل)
Here is a solution:
>>> for line in open('DBAN1001.txt').readlines():
... line = line.split()
... if len(line) > 1: # This is what makes it work for me.
... print line[1]
...
it's
have
the
way
that
is
is
prison
we


It works fine. It seems that in the file you have there are lines whose
length is less than you should expect, or maybe a more experienced Python
programmer can give you a better answer.


On Thu, Oct 16, 2008 at 4:25 AM, Visvaldas K. <[EMAIL PROTECTED]>wrote:

> Hi,
>
> I feel very stupid, but I am stuck. I could try some workaround, but I want
> to understand what I am doing wrong.
>
> The line:
>
> for line in open("parameterfile").readlines( ):
>print line.split()# trouble line
>
>
> The "trouble line" works fine in this example. It prints
> what I want, something which looks like lists of words:
>
> ['CT', 'CT', '268.0', '1.529']...  etc.
>
> However, if I want to manipulate the individual list elements, I run into
> trouble. While
>
> print line.split()[0]
>
> still works, (it yields CT  - first element),
>
> however,
>
> print line.split()[1]
>
> gives error:
>
> File "readatoms.py", line 103, in 
>print line.split()[1]
> IndexError: list index out of range
>
> Could you please tell me what's wrong. (I come from Perl background so
> Python seems out-of-the-body experience to me).
>
> Sincerely,
>
> Vis
>
>
>
>
>
>
>
>
>
>
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
لا أعرف مظلوما تواطأ الناس علي هضمه ولا زهدوا في إنصافه كالحقيقة.محمد
الغزالي
"No victim has ever been more repressed and alienated than the truth"

Emad Soliman Nawfal
Indiana University, Bloomington
http://emnawfal.googlepages.com

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] newbie question about list element manipulation after split()

2008-10-16 Thread Visvaldas K.
Hi,

I feel very stupid, but I am stuck. I could try some workaround, but I want to 
understand what I am doing wrong.

The line:

for line in open("parameterfile").readlines( ):
print line.split()# trouble line


The "trouble line" works fine in this example. It prints
what I want, something which looks like lists of words:

['CT', 'CT', '268.0', '1.529']...  etc.

However, if I want to manipulate the individual list elements, I run into 
trouble. While

print line.split()[0]

still works, (it yields CT  - first element), 

however,

print line.split()[1]

gives error:

File "readatoms.py", line 103, in 
print line.split()[1]
IndexError: list index out of range

Could you please tell me what's wrong. (I come from Perl background so Python 
seems out-of-the-body experience to me).

Sincerely,

Vis






 





  
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor