Re: Is there a way to find IP address?

2006-09-15 Thread Winfried Tilanus
On 09/15/2006 Lad wrote:
> How can be HTTP_X_FORWARDED_FOR easily  spoofed? I thought that  IP
> address is not possible change.

Because it is a header that is added by the proxy. This header has (or
should have) no role in the proces of relaying the request by the proxy.
It is just politely added by the proxy to make it possible to identify
for who the request is forwarded. So the proxy might add anything it
likes, or nothing at all if it is an anonymizing proxy.

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


Re: mod_python performs several magnitudes slower than PHP?

2007-05-21 Thread Winfried Tilanus
On 05/20/2007 Graham Dumpleton wrote:

Hi,

> A more suitable example for comparison would have been:

And are there any benchmarks with this new version available? Just
curious...

best wishes,

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


Re: can i set up a mysql db connection as a class ?

2006-04-27 Thread Winfried Tilanus
On 04/28/2006 07:54 AM, *binarystar* wrote:

Just wondering: is there any risk of two threads accessing the Execute
function at the same time and getting something like this on the same
cursor object:

thread_1: self.cursor.Execute( sql_statement )
thread_2: self.cursor.Execute( sql_statement )
thread_1: return self.cursor.FetchAll()
thread_2: return self.cursor.FetchAll()

In that case the queries would seriously be messed up. My intuition says
this would need some locking or a 'cursor-pool'.

best wishes,

Winfried


> your on the right track ... create something like this ( hope the
> formatting doesn't go to hay wire )
> 
> class DB_Connector(object):
> 
> """ Humble Database Connection Class """
> def __init__(self, host="localhost",
> user="MyUser",passwd="MyPassword", **other_db_arguments):
>   self.host   =   host
>self.user   =   user
>self.passwd =   passwd
>   # Unpack Other Database Arguments Here
>  self.CreateConnection()
>def CreateConnection( self ):
>   self.cursor = MySQLdb.connect(self.host, self.user,
> self.passwd)
>def DestroyConnection( self ):
>   self.cursor.close()
>def Execute( self, sql_statement ):
>   self.cursor.Execute( sql_statement )
>   return self.cursor.FetchAll()
>Then when you run your program create an instance of the object
> 
> db_connection = DB_Connector( 'localhost', 'administrator',
> 'betelgeuse99', auto_commit=1, other_keyword_arg="yes" )
> 
> now when you pass the db_connection instance to other classes, a copy
> will be made automagically
> 
> thread_1_instance= ThreadingClass( db_connection )
> thread_2_instance= ThreadingClass( db_connection )
> thread_3_instance= ThreadingClass( db_connection )
> 
> should work ..
> I hope this is useful
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can i set up a mysql db connection as a class ?

2006-04-28 Thread Winfried Tilanus
On 04/28/2006 08:35 AM, *binarystar* wrote:

Looking better at the  """ Humble Database Connection Class """: if I am
not mistaken, it seems to mix up connections and cursors.

MySQLdb has a thread safety level of '1', meaning: "Threads may share
the module, but not connections". So you have to give each thread an own
connection. Beside of that I would prefer not to share the cursor
object, although it should not really matter.

The following should work and make the cursors private to the Execute
function (untested):

class DB_Connector(object):

""" Humble Database Connection Class """
def __init__(self, host="localhost",
 user="MyUser",
 passwd="MyPassword",
 **other_db_arguments):
self.host   =   host
self.user   =   user
self.passwd =   passwd
# Unpack Other Database Arguments Here
self.CreateConnection()

def CreateConnection(self):
self.connection = MySQLdb.connect(self.host,
  self.user,
  self.passwd)

def DestroyConnection(self):
self.connection.close()

def Execute(self, sql_statement):
cursor = self.connection.cursor()
cursor.execute(sql_statement)
result = cursor.fetchall()
cursor.close()
return result


> I suppose that is possible because you are calling the one instance of a
> cursor object ... maybe you have to create a copy of the cursor object,
> rather than passing a reference to the one object? or set up the
> db_connection objects inside each of the threads? ..
> 
> Winfried Tilanus wrote:
>> On 04/28/2006 07:54 AM, *binarystar* wrote:
>>
>> Just wondering: is there any risk of two threads accessing the Execute
>> function at the same time and getting something like this on the same
>> cursor object:
>>
>> thread_1: self.cursor.Execute( sql_statement )
>> thread_2: self.cursor.Execute( sql_statement )
>> thread_1: return self.cursor.FetchAll()
>> thread_2: return self.cursor.FetchAll()
>>
>> In that case the queries would seriously be messed up. My intuition says
>> this would need some locking or a 'cursor-pool'.
>>
>> best wishes,
>>
>> Winfried
>>
>>
>>> your on the right track ... create something like this ( hope the
>>> formatting doesn't go to hay wire )
>>>
>>> class DB_Connector(object):
>>>
>>> """ Humble Database Connection Class """
>>> def __init__(self, host="localhost",
>>> user="MyUser",passwd="MyPassword", **other_db_arguments):
>>>   self.host   =   host
>>>self.user   =   user
>>>self.passwd =   passwd
>>>   # Unpack Other Database Arguments Here
>>>  self.CreateConnection()
>>>def CreateConnection( self ):
>>>   self.cursor = MySQLdb.connect(self.host, self.user,
>>> self.passwd)
>>>def DestroyConnection( self ):
>>>   self.cursor.close()
>>>def Execute( self, sql_statement ):
>>>   self.cursor.Execute( sql_statement )
>>>   return self.cursor.FetchAll()
>>>Then when you run your program create an instance of the object
>>>
>>> db_connection = DB_Connector( 'localhost', 'administrator',
>>> 'betelgeuse99', auto_commit=1, other_keyword_arg="yes" )
>>>
>>> now when you pass the db_connection instance to other classes, a copy
>>> will be made automagically
>>>
>>> thread_1_instance= ThreadingClass( db_connection )
>>> thread_2_instance= ThreadingClass( db_connection )
>>> thread_3_instance= ThreadingClass( db_connection )
>>>
>>> should work ..
>>> I hope this is useful
-- 
http://mail.python.org/mailman/listinfo/python-list