Re: Python IDE

2004-12-14 Thread Tomas
"Fuzzyman" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> If you're willing to pay for one, Komodo is very good. Especially for
> projects.

I would recomend Wing IDE over Komodo. My experience is that Wing IDE has 
far better code completion. And the Source Assistant feature of the 
professional version is very useful.

As for projects, it doesn't support CVS or anything similar. Still, I don't 
miss this feature, because there are other excelent and free CVS clients. I 
use TortoiseCVS, http://www.tortoisecvs.org/, which integrates CVS-support 
in Explorer.

-Tomas 


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


Python refuses to import SVN

2008-02-26 Thread Tomas
Dear group.
I have some big problems getting python to work with svn.
Python SVN and SWIG is compiled from source.
I have been testing Python 2.5.1 and 2.4.4 together with SWIG 1.3.25 and
1.3.33 and SVN 1.4.5 and 1.4.6

All combinations creates the same problem:

[EMAIL PROTECTED] libsvn]# python
Python 2.4.4 (#1, Feb 25 2008, 08:46:36)
[GCC 3.4.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from svn import core
Traceback (most recent call last):
  File "", line 1, in ?
  File "/usr/local/lib/svn-python/svn/core.py", line 19, in ?
from libsvn.core import *
  File "/usr/local/lib/svn-python/libsvn/core.py", line 5, in ?
import _core
ImportError: File not found
>>> from svn import core
Segmentation fault
[EMAIL PROTECTED] libsvn]#

I just can't figure out what the heck is wrong.
Can someone please help me with this.
I did a gdb session on the same, but to be honest, the output tells me
nothing.

"/usr/local/lib/svn-python" is in in svn.pth in "site-packages"
Also tried to move libsvn and svn to "site-packages" without any luck

contents of "libsvn"
[EMAIL PROTECTED] libsvn]# ls -al
total 7636
drwxr-xr-x 2 root root   4096 Feb 26 19:29 .
drwxr-xr-x 4 root root   4096 Feb 26 19:29 ..
-rw-r--r-- 1 root root700 Feb 26 19:29 __init__.py
-rw-r--r-- 1 root root124 Feb 26 19:29 __init__.pyc
-rw-r--r-- 1 root root 640100 Feb 26 19:28 _client.a
-rwxr-xr-x 1 root root   1381 Feb 26 19:28 _client.la
-rwxr-xr-x 1 root root 483355 Feb 26 19:28 _client.so
-rw-r--r-- 1 root root 753614 Feb 26 19:28 _core.a
-rwxr-xr-x 1 root root   1367 Feb 26 19:28 _core.la
-rwxr-xr-x 1 root root 564054 Feb 26 19:28 _core.so
-rw-r--r-- 1 root root 276172 Feb 26 19:29 _delta.a
-rwxr-xr-x 1 root root   1374 Feb 26 19:29 _delta.la
-rwxr-xr-x 1 root root 214896 Feb 26 19:29 _delta.so
-rw-r--r-- 1 root root 372296 Feb 26 19:29 _fs.a
-rwxr-xr-x 1 root root   1353 Feb 26 19:29 _fs.la
-rwxr-xr-x 1 root root 284834 Feb 26 19:29 _fs.so
-rw-r--r-- 1 root root 508620 Feb 26 19:29 _ra.a
-rwxr-xr-x 1 root root   1353 Feb 26 19:29 _ra.la
-rwxr-xr-x 1 root root 385058 Feb 26 19:29 _ra.so
-rw-r--r-- 1 root root 489820 Feb 26 19:29 _repos.a
-rwxr-xr-x 1 root root   1374 Feb 26 19:29 _repos.la
-rwxr-xr-x 1 root root 369334 Feb 26 19:29 _repos.so
-rw-r--r-- 1 root root 790324 Feb 26 19:29 _wc.a
-rwxr-xr-x 1 root root   1353 Feb 26 19:29 _wc.la
-rwxr-xr-x 1 root root 580953 Feb 26 19:29 _wc.so
-rw-r--r-- 1 root root  55399 Feb 26 19:29 client.py
-rw-r--r-- 1 root root  59178 Feb 26 19:29 client.pyc
-rw-r--r-- 1 root root 151964 Feb 26 19:29 core.py
-rw-r--r-- 1 root root 159874 Feb 26 19:29 core.pyc
-rw-r--r-- 1 root root  26235 Feb 26 19:29 delta.py
-rw-r--r-- 1 root root  28256 Feb 26 19:29 delta.pyc
-rw-r--r-- 1 root root  38222 Feb 26 19:29 fs.py
-rw-r--r-- 1 root root  45727 Feb 26 19:29 fs.pyc
-rw-r--r-- 1 root root  43835 Feb 26 19:29 ra.py
-rw-r--r-- 1 root root  47632 Feb 26 19:29 ra.pyc
-rw-r--r-- 1 root root  43248 Feb 26 19:29 repos.py
-rw-r--r-- 1 root root  47508 Feb 26 19:29 repos.pyc
-rw-r--r-- 1 root root  83300 Feb 26 19:29 wc.py
-rw-r--r-- 1 root root  89225 Feb 26 19:29 wc.pyc

contents of svn

[EMAIL PROTECTED] svn]# ls -al
total 92
drwxr-xr-x 2 root root 4096 Feb 26 19:29 .
drwxr-xr-x 4 root root 4096 Feb 26 19:29 ..
-rw-r--r-- 1 root root  760 Feb 26 19:29 __init__.py
-rw-r--r-- 1 root root  226 Feb 26 19:29 __init__.pyc
-rw-r--r-- 1 root root  861 Feb 26 19:29 client.py
-rw-r--r-- 1 root root  317 Feb 26 19:29 client.pyc
-rw-r--r-- 1 root root 7193 Feb 26 19:29 core.py
-rw-r--r-- 1 root root 6348 Feb 26 19:29 core.pyc
-rw-r--r-- 1 root root 2018 Feb 26 19:29 delta.py
-rw-r--r-- 1 root root 2552 Feb 26 19:29 delta.pyc
-rw-r--r-- 1 root root 3924 Feb 26 19:29 fs.py
-rw-r--r-- 1 root root 3353 Feb 26 19:29 fs.pyc
-rw-r--r-- 1 root root  841 Feb 26 19:29 ra.py
-rw-r--r-- 1 root root  301 Feb 26 19:29 ra.pyc
-rw-r--r-- 1 root root 9580 Feb 26 19:29 repos.py
-rw-r--r-- 1 root root 6797 Feb 26 19:29 repos.pyc
-rw-r--r-- 1 root root  841 Feb 26 19:29 wc.py
-rw-r--r-- 1 root root  301 Feb 26 19:29 wc.pyc

System is "generic linux 2.6" on ARM5tejl


With best regards

Tomas Larsson
TL Engineering & Consultants
Engelbrektsgatan 121
SE 506 39 Borås
Sweden

+46 739 932 673

http://www.tlec.se


Verus Amicus Est Tamquam Alter Idem

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


Order of addresses returned by socket.gethostbyname_ex()

2011-08-21 Thread Tomas Lidén
In what order are the addresses returned by socket.gethostbyname_ex()?

We know that gethostbyname() is indeterministic but hope that
gethostbyname_ex() has a specified order.

Best regards,
Tomas
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Order of addresses returned by socket.gethostbyname_ex()

2011-08-22 Thread Tomas Lidén
On 22 Aug, 10:15, Steven D'Aprano  wrote:
> On Mon, 22 Aug 2011 04:37 pm Tomas Lidén wrote:
>
> > In what order are the addresses returned by socket.gethostbyname_ex()?
>
> > We know that gethostbyname() is indeterministic but hope that
> > gethostbyname_ex() has a specified order.
>
> Did you want a particular order, or just any deterministic order?
>
> Have you considered sorting the addresses yourself?
>
> --
> Steven

In this particular case we have a host with several connections (LAN,
WIFI, VmWare adapters etc). When using gethostbyname() we got a VmWare
adapter but we wanted to get the LAN (or the "best" connection to our
server). With gethostbyname_ex() the ordering seemed to become LAN,
Wifi, etc and that's good for us. But we don't know if this holds on
other platforms (we're running on Windows 7).

A cross-platform deterministic order would be excellent for us.

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


Re: Order of addresses returned by socket.gethostbyname_ex()

2011-08-22 Thread Tomas Lidén
On 22 Aug, 12:06, Cameron Simpson  wrote:
>
> It would not surprise me if the order was related to the order a scan of
> the system interfaces yields information, and I would imagine that may
> be influenced by the order in which the interfaces were initialised.
>
> So getting the LAN first may merely be fortuitous.
> I wouldn't rely on it, especially if interfaces come and go.
>

We did try to disable/enable the interfaces in different orders, but
always got the same return order from gethostbyname_ex(). So it looked
pretty stable (on that specific OS). There's been some testing on
Linux as well, but since this should be used in a general cross
platform tool we wanted to check the exact behaviour of the method.

> What if you queried your routing table instead? Usually there's just one
> default route, and hopefully it would be configured to use the "best"
> interface.
>

Hmm... perhaps. How would you do that?
/Tomas
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Order of addresses returned by socket.gethostbyname_ex()

2011-08-22 Thread Tomas Lidén
On 22 Aug, 12:36, Chris Angelico  wrote:
>
> Explicit is better than implicit. Instead of using the order, have a
> config file that chooses the one(s) you want by name or IP address. Of
> course, if you're on Unix/Linux, you can use the interface name (eth0,
> eth1, etc) with a fair degree of reliability.
>

The config file solution is not suitable, I think. This code should
run in a general cross platform application (Texttest), and we do not
want each user of that system to be forced to edit a config file..

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


Re: Order of addresses returned by socket.gethostbyname_ex()

2011-08-22 Thread Tomas Lidén
On 22 Aug, 13:26, Roy Smith  wrote:
> In article
> <356978ef-e9c1-48fd-bb87-849fe8e27...@p5g2000vbl.googlegroups.com>,
>  Tomas Lidén  wrote:
>
> > In what order are the addresses returned by socket.gethostbyname_ex()?
>
> > We know that gethostbyname() is indeterministic but hope that
> > gethostbyname_ex() has a specified order.
>
> Why would you hope that?  Or maybe a better question is, why would you
> expect that?  In general, all name resolution calls return results in
> arbitrary order.  In some cases, results are intentionally changed on
> every call (i.e. round-robin) in an attempt at load sharing.
>
> What kind of ordering were you hoping for?

See previous posts.

Basically I was asking about the contract for this method.. hoping
that it is deterministic.
Our testing indicated that the interfaces are returned in a specific
order, but we want to know if this is really the case (on all
platforms).

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


Re: Order of addresses returned by socket.gethostbyname_ex()

2011-08-22 Thread Tomas Lidén
OK - thank you all for your contributions.
/T
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [RELEASE] Python 3.9.0 is now available, and you can already test 3.10.0a1!

2020-10-07 Thread Tomas Hrnciar
Hello,

I am getting PGP error with the new Python3.10.0a1.
I would like to ask what key it was signed with and whether it wasn't
Pablo's.
If so, it might be missing in pubkeys.txt.

Thank you.
T.

On Mon, Oct 5, 2020 at 10:48 PM Łukasz Langa  wrote:

> On behalf of the Python development community and the Python 3.9 release
> team, I’m pleased to announce the availability of Python 3.9.0.
>
> Python 3.9.0 is the newest feature release of the Python language, and it
> contains many new features and optimizations. You can find Python 3.9.0
> here:
>
> https://www.python.org/downloads/release/python-390/ <
> https://www.python.org/downloads/release/python-390/>
>
> Most third-party distributors of Python should be making 3.9.0 packages
> available soon.
>
> See the “What’s New in Python 3.9 <
> https://docs.python.org/release/3.9.0/whatsnew/3.9.html>” document for
> more information about features included in the 3.9 series. Detailed
> information about all changes made in 3.9.0 can be found in its change log <
> https://docs.python.org/release/3.9.0/whatsnew/changelog.html#changelog>.
>
> Maintenance releases for the 3.9 series will follow at regular bi-monthly
> intervals starting in late November of 2020.
>
>
>
> OK, boring! Where is Python 4?
>
> Not so fast! The next release after 3.9 will be 3.10. It will be an
> incremental improvement over 3.9, just as 3.9 was over 3.8, and so on.
>
> In fact, our newest Release Manager, Pablo Galindo Salgado, prepared the
> first alpha release of what will become 3.10.0 a year from now. You can
> check it out here:
>
> https://www.python.org/downloads/release/python-3100a1/ <
> https://www.python.org/downloads/release/python-3100a1/>
>
> We hope you enjoy the new releases!
>
> Thanks to all of the many volunteers who help make Python Development and
> these releases possible! Please consider supporting our efforts by
> volunteering yourself or through organization contributions to the Python
> Software Foundation.
>
> https://www.python.org/psf/ 
> More resources
>
> Online Documentation 
> PEP 596 , 3.9 Release Schedule
> PEP 619 , 3.10 Release Schedule
> Report bugs at https://bugs.python.org .
> Help fund Python and its community  >.
> Your friendly release team,
> Ned Deily @nad 
> Steve Dower @steve.dower 
> Pablo Galindo Salgado @pablogsal 
> Łukasz Langa @ambv 
> ___
> Python-announce-list mailing list -- python-announce-l...@python.org
> To unsubscribe send an email to python-announce-list-le...@python.org
> https://mail.python.org/mailman3/lists/python-announce-list.python.org/
> Member address: thrnc...@redhat.com
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: lies about OOP

2004-12-14 Thread Tomas Christiansen
projecktzero wrote:
> A co-worker considers himself "old school" in that he hasn't seen the
> light of OOP ... He thinks that OOP has more overhead and is slower
> than programs written the procedural way.

He may be right, but consider the alternatives.

Think of an integer. An integer is an object!

You can assign a new integer-value to the object.
You can read the integer-value of the object.
(The integer can be part of complex expressions.)

Usually you are unaware (or don't care) _how_ the object is implemented.
Wether the bits are red, green, turns upside-down or are inverted - you
doesn't really care, as long as it can hold the values that you want it to
hold and be used in the relevant contexts (addition, multiplication, ...).

Some lanugages gives you the choise of many integer-implementations, some
languages gives you only a few choises and some languages gives you only one
choise.

Surely we can agree that the presence of an integer-object is extremely
useful! If you had to do all the integer-stuff in machine code _every_ time,
you would soon be very, very tired of working with integers. There is no
doubt that objects are (or can be) extremely useful, time-saving and very
efficient. Chances are that your own machine-code integer-inplementation is
not nearly as good as the one made by a team of top-tuned programmers (no
offense) programming the integer-implementation "object".

Wether the language should give you the choise of one, some, many or
extremely many integer-implementations, depends entirely on your needs
("what a pervert - he needs an integer!"). Lowering the number of choises of
implementations, rises the chances of having to chose a "not very good"
implementation. Letting the language automaticly chose the right one, frees
your mind to other processes, but at the risk of some kind of run-time
overhead.

---
Tomas

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


Different behavior with multiprocessing

2013-03-04 Thread Tomas Kotal
Hi all.

Recently I discovered a strange behavior with multiprocessing library and call 
to function os.system (a different behavior under Linux and Windows to be more 
specific). I have this simple testing script:


import sys
import os
from multiprocessing import Process

def do_fork(cmd):
ret = os.system(cmd)
# print result of call
print ret
os._exit(ret)

if __name__ == "__main__":
cmds = [ "dir", "xy" ]

procs = []
for cmd in cmds:
proc = Process(target=do_fork, args=(cmd, ))
proc.start()
procs.append( proc )

for proc in procs:
proc.join()
print "exitcode: %d" % proc.exitcode

print "ok" 


This script just starts 2 processes. Each process executes one command in 
system shell and exits setting it's exit code same as exit code of a system 
call. There are 2 commands: "dir" (which works fine on Windows and Linux) and 
"xy" (which is supposed to fail under both systems). The strange thing is that 
when I run this script under Windows I get this output:

0
1
exitcode: 0
exitcode: 1
ok

The first 0 and 1 are results of os.system call which are printed from child 
processes. Rest of lines are printed from main process. This is expected output.

But when I run same script on Linux, what I get is this:

0
32512
exitcode: 0
exitcode: 0
ok

Although the second command fails and returns exit code 32512, the exit code 
from process in parent process gives me 0. I tried to change the script to use 
fork() instead of Process but the result was same.

Can anybody explain me what's the problem here?

(I use Python 2.6 on both Windows and Linux machines)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Different behavior with multiprocessing

2013-03-04 Thread Tomas Kotal
> Under Unix, the return value from os.system() encodes more than one
> 
> piece of information:
> 
> 
> 
> http://docs.python.org/2/library/os.html#os.system
> 
> http://docs.python.org/2/library/os.html#os.wait
> 
> 
> 
> 32512 is 127*256, meaning that the shell exited with return code 127
> 
> when given an unrecognized command.
> 
> 
> 
> ChrisA

Well the point is not the difference between return values of os.system under 
Windows and Linux.

The point is that I set the exist code of child process with os._exit() which 
works fine on Windows but on Linux the process.exitcode returns always 0.

What is very strange is, that if I set return code to some other value, like:

...
os._exit( len(cmd) )
...

Then I got exit codes 3 and 2 under Linux, which is correct. But when I do 
something like this:

...
ret = os.system(cmd)
print ret # this print real value, like 32512
os._exit(ret) # exitcode of this child process will be 0 on Linux
...

It doesn't work, which seems very strange to me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Different behavior with multiprocessing

2013-03-04 Thread Tomas Kotal
Dne pondělí, 4. března 2013 15:31:41 UTC+1 Tomas Kotal napsal(a):
> Hi all.
> 
> 
> 
> Recently I discovered a strange behavior with multiprocessing library and 
> call to function os.system (a different behavior under Linux and Windows to 
> be more specific). I have this simple testing script:
> 
> 
> 
> 
> 
> import sys
> 
> import os
> 
> from multiprocessing import Process
> 
> 
> 
> def do_fork(cmd):
> 
> ret = os.system(cmd)
> 
> # print result of call
> 
> print ret
> 
> os._exit(ret)
> 
> 
> 
> if __name__ == "__main__":
> 
> cmds = [ "dir", "xy" ]
> 
> 
> 
> procs = []
> 
> for cmd in cmds:
> 
> proc = Process(target=do_fork, args=(cmd, ))
> 
> proc.start()
> 
> procs.append( proc )
> 
> 
> 
> for proc in procs:
> 
> proc.join()
> 
> print "exitcode: %d" % proc.exitcode
> 
> 
> 
> print "ok" 
> 
> 
> 
> 
> 
> This script just starts 2 processes. Each process executes one command in 
> system shell and exits setting it's exit code same as exit code of a system 
> call. There are 2 commands: "dir" (which works fine on Windows and Linux) and 
> "xy" (which is supposed to fail under both systems). The strange thing is 
> that when I run this script under Windows I get this output:
> 
> 
> 
> 0
> 
> 1
> 
> exitcode: 0
> 
> exitcode: 1
> 
> ok
> 
> 
> 
> The first 0 and 1 are results of os.system call which are printed from child 
> processes. Rest of lines are printed from main process. This is expected 
> output.
> 
> 
> 
> But when I run same script on Linux, what I get is this:
> 
> 
> 
> 0
> 
> 32512
> 
> exitcode: 0
> 
> exitcode: 0
> 
> ok
> 
> 
> 
> Although the second command fails and returns exit code 32512, the exit code 
> from process in parent process gives me 0. I tried to change the script to 
> use fork() instead of Process but the result was same.
> 
> 
> 
> Can anybody explain me what's the problem here?
> 
> 
> 
> (I use Python 2.6 on both Windows and Linux machines)

Seems like I found the problem: os._exit probably takes as parametr unsigned 
char, so it uses as error code whatever value it gets modulo 256:

os._exit(1)  # process.exitcode == 1
os._exit(255)  # process.exitcode == 255
os._exit(256)  # process.exitcode == 0
os._exit(257)  # process.exitcode == 1
os._exit(32512)  # process.exitcode == 0

So on Linux it's necesary to call something like this:
os._exit( os.system(cmd) >> 8 )

Because the first byte of return value on Linux is number of signal which kills 
the process and the second one is actual exit code.

http://docs.python.org/2/library/os.html#os.wait
-- 
http://mail.python.org/mailman/listinfo/python-list


Simple TCP "relay" or "proxy"

2005-05-13 Thread Tomas Christiansen
Im trying to make a simple TCP socket "relay" or "proxy", but my skills in 
Python are not high (yet).

The only thing it should do, is to open the connection on behalf of the 
client, and when the client closes the connection, it should do so too. 
It's going to "relay" PCL and/or PostScript printjobs to a TCP/IP printer.

Does anyone have some sugggestions on code-examples? I've tried googling 
around, but couldn'r find anythin usefull.

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


Send all packets (socket programming)

2005-05-22 Thread Tomas Christiansen
Is there a way to make shure that all packets has been sent before issuing 
a Shutdown and/or Close on a (TCP) Socket?

The problem is that "the other end" interprets a reset-flag (RST) on an IP-
packet as an indication of an error. Instead the finish-flag (FIN) must be 
set, in order to close the connection non-errornously. That can be achieved 
by using socket.shutdown(SHUT_RDWR) followed by socket.close().

BUT if all data has not been sent, sometimes shutdown(SHUT_RDWR) followed 
by close(), sets RST, and the other end thinks that something went wrong 
(the other end is some unknown TCP/IP printer) and goes to an error-state.

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


urllib2 slow for multiple requests

2009-05-13 Thread Tomas Svarovsky
Hello everybody, really new to python, so bear with me. I am trying to
do some very basic scraping tool. Bascally it just grabs a page xy
times and tells me how long it took. When I do this once, it is
blazingly fast, but when I increase the number of repetitions, it is
slowing down considerably (1 is like 3 ms, 100 takes 6 seconds). I
have done implementations in couple more languages (php, ruby) and
none of them seems to suffer from a similar problem and it seems, that
it behaves linearly. Maybe it is a known issue in urllib2, or I am
simply using it badly. I am using python 2.4.3, machine has CentOS,
below is the sc. Thanks in advance

import urllib2
from datetime import datetime

def application():
start = datetime.now()
req = urllib2.Request("http://127.0.0.1/gdc/about";, None,
{'Accept': 'application/json'})
for number in range(100):
  response = urllib2.urlopen(req)
end = datetime.now()
output = end - start
print output

application()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: urllib2 slow for multiple requests

2009-05-14 Thread Tomas Svarovsky
On May 13, 4:55 pm, cgoldberg  wrote:
> > Bascally it just grabs a page xy
> > times and tells me how long it took.
>
> you aren't doing a read(), so technically you are just connecting to
> the web server and sending the request but never reading the content
> back from the socket.  So your timing wouldn't be accurate.
>
> try this instead:
> response = urllib2.urlopen(req).read()
>
> But that is not the problem you are describing...

Thanks for this pointer, didn't come to my mind.

> > when I increase the number of repetitions, it is
> > slowing down considerably (1 is like 3 ms, 100 takes 6 seconds).
> > Maybe it is a known issue in urllib2
>
> I ran your code and can not reproduce that behavior.  No matter how
> many repetitions, I still get a similar response time per transaction.
>
> any more details or code samples you can provide?
>

I don;t know, I have tried the program on my local MacOs, where I have
several python runtimes installed and there is huge dfference between
result after running at 2.6 and 2.4. So this might be the problem.
When ran on the 2.6 result are comparable to php and better than ruby,
which is what I expect.

The problem is, that CentOS is running on the server and there is only
2.4 available. On wich version did you ran these tests?

Thanks

> -Corey Goldberg

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


Re: urllib2 slow for multiple requests

2009-05-14 Thread Tomas Svarovsky
One more thing, since I am stuck with 2.4 (and if this is really 2.4
issue), is there some substitution for urllib2?

On May 14, 11:00 am, Tomas Svarovsky 
wrote:
> On May 13, 4:55 pm, cgoldberg  wrote:
>
> > > Bascally it just grabs a page xy
> > > times and tells me how long it took.
>
> > you aren't doing a read(), so technically you are just connecting to
> > the web server and sending the request but never reading the content
> > back from the socket.  So your timing wouldn't be accurate.
>
> > try this instead:
> > response = urllib2.urlopen(req).read()
>
> > But that is not the problem you are describing...
>
> Thanks for this pointer, didn't come to my mind.
>
> > > when I increase the number of repetitions, it is
> > > slowing down considerably (1 is like 3 ms, 100 takes 6 seconds).
> > > Maybe it is a known issue in urllib2
>
> > I ran your code and can not reproduce that behavior.  No matter how
> > many repetitions, I still get a similar response time per transaction.
>
> > any more details or code samples you can provide?
>
> I don;t know, I have tried the program on my local MacOs, where I have
> several python runtimes installed and there is huge dfference between
> result after running at 2.6 and 2.4. So this might be the problem.
> When ran on the 2.6 result are comparable to php and better than ruby,
> which is what I expect.
>
> The problem is, that CentOS is running on the server and there is only
> 2.4 available. On wich version did you ran these tests?
>
> Thanks
>
> > -Corey Goldberg

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


Re: urllib2 slow for multiple requests

2009-05-14 Thread Tomas Svarovsky
On May 14, 11:57 am, "Richard Brodie"  wrote:
> "cgoldberg"  wrote in message
>
> news:9ae58862-1cb2-4981-ae6a-0428c7684...@z5g2000vba.googlegroups.com...
>
> > you aren't doing a read(), so technically you are just connecting to
> > the web server and sending the request but never reading the content
> > back from the socket.
>
> > But that is not the problem you are describing...
>
> It might be, if the local server doesn't scale well enough to handle
> 100 concurrent requests.

This is a good point, but then it would manifest regardless of the
language used AFAIK. And this is not the case, ruby and php
implementations are working quite fine.

Thanks for reply
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: urllib2 slow for multiple requests

2009-05-15 Thread Tomas Svarovsky
On May 14, 6:33 pm, "Richard Brodie"  wrote:
> "Tomas Svarovsky"  wrote in message
>
> news:747b0d4f-f9fd-4fa6-bb6d-0a4365f32...@b1g2000vbc.googlegroups.com...
>
> > This is a good point, but then it would manifest regardless of the
> > language used AFAIK. And this is not the case, ruby and php
> > implementations are working quite fine.
>
> What I meant was: not reading the data and leaving the connection
> open is going to force the server to handle all 100 requests concurrently.
> I'm guessing that's not what your other implementations do.
> What happens to the timing if you call response.read(), response.close() ?

Now I get it, but nevertheless, even when I explicitely read from the
socket and then close it properly, the timing still doesn't change.

Thanks for advice though
-- 
http://mail.python.org/mailman/listinfo/python-list


Using MAPI (simplemapi.py)

2006-03-22 Thread Tomas Brabenec
Hi all,

i need open new messages in default e-mail client from my application in 
windows.
I using simplemapi.py (http://www.kirbyfooty.com/simplemapi.py)
But not worked correctly.

This is a error message:

Traceback (most recent call last):
  File "Q:\Notebook\frmApp.py", line 206, in on_mnu_email

simplemapi.SendMail("",self.tree.GetItemText(self.tree.GetSelection()),self.memo.GetValue(),"")
  File "C:\bra\Programs\Notebook\lib\simplemapi.py", line 141, in SendMail
raise WindowsError, "MAPI error %i" % rc
WindowsError: MAPI error 3221225477


Please, where is a problem ?

Tomas Brabenec
http://brabenec.net
 

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


Re: import random module

2006-03-22 Thread Tomas Brabenec
You must rename Your script.
Your script doesn't same name as calling module.

Tomas Brabenec
http://brabenec.net 


DataSmash napsal(a):
> Hi,
> When I import the random module at the python interpreter, it works
> fine:
>   
>>>> import random
>>>> x = random.randint(1,55)
>>>> print x
>>>> 
> 14
>   
>
> BUT, when I put the same code in a python script:
> * random.py:
>
> import random
>
> x = random.randint(1,55)
> print x
>
> and run it at the command line, I get:
> Traceback (most recent call last):
>File p:\temp\random.py, line 7, in ?
>   import random
>File p:\temp\random.py, line 8, in ?
>   x = random.randint(1,55)
> AttributeError: 'module" object has no attribut 'randint'
>
> I run scripts at the command line everyday so there must be something
> specifically
> wrong with the "random" module, unless I'm totally missing something
> here.
>
> Any ideas?
> Thanks,
> R.D.
>
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


subprocess troubles

2010-01-21 Thread Tomas Pelka

Hey all,

have a problem with following piece of code:

--
import subprocess

paattern = "python"
cmd = "/usr/bin/locate"
arg1 = " -i"
arg2 = " -d /var/www/books/mlocate.db"
arg3 = str(" " + pattern)

p1 = subprocess.Popen([cmd, arg1, arg2, arg3], shell=False, 
stdout=subprocess.PIPE, stderr=subprocess.PIPE)

(stdoutdata, stderrdata) = p1.communicate()

print p1.returncode
print "%s -- %s" % (stdoutdata, stderrdata)
--

But return code is always 1 and command do not return any result/error 
(stdoutdata, stderrdata are None). If I run this command 
(/usr/bin/locate -i -d /var/www/books/mlocate.db python) from standard 
shell everything goes fine.


Could you please give me an advice what I'm doing wrong?

Thanks
Cheers

--
Tom

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


Re: subprocess troubles

2010-01-21 Thread Tomas Pelka

On 01/21/2010 11:39 AM, Javier Collado wrote:

Hello,

If you set shell=False, then I think that arg2 should be separated
into two different parts.

Also, arg3 could be set just to pattern (no need to add extra spaces
or using str function).

Best regards,
 Javier

2010/1/21 Tomas Pelka:


Hey all,

have a problem with following piece of code:

--
import subprocess

paattern = "python"
cmd = "/usr/bin/locate"
arg1 = " -i"
arg2 = " -d /var/www/books/mlocate.db"
arg3 = str(" " + pattern)

p1 = subprocess.Popen([cmd, arg1, arg2, arg3], shell=False,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdoutdata, stderrdata) = p1.communicate()

print p1.returncode
print "%s -- %s" % (stdoutdata, stderrdata)
--

But return code is always 1 and command do not return any result/error
(stdoutdata, stderrdata are None). If I run this command (/usr/bin/locate -i
-d /var/www/books/mlocate.db python) from standard shell everything goes
fine.

Could you please give me an advice what I'm doing wrong?

Thanks
Cheers

--
Tom

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




Thanks Javier for advice, but sill same result. I'm running this code as 
cgi  script from apache. Weird is that when i run  it from shell as 
apache user, like



# su -s /bin/bash -c "/usr/bin/locate -i -d /var/www/books/mlocate.db 
python; echo $?" apache

0
---
I always get "0", but as cgi it returns "1". When I run this script by 
other user (tom), I'll obtain nonzero output what is OK.


Additional info:
#  su -s /bin/bash -c "ls -l /var/www/books/mlocate.db" apache
-rw-rw-r-- 1 tom books 1465653 Jan 20 13:33 /var/www/books/mlocate.db
so db is readable by apache

Whore source attached.

--
Tom


#!/usr/bin/python

import cgi
import cgitb; cgitb.enable()  # for troubleshooting
import subprocess
import sys
import os
sys.stderr = sys.stdout

command = ""
result = ""
stdoutdata = ""
stderrdata = ""

# Create instance of FieldStorage
form = cgi.FieldStorage()

# Get data from field 'pattern'
pattern = form.getvalue('pattern', 'None')
# Get data from field 're'
re = form.getvalue('re')

cmd = "/usr/bin/locate"
arg1 = "-i"
arg2a = "-d"
arg2b = "/var/www/books/mlocate.db"
arg3 = "-r"
arg4 = str(pattern)
p1 = None

if re == "re":
p1 = subprocess.Popen([cmd, arg1, arg2a, arg2b, arg3, arg4], 
shell=False, \
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
command = "%s %s %s %s %s %s" % (cmd, arg1, arg2a, arg2b, arg3, arg4)
else:
p1 = subprocess.Popen([cmd, arg1, arg2a, arg2b, arg4], shell=False, \
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
command = "%s %s %s %s %s " % (cmd, arg1, arg2a, arg2b, arg4)

(stdoutdata, stderrdata) = p1.communicate()

print "Content-type: text/html"
print

# debug
print "UID: %i " % os.getuid()
print "Search pattern: %s " % pattern
print """stdout: %s 
stderr: %s 
""" % (stdoutdata, stderrdata)
print "Return code: %i" % p1.returncode

print """

Hledej v books


Hledany vyraz:



Hledat pomoci regularniho vyrazu?






"""
if p1.returncode == 0:
if stdoutdata:
result = stdoutdata
else:
result = "Nic takoveho sem nenasel :/"

else:
result = 'Chyba: \
index souboru je bud zastaraly nebo doslo \
k chybe pri vyhledavani.%s \
%s' % (command, stderrdata)

print """
Hledany vyraz "%s" se nachazi v nasledujicich adresarich
%s
 
""" % (pattern, result)


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


Module inspect Bug

2009-10-05 Thread Tomas Zulberti
Hi. I have a class that extends collections.MutableMapping. I am
checking if it is abstract, using the module inspect. But isabstract
returns a number different from zero insted of True or False. The
problem with that is that sometimes it returns False when the class
isn't an abstract.

>>> inspect.isabstract(collections.MutableMapping)
1048576
>>> inspect.isabstract(os)
False

Its true that the condition nevertheless will be True on the if, but
the return value I think that should be boolean.

Thanks,
Tomas Zulberti

pd: Sorry for my bad English...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Module inspect Bug

2009-10-06 Thread Tomas Zulberti
On Oct 6, 1:36 am, "Gabriel Genellina"  wrote:
> En Mon, 05 Oct 2009 11:59:01 -0300, Tomas Zulberti   
> escribió:
>
> > Hi. I have a class that extends collections.MutableMapping. I am
> > checking if it is abstract, using the moduleinspect. But isabstract
> > returns a number different from zero insted of True or False. The
> > problem with that is that sometimes it returns False when the class
> > isn't an abstract.
>
> >>>>inspect.isabstract(collections.MutableMapping)
> > 1048576
> >>>>inspect.isabstract(os)
> > False
>
> > Its true that the condition nevertheless will be True on the if, but
> > the return value I think that should be boolean.
>
> It would be nice ifinspect.isabstract() returned True/False, but 1048576  
> is as good as any other true value, ok? You should not rely on specific  
> values, nor compare the result against True nor False directly.
>


> Anyway, given that no other isXXX function behaves that way, and  
> inspect.isgeneratorfunction() uses a similar construct but always returns  
> True/False, I've submitted a bug+patch:http://bugs.python.org/issue7069
>

Thanks for the help... I wasn't using that the returned value was a
boolean, but the other methods returned a boolean, so I found that was
strange...

Thank you a lot,
Tomas Zulberti
-- 
http://mail.python.org/mailman/listinfo/python-list


how to run part of my python code as root

2010-02-04 Thread Tomas Pelka
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hey,

is there possibility how to run part of my code (function for example)
as superuser.

Or only way how to do this is create a wrapper and run is with Popen
through sudo (but I have to configure sudo to run "whole" python as root).

Thanks for advice.

- --
Tom

Key fingerprint = 06C0 23C6 9EB7 0761 9807  65F4 7F6F 7EAB 496B 28AA
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAktrGoYACgkQf29+q0lrKKqaNACdEvfg+g0n3DzFr/7R33y2Nesy
hK8An3ZlpUEEibf0Q1wVET/KpXnsv/PO
=JKro
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to run part of my python code as root

2010-02-06 Thread Tomas Pelka
sjdevn...@yahoo.com wrote:
> On Feb 4, 2:05 pm, Tomas Pelka  wrote:
>> -BEGIN PGP SIGNED MESSAGE-
>> Hash: SHA1
>>
>> Hey,
>>
>> is there possibility how to run part of my code (function for example)
>> as superuser.
>>
>> Or only way how to do this is create a wrapper and run is with Popen
>> through sudo (but I have to configure sudo to run "whole" python as root).
>

thank you for excellent explanation.

> In decreasing order of desirability:
> 1. Find a way to not need root access (e.g. grant another user or
> group access to whatever resource you're trying to access).
> 2. Isolate the stuff that needs root access into a small helper
> program that does strict validation of all input (including arguments,
> environment, etc); when needed, run that process under sudo or
> similar.

I thing this approach is the best for me. But how to connect two
separated processes, one running with root privileges and second without
superuser privileges? Is was thinking about Queues from multiprocessing,
didn't you know if it is a good choice?

> 2a. Have some sort of well-verified helper daemon that has access to
> the resource you need and mediates use of that resource.
> 3. Run the process as root, using seteuid() to switch between user and
> root privs.  The entire program must be heavily verified and do strict
> validation of all inputs.  Any attacker who gets control over the
> process can easily switch to root privs and do damage.  This is
> generally a bad idea.


-- 
Tom

Key fingerprint = 06C0 23C6 9EB7 0761 9807  65F4 7F6F 7EAB 496B 28AA
-- 
http://mail.python.org/mailman/listinfo/python-list


object exported through manager from multiprocess module

2010-07-08 Thread Tomas Pelka

Hi all,

have troubles with exporting objects through managers from multiprocess 
module, see example:


Worker.py:
###
from multiprocessing import Process
from multiprocessing.managers import BaseManager
import pcapy
from impacket.ImpactDecoder import EthDecoder

__all__ = ['Worker']

class Worker(Process):
'''
Class for sniffing packets, runnig as root
'''

public = ['go', 'terminate']

def __init__(self):
super(Worker, self).__init__()
self.iface = ''
self.expr = ''
self.pcap = ''
# define packet decoder
self.decoder = EthDecoder()
# key for queue daemon, remotely on localhost:5000
self._keyQ = '10b222970537b97919db36ec757370d2'
class QueueManager(BaseManager): pass
QueueManager.register('get_dataQueue')
self._m = QueueManager(address=('127.0.0.1', 5000), 
authkey=self._keyQ)

self._m.connect()
self.dataQueue = self._m.get_dataQueue()
def go(self, iface, expr):
'''
start sniffer
'''
print "Starting sniffer"
self.iface = iface
self.expr = expr
super(Worker, self).start()
def terminate(self):
'''
terminate sniffer
'''
super(Worker, self).terminate()
def run(self):
print "sniffing ..."
print self.iface
print self.expr
self.pcap = pcapy.open_live(self.iface, 1500, 1, 0)
self.pcap.setfilter(self.expr)
self.pcap.loop(0, self.__packetHandler)
print "... done"
def __packetHandler(self, hdr, data):
'''
handles packets and put them in to the queue
'''
print "Handling packets"
#print data
print "Queue size: %i" % self.dataQueue.qsize()
print self.decoder.decode(data)
self.dataQueue.put(data)

Export object (Worker):
###
from Worker import Worker

class SniffManager(BaseManager): pass
SniffManager.register('Worker', callable=Worker)
Sm = SniffManager(address=('127.0.0.1', 5001), 
authkey='f1f16683f3e0208131b46d37a79c8921')

Ss = Sm.get_server()
Ss.serve_forever()


Call object methods remotely:
###
# get remote object
class WorkerManager(BaseManager): pass
WorkerManager.register('Worker')
w = WorkerManager(address=('127.0.0.1', 5001), 
authkey='f1f16683f3e0208131b46d37a79c8921')

w.connect()
worker = w.Worker()

worker.go(iface="ethx", expr="whatever") # WORKS FINE

but

worker.terminate()

File "/home/tom/web2py/applications/init/controllers/sniffer.py", line 
143, in index

worker.terminate()
File "", line 2, in terminate
File "/usr/lib/python2.6/multiprocessing/managers.py", line 740, in 
_callmethod

raise convert_to_error(kind, result)
AttributeError: 'NoneType' object has no attribute 'terminate'

Which is strange from my point of view, don't you think?
Thanks for advices,
cheers

--
Tomas Pelka

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