Re: Create a cookie with cookielib

2007-02-03 Thread Matthew Franz
I'm not sure what you mean be forge, but if you mean set an arbitrary
cookie manually (vs. one that was provided by the server).  just use
add_header() in http://docs.python.org/lib/request-objects.html

It may be possible to use CookieJar for this purpose but I've only
used it for manipulating cookies set by the server...

And  I would agree that Python cookie APIs are less intuitive than
what are available in others such as Jakarta HttpClient

- mdf

On 2/3/07, Alessandro Fachin <[EMAIL PROTECTED]> wrote:
> Hi, i am trying to forge a new cookie by own with cookielib. But i don't
> still have success. This a simply code:
>
> import cookielib, urllib, urllib2
> login = 'Ia am a cookie!'
> cookiejar = cookielib.CookieJar()
> urlOpener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar))
> values = {'user':login}
> data = urllib.urlencode(values)
> request = urllib2.Request("http://localhost/cookie.php";, data)
> url = urlOpener.open(request)
> print url.info()
> page = url.read(50)
> print page
> print cookiejar
>
> the output of this is:
>
> Date: Sat, 03 Feb 2007 10:20:05 GMT
> Server: Apache
> X-Powered-By: PHP/5.1.6
> Set-Cookie: user=Alex+Porter; expires=Sat, 03-Feb-2007 11:20:05 GMT
> Content-Length: 11
> Connection: close
> Content-Type: text/html; charset=UTF-8
>
> Array
> (
> )
> ]>
>
> And here is the code of cookie.php that i've create for this example:
>
>  setcookie("user", "Alex Porter", time()+3600);
> ?>
>  // Print a cookie
> echo $_COOKIE["user"];
> // A way to view all cookies
> print_r($_COOKIE);
> ?>
>
> if anyone could help... Thank you
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Matthew Franz
http://www.threatmind.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python linux distro

2007-02-08 Thread Matthew Franz
> thanks guys
>
> when i wrote this, i thought that out there is some crazy guy like me.
> i was hoping for more support but after these arguments, there is
> nothing more then to say:you are right. the world doesnt need another
> distro. but if one day I mange to do it, hope you will be glade that i
> post the lik here.
>

Now what would be interesting (and *really* crazy) would be Linux (or
BSD or whatever) distro written almost entirely *in* Python, with the
goal of eliminating as much bash/sh as possible.

That would be fun.

- mdf
-- 
http://mail.python.org/mailman/listinfo/python-list


Curious UnboundLocalError Behavior

2007-02-28 Thread Matthew Franz
I'm probably fundamentally misunderstanding the way the interpreter
works with regard to scope, but is this the intended behavior...

franz-macbook:~ mdfranz$ python unboundlocal.py
('Darwin', 'franz-macbook.local', '8.8.5', 'Darwin Kernel Version
8.8.5: Mon Dec 11 19:39:17 PST 2006;
root:xnu-792.16.5.obj~1/RELEASE_I386', 'i386')
2.4.3 (#1, Feb 24 2007, 23:01:32)
[GCC 4.0.1 (Apple Computer, Inc. build 5367)]
{'__builtins__': , '__file__':
'unboundlocal.py', 'SOMEGLOBAL': 1, 'sys': ,
'__name__': '__main__', 'foo': , 'os':
,
'__doc__': None}
SOMEGLOBAL:
Traceback (most recent call last):
  File "unboundlocal.py", line 15, in ?
foo()
  File "unboundlocal.py", line 11, in foo
print "SOMEGLOBAL:",SOMEGLOBAL
UnboundLocalError: local variable 'SOMEGLOBAL' referenced before assignment


Where unboundlocal.py is...

import os,sys

SOMEGLOBAL=1

def foo():
dome=False
if dome:
SOMEGLOBAL = 0

print globals()
print "SOMEGLOBAL:",SOMEGLOBAL

print os.uname()
print sys.version
foo()

Is SOMEGLOBAL is some weird in-between state, since it is referenced
within foo() but not actually assigned?

If I set dome to True SOMEGLOBAL gets overriden (as I would have expected)

franz-macbook:~ mdfranz$ python unboundlocal.py
('Darwin', 'franz-macbook.local', '8.8.5', 'Darwin Kernel Version
8.8.5: Mon Dec 11 19:39:17 PST 2006;
root:xnu-792.16.5.obj~1/RELEASE_I386', 'i386')
2.4.3 (#1, Feb 24 2007, 23:01:32)
[GCC 4.0.1 (Apple Computer, Inc. build 5367)]
{'__builtins__': , '__file__':
'unboundlocal.py', 'SOMEGLOBAL': 1, 'sys': ,
'__name__': '__main__', 'foo': , 'os':
,
'__doc__': None}
SOMEGLOBAL: 0



-- 
Matthew Franz
http://www.threatmind.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Curious UnboundLocalError Behavior

2007-03-01 Thread Matthew Franz
I had tried the global prefix in the real code (vs. the contrived
example in the post), but in the incorrect code block, which made me
think something else was up. Yes, these were supposed to be constants
that under rare circumstances were changed ;)  In the end, I  scrapped
the rebind approach, because that wasn't the behavior I wanted
either.Thanks for the help.

- mdf

On 1 Mar 2007 00:20:05 -0800, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> On 28 fév, 18:15, "Matthew Franz" <[EMAIL PROTECTED]> wrote:
> > I'm probably fundamentally misunderstanding the way the interpreter
> > works with regard to scope, but is this the intended behavior...
> >
> (snip traceback)
>
> > import os,sys
> >
> > SOMEGLOBAL=1
> >
> > def foo():
> > dome=False
> > if dome:
> > SOMEGLOBAL = 0
>
>
> This makes SOMEGLOBAL local !-)
>
> Look for the 'global' statement. Or better, try to avoid rebinding
> globals from within a function.
>
> As as side note: by convention, ALL_UPPER names denote constants.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
Matthew Franz
http://www.threatmind.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Performance on local constants?

2007-12-27 Thread Matthew Franz
I get class Searcher(object) but can't for the life of me see why
(except to be intentionally obtuse) one would use the def
searcher(rex) pattern which I assure you would call with
searcher(r)(t) right?

- mdf


> >
> > 'Most flexible' in a different way is
> >
> > def searcher(rex):
> > crex = re.compile(rex)
> > def _(txt):
> > return crex.search(txt)
> > return _
> >
>
> I see your obfuscatory ante and raise you several dots and
> underscores:
>
> class Searcher(object):
> def __init__(self, rex):
> self.crex = re.compile(rex)
> def __call__(self, txt):
> return self.crex.search(txt)
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Performance on local constants?

2007-12-27 Thread Matthew Franz
Thanks, that makes more sense. I got tripped up by the function
returning a function thing and (for a while) thought _ was some sort
of spooky special variable.

- mdf

> On Dec 28, 7:53 am, "Matthew Franz" <[EMAIL PROTECTED]> wrote:
> > I get class Searcher(object) but can't for the life of me see why
> > (except to be intentionally obtuse) one would use the def
> > searcher(rex) pattern which I assure you would call with
> > searcher(r)(t) right?
> >
>
> The whole point of the thread was performance across multiple searches
> for the one pattern. Thus one would NOT do
> searcher(r)(t)
> each time a search was required; one would do
> s = searcher(r)
> ONCE, and then do
> s(t)
> each time ...
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Matthew Franz
http://www.threatmind.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Network Module

2008-01-01 Thread Matthew Franz
Why not just wrap netstat for what you need? or you might be able to
get from /proc entries? Or look at
http://www.psychofx.com/psi/trac/wiki/  (PSI Tools)   If you want
interface statistics you can process the CSV output of bwm-ng
(http://www.gropp.org/?id=projects&sub=bwm-ng)

- mdf

On Jan 1, 2008 7:40 AM, Sunil Ghai <[EMAIL PROTECTED]> wrote:
> Hello people,
> I am searching for a python module to interact with the network
> connections/interfaces. For example the number of active TCP/IP connections
> via eth0 interface and all that stuff.
> I have done googling and search at pythonorg but couldn't find any.
>
> Thanks
> Sunil Kumar Ghai
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Matthew Franz
http://www.threatmind.net/
-- 
http://mail.python.org/mailman/listinfo/python-list