windows 7 create directory with read write execute permission for everybody

2011-06-26 Thread Gelonida

Hi,

What do I have to do under python windows to create a directory with all 
permissions, such, that new files / directories created below will 
inherit the permissions.



The reason I am asking is, that I'd like to create a directory structure 
where multiple users should be allowed to read / write / create files 
and directories.



Alternatively it would be even better to specify exactly which users 
should be allowed to access the directory tree.


I never used / modified Windows file permissions except once or twice 
via explorer. I'm thus a little shaky with Microsoft's file permissions.


Thanks in advance for your answer.

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


Re: windows 7 create directory with read write execute permission for everybody

2011-06-26 Thread Gelonida

On 6/26/2011 11:24 PM, Irmen de Jong wrote:

On 26-6-2011 22:57, Gelonida wrote:

Hi,

What do I have to do under python windows to create a directory with all 
permissions,
such, that new files / directories created below will inherit the permissions.

The reason I am asking is, that I'd like to create a directory structure where 
multiple
users should be allowed to read / write / create files and directories.


Isn't this the default when you create a new directoy in Windows? (unless you're
creating it in some location where access is restricted, for instance C:\ or 
c:\program
files).  I'd try os.mkdir first in any case and check if it does the job.


Have to check when I'm back to the machine in question.

On this machine I used os.mkdir() / os.makedirs() and I had permission 
problems , but only on Windows7. This is why I was asking the question.


I expect, that the win32 libraries might have function calls allowing to 
control the permissions of a directory, but I am really bad with win32 
as I worked mostly with Linux or code, that was platform independent, 
which Windows file permission handling is not :-( .







Alternatively it would be even better to specify exactly which users should be 
allowed
to access the directory tree.


Sorry, can't help you with this. I guess you'll need to use the windows 
extensions for
Python here and deal with user accounts and ACL's.


Yep I'm afraid that's the way to go and where I hoped somebody would 
have a few tiny example lines or pointers to the functions in question 
to be used.




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


Re: windows 7 create directory with read write execute permission for everybody

2011-06-27 Thread Gelonida

Hi Tim,

On 6/27/2011 9:39 AM, Tim Golden wrote:

On 26/06/2011 21:57, Gelonida wrote:

Hi,

What do I have to do under python windows to create a directory with all
permissions, such, that new files / directories created below will
inherit the permissions.

. . .


I never used / modified Windows file permissions except once or twice
via explorer. I'm thus a little shaky with Microsoft's file permissions.


Have a look at this to see if takes you anywhere:

http://timgolden.me.uk/python/win32_how_do_i/add-security-to-a-file.html


That's exactly the kind of link I was looking for.

Thanks a lot.

For the current existing code I can just replace all open(fname, "w") 
calls with a custom wrapper and I should be fine.


One thing, which I would still like to know (though I don't need it for 
my current task) is what to do to to setup an ACE on a directory, such, 
that all entries below will inherit the directory's access settings.


I will look into this lateron.




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


Re: windows 7 create directory with read write execute permission for everybody

2011-06-27 Thread Gelonida

On 6/27/2011 7:21 AM, Thorsten Kampe wrote:

* Gelonida (Sun, 26 Jun 2011 22:57:57 +0200)

What do I have to do under python windows to create a directory with
all permissions, such, that new files / directories created below will
inherit the permissions.


Exactly nothing (except creating the directory, of course).

:-) I thought so as well.

I asume the security settings of the directory below which I created 
mine were setup to give no write permission to Everybody.


If I changed the parent directories security settings with the explorer 
everything behaved fine.


So if the parent directories security settings are unknown it seems 
mkdir() is not sufficient and I have to use some win32 calls

as mentioned in the url of Tim's reply to have the correct settings.

http://timgolden.me.uk/python/win32_how_do_i/add-security-to-a-file.html





The reason I am asking is, that I'd like to create a directory
structure where multiple users should be allowed to read / write /
create files and directories.

Alternatively it would be even better to specify exactly which users
should be allowed to access the directory tree.

I never used / modified Windows file permissions except once or twice
via explorer. I'm thus a little shaky with Microsoft's file
permissions.


Microsoft's permission handling hasn't changed in the last eleven years.
So you had a lot of time to learn about it.

but never the need so far.

> Do you see this "Learn about

access control and permissions" link when you're in the security tab?
Just click on it.

Will click



Thorsten




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


debugging segfaults in pythen PyQt (QWebview)

2011-03-03 Thread Gelonida
Hi,

I have a QWebview application, which segfaults rather often,
but not all the time.

I assume it is some kind of race condition when loading a certain web
page with quite some built in AJax.



How can I debug it?

The application crashes under Windows and under Linux.


I enabled already core dumps and am able to

start

gdb python.exe core

I guess the command "bt"
will be able to give m a backtrace of  the C program


Is there any way to obtain the related  backtrace of the python script?


I'm at a complete loss of what I am doing wrong in my script and would
hope to get at least some indication.


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


Good literature about python twisted

2011-03-15 Thread gelonida
Hi,

Just wanted to learn more about python twisted and wanted to buy the
O'Reilly book.

However I noticed, that the book is from 2005.


Is this book still worth it or is there anything better to learn about
twisted.

I though about buying a paper book in order to be able to read in in
the train.

If there is however a reall nice online document, then I wouldn't
object of not buying a book at all.


Thanks in advance for any suggestions
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Good literature about python twisted

2011-03-15 Thread gelonida
On Mar 15, 2:18 pm, Daniel Mahoney  wrote:
> On Tue, 15 Mar 2011 04:34:52 -0700, gelonida wrote:
> > Hi,
>
> > Just wanted to learn more about python twisted and wanted to buy the
> > O'Reilly book.
>
> > However I noticed, that the book is from 2005.
>
> > Is this book still worth it or is there anything better to learn about
> > twisted.
>
> > I though about buying a paper book in order to be able to read in in the
> > train.
>
> > If there is however a reall nice online document, then I wouldn't object
> > of not buying a book at all.
>
> > Thanks in advance for any suggestions
>
> I bought and read that book a couple of years ago, and found that it
> didn't help me much. I came away with a very shaky understanding of
> Twisted's principles. I still am very shaky - I'd love to find some
> Twisted docs that will help the light bulb to go on, as Twisted seems
> like a very handy tool.



Thanks a lot for your answer.

o it seems another book or some other documentation would be great.

Does anyone have recommendations?

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


first attempt with pybluez on XP fail

2010-11-16 Thread gelonida
Hi,

Wanted to write a first simple example with pybluez and offer
a serial connection service with a given name.

What I tried (being inspired by 
http://people.csail.mit.edu/albert/bluez-intro/x290.html
) is:

server_sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
port = bluetooth.PORT_ANY # original example used get_available_port()
  # buy this seems obsolete
server_sock.bind(("",port))
server_sock.listen(1)
print "listening on port %d" % port

loc_host, loc_port = server_sock.getsockname()
print "HOST", loc_host, "PORT??", loc_port

uuid = "1e0ca4ea-299d-4335-93eb-27fcfe7fa848"
bluetooth.advertise_service( server_sock, "FooBar Service", uuid )

The error message, that I get is:
listening on port 0
HOST XX:XX:XX:XX:XX:XX PORT?? 1
Traceback (most recent call last):
  File "XXX\bt_01.py", line 94, in 
cmd(args)
  File "XXX\bt_01.py", line 71, in srvr
srvr = BTSerService()
  File "XXX\bt_01.py", line 51, in __init__
bluetooth.advertise_service( server_sock, "FooBar Service", uuid )
  File "C:\Python26\lib\site-packages\bluetooth\msbt.py", line 173, in
advertise
_service
sock._sdp_handle = bt.set_service_raw (sock._raw_sdp_record, True)
IOError: An invalid argument was supplied.



What might I be doing wrong?

I got rid of the obsolete get_available_port() and wonder what else
might have changed?

Thanks a lot for your help.

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


first attempts with pybluez on Win XP fail

2010-11-16 Thread Gelonida
Hi,

My post from Google groups doesn't sem to get through. SO here once more
posted from gmane.


Wanted to write a first simple example with pybluez and offer
a serial connection service with a given name.

What I tried (being inspired by
http://people.csail.mit.edu/albert/bluez-intro/x290.html
) is:

server_sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
port = bluetooth.PORT_ANY # original example used get_available_port()
  # buy this seems obsolete
server_sock.bind(("",port))
server_sock.listen(1)
print "listening on port %d" % port

loc_host, loc_port = server_sock.getsockname()
print "HOST", loc_host, "PORT??", loc_port

uuid = "1e0ca4ea-299d-4335-93eb-27fcfe7fa848"
bluetooth.advertise_service( server_sock, "FooBar Service", uuid )

The error message, that I get is:
listening on port 0
HOST XX:XX:XX:XX:XX:XX PORT?? 1
Traceback (most recent call last):
  File "XXX\bt_01.py", line 94, in 
cmd(args)
  File "XXX\bt_01.py", line 71, in srvr
srvr = BTSerService()
  File "XXX\bt_01.py", line 51, in __init__
bluetooth.advertise_service( server_sock, "FooBar Service", uuid )
  File "C:\Python26\lib\site-packages\bluetooth\msbt.py", line 173, in
advertise
_service
sock._sdp_handle = bt.set_service_raw (sock._raw_sdp_record, True)
IOError: An invalid argument was supplied.

What might I be doing wrong?

I got rid of the obsolete get_available_port() and wonder what else
might have changed?

Thanks a lot for your help.

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


first attempts with pybluez on Linux fail as well

2010-11-17 Thread Gelonida
Hi,


Wanted to write a first simple example with pybluez and offer
a serial connection service with a given name.

What I tried (being inspired by
http://people.csail.mit.edu/albert/bluez-intro/x290.html
) is:

server_sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
port = bluetooth.PORT_ANY # original example used get_available_port()
  # buy this seems obsolete
server_sock.bind(("",port))
server_sock.listen(1)
print "listening on port %d" % port

loc_host, loc_port = server_sock.getsockname()
print "HOST", loc_host, "PORT??", loc_port

uuid = "1e0ca4ea-299d-4335-93eb-27fcfe7fa848"
bluetooth.advertise_service( server_sock, "FooBar Service", uuid )


Unde Linux the file does not produce an error message, but When I use
another PC to look for services I do NOT see the service "FooBar Service"


What might I be doing wrong?
Are there any special requirements on the buetooth dongle / bluetooth
stack to make abov example work?


Thanks a lot for your help.


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


simplest way to create simple standalone wsgi server without import wsgi_lib.server

2011-01-31 Thread Gelonida
Hi,

Normally I use following code snippet to quickly test a wsgi module
without a web server.

import wsgi_lib.server
wsgi_lib.server.run(application, port=port)


However Now I'd like to test a small wsgi module on a rather old host
( Python 2.4.3 ) where I don't have means to update python.

Is there any quick and easy code snippet / module, performing the same
task as my above mentioned lines?

Thanks in advance for any hints




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


test: please ignore

2011-02-01 Thread Gelonida
Somehow I can't post anymore to gmane.

Would like to know why.

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


Re: simplest way to create simple standalone wsgi server without import wsgi_lib.server

2011-02-01 Thread Gelonida
On 02/01/2011 03:07 AM, Jean-Paul Calderone wrote:
> On Jan 31, 5:28 pm, Gelonida  wrote:
>> Hi,
>>
>> Normally I use following code snippet to quickly test a wsgi module
>> without a web server.
>>
>> import wsgi_lib.server
>> wsgi_lib.server.run(application, port=port)
>>
>> However Now I'd like to test a small wsgi module on a rather old host
>> ( Python 2.4.3 ) where I don't have means to update python.
>>
>> Is there any quick and easy code snippet / module, performing the same
>> task as my above mentioned lines?
>>
>> Thanks in advance for any hints
> 
> You didn't mention why you can't update Python, or if that means you
> can't install new libraries either.  However, if you have Twisted 8.2
> or newer, you can replace your snippet with this shell command:
> 
> twistd -n web --port  --wsgi 

Thanks Jean-Paul

The problem is rather simple. The host in question is not 100% under my
control. I can request to have packages installed if they're in the list
of available packages.

python 2.4 is part of it. twisted is not

In the worst case I could request the installation of python virtualenv,
the entire gcc tool chain and try to compile twisted,
or wsgilib, but I wondered whether there isn't a simple pure python way
of starting a wsgi server for test purposes.


> 
>  is the fully-qualified Python name of your application
> object.  So, for example if you have a module named "foo" that defines
> an "application" name, you would pass "foo.application".
> 
> Jean-Paul


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


Re: test: please ignore

2011-02-01 Thread Gelonida
On 02/01/2011 10:44 PM, Gelonida wrote:
> Somehow I can't post anymore to gmane.
> 
> Would like to know why.
> 
Now this message arrived.
So it seems to work again, though with quite some heavy delay.

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


Re: simplest way to create simple standalone wsgi server without import wsgi_lib.server

2011-02-01 Thread Gelonida
On 02/01/2011 11:36 PM, Jean-Paul Calderone wrote:
>>
>>> twistd -n web --port  --wsgi 
>>
>>
>> The problem is rather simple. The host in question is not 100% under my
>> control. I can request to have packages installed if they're in the list
>> of available packages.
>>
>> python 2.4 is part of it. twisted is not
>>
> 
> You may be able to install Twisted (or even wsgilib) in your home
> directory.  For example, the command:
> 
> python setup.py --prefix ~/.local
> 
> will install Twisted (or maybe wsgilib) in ~/.local/lib/python2.4/site-
> packages/.  Add that to your PYTHONPATH (eg in your .bashrc) and
> you're basically all set.  Also, though Twisted has some extension
> modules, they're optional.  So you should be fine without a compiler,
> *except* that distutils doesn't cope so well with certain cases.  If
> you find "setup.py install" fails for some reason, you can also just
> add the unpacked source directory to PYTHONPATH and run it in-place
> without installation.
> 

Thanks a lot you gave me some new ideas.

I made first attempts with virtualenv
and easy_install

no module with C-code can be installed (some issue with tool chain)

- wsgilib installation failed therefore
- twisted installation failed therefore

I untarred twisted and tried to run twistd.

it complains about missing zope.interface
installing of zope.interface fails also with gcc error.

It seems I am currently stuck until I find a simplistic python only
solution for quick standalone wsgi_module tests.





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


PyQT: QWebView with custom QNetworkAccessManager

2011-02-01 Thread Gelonida
Hi,

I would like to subclass QNetworkAccessManager and
create a subclass of QWebView, that will use the subclassed
QNetworkAccessManager for all accesses.

Is this possible?
I have really no idea when and how I could achieve this.

Thanks in advance for any suggestions / pointers

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


Re: PyQT: QWebView with custom QNetworkAccessManager

2011-02-01 Thread Gelonida
On 02/02/2011 12:31 AM, Gelonida wrote:
> Hi,
> 
> I would like to subclass QNetworkAccessManager and
> create a subclass of QWebView, that will use the subclassed
> QNetworkAccessManager for all accesses.
> 
> Is this possible?
> I have really no idea when and how I could achieve this.
> 
> Thanks in advance for any suggestions / pointers
> 


Well I answer my own question.

In fact my first experiments failed horribly due to a tiny PyQt detail.

I expected that, the variable new_manager does not have to be persistent.

I naively assumed, that a call to setNetworkAccessManager() would keep a
reference to new_manager and thus avoid its destruction this does not
seem to be the case.

Below an example of how to create a QQWebview with a custom
NetworkAccessManager

import sys
import PyQt4.QtGui as QtGui
import PyQt4.QtCore as QtCore
import PyQt4.QtWebKit as QtWebKit
from PyQt4.QtNetwork import QNetworkAccessManager

class MyNetworkAccessManager(QNetworkAccessManager):
def __init__(self, old_manager):
QNetworkAccessManager.__init__(self)
self.setCache(old_manager.cache())
self.setCookieJar(old_manager.cookieJar())
self.setProxy(old_manager.proxy())
self.setProxyFactory(old_manager.proxyFactory())

def createRequest(self, operation, request, data):
print "mymanager handles ", request.url()
return QNetworkAccessManager.createRequest(
self, operation, request, data)


def set_new_manager(web):
global new_manager # if this line is commented I will se
old_manager = web.page().networkAccessManager()
new_manager = MyNetworkAccessManager(old_manager)
web.page().setNetworkAccessManager(new_manager)

app = QtGui.QApplication(sys.argv)
web = QtWebKit.QWebView()
set_new_manager()
web.setUrl( QtCore.QUrl("http://www.google.com";) )
web.show()

sys.exit(app.exec_())





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


How to debug a problem with python crashing under windows

2011-02-04 Thread gelonida
Hi,

I have a python application, which occasionally crashes.

With crashing I mean, that windows pops up a screen saying, that
python.exe failed.
I do not have any usable trace on stdout / stderr.

What are the best means to analyze such errors?

Is there any way to get something like a core dump and to look at it
after the application died?

Thanks in advance for any idea.
-- 
http://mail.python.org/mailman/listinfo/python-list


QWebView: notify python when I clicked on a certain web eleemnt

2011-02-19 Thread Gelonida
I have a web page (existing page, can't modify it) and I would like
to browse it in a QtWebview. (This is already working)

Now I Wonder how I could achieve following behaviour:

When I click on a certain element e.g. ""
I would like to notify my python script.

What is important:
I don't want to change anything else in the web pages behaviour (This
means if clicking on this element will call some java script functions,
load a pag, then this should still happen.


What is the correct way to do it?


Thanks in advance for any suggestions

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


How to log certain web requests.

2011-02-19 Thread Gelonida
Hi,


I created a small browser with QWebview

I subclassed QNetworkAccessManager with a customized version and set it
as NetworAccessManager


By adding a print / log statement in the createRequestMethod I am able
to log, which requests are performed.

What I would be interested in is however to to write the of some post
requests and the data returned from the server into a log file.

How can I do this?

thanks in advance for any ideas?

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


QWebView: Get coordinates of an element and simulate a relative to this position.

2011-02-19 Thread Gelonida
WHht I wondered is following:

Let's assume I use a QWebView,

As soon as the page is loaded ( loadFinished signal)
I'd like to identify a certain element  with findFirstElement(), get
it's coordinates (and size) calculate some related coordinates (for
example 20 pixel above the top left corner of this element
and clcik there.


SO my questions:
- how can I get the coordinate of an element, that I found with
findFirstElement()
- how can I click in the  browser window relative to the coordinate
previously obtained



Thanks in advance for any suggestions ideas.

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


Re: QWebView: notify python when I clicked on a certain web eleemnt

2011-02-23 Thread Gelonida
Hi Damjan,

Thanks for your answer

On 02/21/2011 05:09 PM, Дамјан Георгиевски wrote:
>> I have a web page (existing page, can't modify it) and I would like
>> to browse it in a QtWebview. (This is already working

>> When I click on a certain element e.g. ""
>> I would like to notify my python script.
>>
>> What is important:
>> I don't want to change anything else in the web pages behaviour (This
>> means if clicking on this element will call some java script
>> functions, load a pag, then this should still happen.
> 
> 
> You can inject JavaScript using the method 
> QWebElement::evaluateJavaScript()
> 
> Also you can insert a Python object in the JS runtime with 
> QWebFrame::addToJavaScriptWindowObject()
> see here:
> http://pysnippet.blogspot.com/2010/01/calling-python-from-javascript-in-
> pyqts.html
> 

> 
> so make a Python object with some methods you'd wish to call, then 
> evaluate some small JS that will bind the click event on your element to 
> the method of the Python object.
> 

OK, but how do I make sure, that I don't override an existing binding to
the element's click() event?



I  will start playing with it.




>

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


Re: QWebView: notify python when I clicked on a certain web eleemnt

2011-02-23 Thread Gelonida
Damjan,


Thanks once more for your help.
You pointed me in the right direction.

On 02/24/2011 12:25 AM, Ian Kelly wrote:
> On Wed, Feb 23, 2011 at 4:02 PM, Gelonida  wrote:
>>> so make a Python object with some methods you'd wish to call, then
>>> evaluate some small JS that will bind the click event on your element to
>>> the method of the Python object.
>>>
>>
>> OK, but how do I make sure, that I don't override an existing binding to
>> the element's click() event?
> 
> If the element has an existing binding, then create a new JS function
> that calls both the Python method and the original event handler, and
> bind that function to the event.

Not sure if it can be done easier, but what I roughly do now is:

top_frame = page.mainFrame()
my_qt_object = MyQtObject()
top_frame.addToJavaScriptWindowObject("pyObj", my_qt_object)
field = top_frame.findFirstElement(path)

js_inject_after = """{
var that = this;
var prev_action = this.%(evt)s;
if (prev_action == null){
prev_action = function(){};
}
this.%(evt)s = function(){
prev_action();
%(action)s;
};
}"""

prms = dict(
evt="onclick",
action=""" pyObj.action(that.id+ "clicked"); """
)

field.evaluateJavaScript(js_inject_after % prms)





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


Re: QWebView: notify python when I clicked on a certain web eleemnt

2011-02-23 Thread Gelonida
Thanks Ian,

Pls see my other reply.

Is that what you meant?

On 02/24/2011 12:25 AM, Ian Kelly wrote:
> On Wed, Feb 23, 2011 at 4:02 PM, Gelonida  wrote:
>>> so make a Python object with some methods you'd wish to call, then
>>> evaluate some small JS that will bind the click event on your element to
>>> the method of the Python object.
>>>
>>
>> OK, but how do I make sure, that I don't override an existing binding to
>> the element's click() event?
> 
> If the element has an existing binding, then create a new JS function
> that calls both the Python method and the original event handler, and
> bind that function to the event.


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


when should I explicitely close a file?

2010-04-13 Thread gelonida
Hi,


I've been told, that following code snippet is not good.


open("myfile","w").write(astring) , because I'm neither explicitely
closing nor using the new 'with' syntax.

What exactly is the impact of not closing the file explicitely
(implicitley with a 'with' block)?


Even with my example
I'd expected to get an exception raised if not all data could have
been written.

I'd also expected, that all write data is flushed as soon as the
filehandle is out of scope (meaning in the next line of my source
code).


Thanks for explaining me exactly what kind of evil I could encounter
with not explicitely closing.

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


python wia and RegisterEvent

2010-04-15 Thread gelonida
Hi,

I'd like to register an event in order to be informed, whenever a
Windows WIA device is connected or disconnected.

In python I can use WIA devices, but I don't know how to register
events

I have existing C# code, which works and looks like.

   class MgrHandlerClass
{
public void devManager_OnEvent(string eventID, string
deviceID, string itemID)
{} // her emy handler code

public void addhandler(DeviceManager manager)
{
Console.WriteLine("adding handler!");
manager.OnEvent += new
WIA._IDeviceManagerEvents_OnEventEventHandler(
devManager_OnEvent);
}

static void Main(string[] args)
{

MgrHandlerClass mgrhndlr;
mgrhndlr = new MgrClass();
DeviceManager manager;

 manager = new DeviceManagerClass();
 
manager.RegisterEvent(WIA.EventID.wiaEventDeviceConnected, "*");
 
manager.RegisterEvent(WIA.EventID.wiaEventDeviceDisconnected, "*");
 mgrhndlr.addhandler(manager);
// wait for callbacks or do other stuff
}


Now in python I'm stuck

import win32com.client
import wia_defs # created with makepy.py
manager = win32com.client.Dispatch("WIA.DeviceManager")
mgrhndlr = MgrClass()
manager.RegisterEvent(EventID=constants.wiaEventDeviceConnected,DeviceID=u'*')
manager.RegisterEvent(EventID=constants.wiaEventDeviceDisconnected,DeviceID=u'*')
mgrhndlr.addhandler(manager)


class MgrHandlerClass:
def OnEvent(self, EventID=defaultNamedNotOptArg,
DeviceID=defaultNamedNotOptArg, ItemID=defaultNamedNotOptArg):
print "Called back with (%s) (%s) (%s)" %
(EventID,DeviceID,ItemID)

def addhandler(self,manager):
# here I'm stuck :-(
# the following line doesn't work as it seems, that manager
does not have attr
# onevent
 
manager.OnEvent.append( 
WIA._IDeviceManagerEvents_OnEventEventHandler(self.OnEvent) )



The autogenerated file contains:
class IDeviceManager(DispatchBaseClass):
CLSID = IID('{73856D9A-2720-487A-A584-21D5774E9D0F}')
coclass_clsid = IID('{E1C5D730-7E97-4D8A-9E42-BBAE87C2059F}')

def RegisterEvent(self, EventID=defaultNamedNotOptArg,
DeviceID=u'*'):
"""Registers the specified EventID for the specified DeviceID. 
If
DeviceID is "*" then OnEvent will be called whenever the event
specified occurs for any device. Otherwise, OnEvent will only be
called if the event specified occurs on the device specified."""
return self._ApplyTypes_(2, 1, (24, 32), ((8, 1), (8, 49)),
u'RegisterEvent', None,EventID
, DeviceID)



but I do not know where to place (how to create the function)
OnEvent()


Any help would be appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python wia and RegisterEvent

2010-04-16 Thread gelonida
Hi Mark,

On Apr 16, 3:16 am, Mark Hammond  wrote:
> On 16/04/2010 7:15 AM,gelonidawrote:
>
> The model used by pywin32 is more "low level" than that exposed by some
> of the MS languages.  You probably need something closer to:
>
>   class MgrHandlerClass:
>        def OnEvent(self, EventID=defaultNamedNotOptArg, ...):
>            print "Called back with ..."
>
> manager = win32com.client.DispatchWithEvents("WIA.DeviceManager",
> MgrHandlerClass)
> manager.RegisterEvent(EventID=constants.wiaEventDeviceConnected,DeviceID=u'*')
> manager.RegisterEvent(EventID=constants.wiaEventDeviceDisconnected,DeviceID=u'*')
>
> And magically your OnEvent should be called when the event happens.
> Googling for 'DispatchWithEvents' might find some good hits for more
> information.
>

I'm still stuck. Please look at following code snippet.
I tried to reduce it to the absolute minimum.
running under WinXP and python 2.6.4


import win32com.client,pythoncom,time

defaultNamedNotOptArg=pythoncom.Empty
wiaEventDeviceConnected   =u'{A28BBADE-64B6-11D2-
A231-00C04FA31809}' # from enum EventID

class MgrHandlerClass: # doesn't work either
def OnEvent(self, EventID=defaultNamedNotOptArg,
DeviceID=defaultNamedNotOptArg, ItemID=defaultNamedNotOptArg):
print "Called back with ..."

manager = win32com.client.DispatchWithEvents("WIA.DeviceManager",
MgrHandlerClass)
manager.RegisterEvent(EventID=wiaEventDeviceConnected,DeviceID=u'*')

while True:
print "sleep"
time.sleep(10)

When I plug / unplug a USB WIA device nothing shows up.
My C# implementation prints messages on wiaEventDeviceConnected /
wiaEventDeviceDisconnected events if I register them.

What am I missing?

Should MgrHandlerClass inherit from some kind of default class?


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


find out whther byte two .pyc files contain the same byte code.

2010-05-05 Thread gelonida
Hi,

I'd like to know whether the byte code of two .pyc files is identical.

I thought, I could just compare the md5sums of thw .pyc files.
However this does not work.

It seems, that .pyc ontains the time stamp of the source file.
the .pyc file changes its contents when I don't change the file's
contents but just
save it again.

Is there any way to compare two .pyc files or to just strip the
timestiam or set it to a fixed value?


Example:
# I create a python file
$ echo 'print 1' > tst.py
# I compile it and display the md5sum of the .pyc file
$ rm -f tst.pyc ; python -c 'import tst' ; md5sum tst.pyc
1
0d67af4c2c233dbbe89bd2dab6b12088 *tst.pyc

# now I recompile and will get the same md5sum
$ rm -f tst.pyc ; python -c 'import tst' ; md5sum tst.pyc
1
0d67af4c2c233dbbe89bd2dab6b12088 *tst.pyc

 now I change the time stamp of the python source
touch tst.py

 now the md5sum will be different
$ rm -f tst.pyc ; python -c 'import tst' ; md5sum tst.pyc
1
f6faf2048b6f967c73e68951558f954c *tst.pyc



thanks for any suggestions / ideas

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


simples setup for an wsgi https server in python

2010-07-10 Thread Gelonida
Hi,

I'd like to debug a small wsgi module.

I run it either on an apache web server

or locally via wsgiref.simple_server.make_server
and following code snippet:

from wsgiref.simple_server import make_server
httpd = make_server('localhost',8012,application)
while True:
   httpd.handle_request()
   print_some_debug_info()



It seems, that wsgiref.simple_server.make_server can only create an http
server.

What I wondered would be how to easiest create an https server, that
supports wsgi modules


TIA




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


how to determine whether pathname1 is below bathname2

2010-07-11 Thread Gelonida
Hi,

I wanted to figure out whether a given path name is below another path name.

Surprisingly this turned out to be more difficult than initially
anticipated:

Let's assume I want to find out, whether path1 is below path2


First I thought about checking whether
path1 starts with path2

For this I had to
- convert path1 / path2 to absolute paths
- I had to normalize the path name

Further this would still fail for
path1='/tmp/dir11' and path2='/tmp/dir1'


next option would be to split both absolute and normalized
paths by os.sep and check whether the path2's split list
starts with path1's split list.

That should work but is also not really nice.


finally I came up with:

#
import os
def is_below_dir(fname,topdir):
relpath = os.path.relpath(fname,topdir)
return not relpath.startswith('..'+os.sep)

print is_below_dir(path1,path2)
#
The basic idea is, if the path name of path1
relative to path2 does NOT start with '..', then
it must be below path2


Does anybody see pitfalls with that solution?
Is there by any chance a function, that I overlooked,
which does already what I'd like to do?



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


Re: how to determine whether pathname1 is below bathname2

2010-07-11 Thread Gelonida
Hi Thomas,

Thomas Jollans wrote:
> On 07/11/2010 03:37 PM, Gelonida wrote:
>> #
>> import os
>> def is_below_dir(fname,topdir):
>> relpath = os.path.relpath(fname,topdir)
>> return not relpath.startswith('..'+os.sep)
>>
>> print is_below_dir(path1,path2)
>> #
>> The basic idea is, if the path name of path1
>> relative to path2 does NOT start with '..', then
>> it must be below path2
>>
>>
>> Does anybody see pitfalls with that solution?
>> Is there by any chance a function, that I overlooked,
>> which does already what I'd like to do?
> 
> It probably won't work on Windows because it isolates volumes (drive
> letters). What does, for example, os.path.relpath do when
> you pass r'c:\foo\bar', r'y:\drive\letters\are\silly' ? I see two
> reasonably correct options:
Thanks, Indeed. different drives raise an ecception.
I could catch the ValueError and let it just return False

> 
> either raise an exception (there is no relative path) or return the
> absolute path, which doesn't start with ..
> 
> On UNIX, the only potential problem I see is that it may or may not do
> what you expect when symlinks are involved somewhere.

Also true. In my case I'd prefer it would not follow, but
it doesn't really matter.


So my function in order to be portable
had now to look like:
#
import os
def is_below_dir(fname,topdir):
try:
   relpath = os.path.relpath(fname,topdir)
except ValueError:
return False
return not relpath.startswith('..'+os.sep)

print is_below_dir(path1,path2)
#

if I wanted to folow symlinks, then had to apply
os.path.realpath() on
fname AND on topdir


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


Re: multitask http server (single-process multi-connection HTTP server)

2010-07-12 Thread Gelonida
Hi lkcl,

Do you have any documentation or overview for your project?


Questions  I would be interested in:
- List of features already working
- list of features under development
- list of features being in in the near future




lkcl wrote:
> for several reasons, i'm doing a cooperative multi-tasking HTTP
> server:
>   git clone git://pyjs.org/git/multitaskhttpd.git
> 
> there probably exist perfectly good web frameworks that are capable of
> doing this sort of thing: i feel certain that twisted is one of them.
> however, the original author of rtmplite decided to rip twisted out
> and to use multitask.py and i'm one of those strange people that also
> likes the idea of using 900 lines of awesome elegant code rather than
> tens of thousands of constantly-moving-target.
> 
> one of the things that's slightly unfortunate is that i'm going to
> have to copy SimpleHTTPServer.py and slightly modify it;
> CGIHTTPServer.py as well.  this is Generally Bad Practice.
> 
> can anyone think of a way of monkey-patching or otherwise using
> SimpleHTTPRequestHandler and CGIHTTPRequestHandler and overriding the
> base class from which those two are derived?
> 
> i have had to pull bits out of BaseHTTPRequestHandler to make them use
> the "yield" logic of multitask.py already, which was painful enough.
> 
> ideas, anyone?
> 
> l.

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


pyqt Error with qtdesigner button groups

2010-07-24 Thread Gelonida
Hi,

I have have a layout with qt designer, which contains radio buttons.

Now I want to add three buttons into a button group.

doing this manually works fine

with manually I mean adding a few lines in my widget class.
example:
   bg = self.buttongroup = Qg.QButtonGroup()
   bg.addButton(self.radioButton, 1)
   bg.addButton(self.radioButton_2, 2)
   bg.addButton(self.radioButton_3, 3)

When I try to create a button group from qt designer, then python code
is created which fails when running:

How I create a button group with qtdesigner.

- I select my three radio buttons
- I right click in the object inspector and select
"Assign to Button Group" -> "New Button Group"

I create my python file with
pyuic4 -o mywidget.py -x mywidget.ui

When I try to use my widget I receive follwoing error:

Traceback (most recent call last):
. . .
line 37
self.QtGui.QApplication.translate("FormGridState", "buttonGroup",
None, QtGui.QApplication.UnicodeUTF8) = QtGui.QButtonGroup(FormGridState)
SyntaxError: can't assign to function call

The generated code lines for the buttongroup look like:
self.QtGui.QApplication.translate("Form1", "buttonGroup", None,
QtGui.QApplication.UnicodeUTF8) = QtGui.QButtonGroup(Form1)
self.QtGui.QApplication.translate("Form1", "buttonGroup", None,
QtGui.QApplication.UnicodeUTF8).setObjectName("QtGui.QApplication.translate(\"Form1\",
\"buttonGroup\", None, QtGui.QApplication.UnicodeUTF8)")
self.QtGui.QApplication.translate("Form1", "buttonGroup", None,
QtGui.QApplication.UnicodeUTF8).addButton(self.radioButton)


Am I doing something wrong or is this a bug?

I'm running ubuntu 10.4 , and python 2.6



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


Re: Multiple versions of Python coexisting in the same OS

2010-07-25 Thread Gelonida
Hi Edward,

On 07/25/2010 04:40 AM, Edward Diener wrote:

> I found the solutions too exotic for actual use, and completely
> ineffectual for the cases I originally cited. The people in that thread
> seem to have completely forgotten that Python can be invoked externally
> and internally both through executing 'python(w) xxx' and through
> executing a file with the file extension(s) associated with Python. They
> seem to have forgotten this can be within scripts or any other program
> using Python, both written by themselves and by others, and not just by
> their typing 'python(w) xxx' somewhere. Their solutions seem to believe
> that only they will externally be i9nvoking Python and only for their
> own written scripts, as opposed to the many libraries using Python as
> well as the Python distribution itself.
> 
> The best solution is some program which changes the PATH and the Python
> file type associations depending on which version of Python one wants to
> use on one's own system when more than one Python version must coexist
> with others. I will probably write such a program for myself.
> 
Hi Edward,

changing the path and is perfect for people who use consoles.
(under linux there's virtuelenv for his and it's great)

changing the file association is perfect for people who'd know at which
time they want to use which version of python.

The usecase, that I'm nore aware of however is somethig like having some
scripts / directories, that should use one version of python
and others that shoud use another.
In unix you do this normally with the 'shebang line'
( e.g.  #!/usr/bin/env/python2.6 )

There the windows solution could be something like a small 'pystarter'
program, which would decide depending on the file's location / the
file's first line which python should be started.




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


Re: Multiple versions of Python coexisting in the same OS

2010-07-25 Thread Gelonida
On 07/25/2010 02:46 PM, Edward Diener wrote:
> On 7/25/2010 6:07 AM, Gelonida wrote:
>> Hi Edward,
>>
>> There the windows solution could be something like a small 'pystarter'
>> program, which would decide depending on the file's location / the
>> file's first line which python should be started.
> 
> This does not work when Python is invoked internally via a file
> association. That was the point of my saying that the simple solutions
> do not work.

What do you mean with invoking python internally?

call another python script? from a python script.

You could start it again via a pystarter.
or just with python (assuming the starter adapts the path)


The problem, that I currently encounter are some scripts, which want to
use python UNO (open office delivers ther own version of python)
and others which want to use libraries of my 'normal' python.

having the file association point to a python starter and let the python
starter choose could be an option.

However I never tried so far.

the fast and easy option is to just have specific file suffixes for the
open office python scripts (like e.g ) .oopy

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


Re: Multiple versions of Python coexisting in the same OS

2010-07-26 Thread Gelonida

>>
>> Thus my idea of having a pystarter with a config file
>> mentioning which directories (tools) should use which python executable
> 
> Well, good luck ! I don;t know how this is resolved for you when some
> scripts executes 'python xxx yyy' or 'someScript.py yyy'.

both could be resolved with a python starter if one wanted.

call the python starter python.exe and put it first in the path.
set the python file associations to the python starter.


By the way:

Something similiar (not identical) has been used for linux hosts in big
companies in order to easily switch between different projects.  (which
potentilly had different versions of development tools)

instead of having multiple .cshrc / .bashrc files

the first entry of path has been set to
/_WRAPPER_/bin (or something similiar)
in this directory one found a wrapper script for each tool to be
wrapped. ( one script, many symlinks for each tool)

the wrapper script took a global setup, the project name and a private
setup to finally call the the desired script.

What is missing is to choose the executable depending on the script to
be called.

If one has a wrapper this could be added.

Just a question of style, whether the decision which script to be called
should come from the
- user
- a config file ( No script to be intrusively changed, what Edward seems
to prefer )
- some coding in the script or the tool's directory ( which MRAB seems
to prefer )






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


Re: Multiple versions of Python coexisting in the same OS

2010-07-26 Thread Gelonida
On 07/25/2010 10:39 PM, MRAB wrote:
> News123 wrote:

>> Thus my idea of having a pystarter with a config file
>> mentioning which directories (tools) should use which python executable
>>
> I think that's the wrong way round. A pystarter should ask the _tool_
> which version of Python it needs.


Hm, it's dfifficult to think about a solution satisfying everyone.

Edward seems to insist on a non intrusive solution, where no script is
changed (thus my idea of a config file)


I personally would probably add information to all of my self written
scripts
and create a config file for all other tools (or add a marker file n the
path of these tools)


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


Re: Multiple versions of Python coexisting in the same OS

2010-07-26 Thread Gelonida
On 07/26/2010 06:36 AM, Edward Diener wrote:
> 
> I start a Python script for version X by going to X's root directory and
> invoking 'python someScript.py' from the command line. Does that not
> sound reasonable ?

Do you have an example of two (not self written) applications requiring
to change the python file association in order to be working?

I never had problems with this, so would be curious about the tools to
avoid.



Apart from that my suggestion for you would be:


Don't write a tool.
Just create one .bat file  for each sript to be started.

The bat file should set the python search path.
This should cover 90% of existing python scripts.
(If you want, you could write a tool to create the bat files)


Now the second problem.

if a python script starts another python file without calling python.exe
but via the file associations, then above solution would not be sufficient/
you had to additionally change the file associations,
(which can easily be done from a bat file as well if you insist. The
commands you need are 'assoc' and 'ftype')

But does this really happen to you?



Please note:
Trying to develop a solution, which believes that you will never have
two concurrent applications requiring two differnt python versions
sounds a little dangerous.

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


how to build same executabl with and without console output

2010-07-30 Thread Gelonida
Hi,


What I'd like to achieve ideally is to create a py2exe program,
which
will only display a window (so 'compiled' as 'windows'-application) if
called normally.

however if being called with the option --debug it should display the
graphical window plus a debug console where I can print to.



Is there any trick in adding a console window to an application,
that was built as 'windows' application?




If above is not possible:

Is there any way to compile the same python script (myprog.py) from one
py2exe script into once a 'windows' executable (myprog.exe) and once
into a 'console' executable (myprog_debug.exe)?




TIA




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


Re: [Py2exe-users] how to build same executabl with and without console output

2010-07-30 Thread Gelonida
Hi,

On 07/30/2010 03:51 PM, Dave Angel wrote:
> pyt...@bdurham.com wrote:
>>> Is there any trick in adding a console window to an application, that
>>> was built as 'windows' application?
,,,
>>> Since we're talking MS Windows here, see:
> 
> http://msdn.microsoft.com/en-us/library/ms682528(VS.85).aspx
> 
> You can access the AllocConsole and related functions with the win32
> module:
>   win32console
> 
> This module is part of the win32 extensions, and also part of
> ActivePython distribution.
> 
Thanks a lot for  your answer
I'll check this out.



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


Re: [Py2exe-users] how to build same executabl with and without console output

2010-07-30 Thread Gelonida
On 07/30/2010 11:00 AM, Jimmy Retzlaff wrote:
> On Fri, Jul 30, 2010 at 1:10 AM, Gelonida  wrote:
>> What I'd like to achieve ideally is to create a py2exe program,
>> which
>> will only display a window (so 'compiled' as 'windows'-application) if
>> called normally.
>>
...
>>
>> Is there any way to compile the same python script (myprog.py) from one
>> py2exe script into once a 'windows' executable (myprog.exe) and once
>> into a 'console' executable (myprog_debug.exe)?
> 
> I can't think of an easy way to achieve the first approach - I've
> always taken the second approach. The advanced example included with
> py2exe has an example of how to do this. Look at all the occurrences
> of test_wx in the following link to see all the pieces involved:
> 
> http://py2exe.svn.sourceforge.net/viewvc/py2exe/trunk/py2exe/py2exe/samples/advanced/setup.py?view=markup
> 
> This uses an alternate form of the "windows" and "console" arguments
> where each target is an object with specially named member variables
> rather than a string that names the .py file (this string is one of
> the member variables). This is necessary so you can give different
> names to the console version and the windows version.
> 

Thanks, I'll read thorugh it.


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


cscope like source code navigation for python code

2010-08-07 Thread Gelonida
Hi,

I'm using g?vim and its c-scope plugin for browsing C-code.

What would be a good way of navigating larger python projects with vim?


thanks for any suggestions



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


Re: cscope like source code navigation for python code

2010-08-08 Thread Gelonida
On 08/08/2010 01:42 AM, Tim Harig wrote:
> On 2010-08-07, Gelonida  wrote:
>> I'm using g?vim and its c-scope plugin for browsing C-code.
>> What would be a good way of navigating larger python projects with vim?
> 
> ctags:
>   http://ctags.sourceforge.net/

Thanks Tim.

This looks quite interesting.

I prefereed vim/cscope for navigation, but  guess after some learning
with vim/ctags I should get along quite well.


My biggest problem with is, that ctrl-] doesn't ask you to which tag to
jump in case multiple options exist.





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


Re: cscope like source code navigation for python code

2010-08-08 Thread Gelonida
Hi Thomas,

On 08/08/2010 01:27 PM, Thomas Jollans wrote:
> On 08/07/2010 07:53 PM, Gelonida wrote:
>> Hi,
>>
>> I'm using g?vim and its c-scope plugin for browsing C-code.
>>
>> What would be a good way of navigating larger python projects with vim?
>>
>>
>> thanks for any suggestions
>>
> 
> 
> http://pypi.python.org/pypi/pycscope/0.2
> 
> Looks like an option

Yes it looks like an option.
Unfortunately it is from 2006 and reported (and aborted) on a syntax
error of one of my files.

My file is running and passes pylint / pychecker.

So I'm afraid, that the code might be outdated.
I'll investigte perhaps a little more.





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


segfault with small pyqt script

2010-08-11 Thread Gelonida
Hi Guys,
I'm desperate. I'm having a real application, which fails rather often
when finishing it. I'm not sure, whether any serious problem could be
hidden behind it

The script is a pyqt script, which segfaults most of the time on my
ubuntu 10.4 linux 64 bit and I'm having trouble to understand why.

Trying to create the smallest possible test case I ended up with
following script, which I named dodo.py and which i made executable with
chmod +x ./dodo.py

#!/usr/bin/env python
from PyQt4.QtGui import
QDialog,QGridLayout,QLabel,QComboBox,QPushButton,QApplication
a = "one"
b = "unused"
c = "also unused"
d= "ans also unused"
e = "another var"
f = "something"
class MyForm(QDialog):
def __init__(self,parent=None,config=None,ini_info=None):
super(MyForm,self).__init__(parent=parent)
grid = QGridLayout()
quit_btn = QPushButton("Quit")
quit_btn.clicked.connect(self.quit)
grid.addWidget(quit_btn,0,0)
name = "a_name"
vals_box = QComboBox()
vals_box.addItem("one")
vals_box.addItem("two")
grid.addWidget(vals_box,0,1)
self.setLayout(grid)
def quit(self):
self.close()
if __name__ == "__main__":
app = QApplication([])
myform = MyForm()
myform.show()
retcode = app.exec_()
print "last"



In order to perform the test several times I typed on the command line:

a="" ; while [ "$a" = "" ] ; do ./dodo.py ; read -t 1 a ; done

As soon as the window shows up
I click twice (slowly ) on 'one' and then on quit.

Sample output can be seen here:
gelon...@mypc:/my/directory$ a="" ; while [ "$a" = "" ] ; do ./dodo.py ;
read -t 1 a ; done
last
last
Segmentation fault
last
last
Segmentation fault
last
Segmentation fault
last
Segmentation fault
last
last
last
last
last
Segmentation fault
last
last
Segmentation fault
last
Segmentation fault


as you see the segfault happens rather often.

Does anybody see something suspicious with my code?
Can anybody else reproduce this?
as soon as I remove more lines the error seems to disappear.

What else could I do to debug this issue?

thanks for help or other ideas



If I run my script with strace ./dodo.py
I get following last lines for a run without error
> rt_sigaction(SIGINT, {SIG_DFL, [], SA_RESTORER, 0x7f65d6b3b8f0}, {0x4d9820, 
> [], SA_RESTORER, 0x7f65d6b3b8f0}, 8) = 0
> munmap(0x7f65c6344000, 622280)  = 0
> brk(0x2d71000)  = 0x2d71000
> poll([{fd=7, events=POLLIN|POLLOUT}], 1, -1) = 1 ([{fd=7, 
> revents=POLLIN|POLLOUT}])
> read(7, 
> "\22\0\233\6\2\0\300\5\2\0\300\5\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 
> 4096) = 384
> writev(7, 
> [{"\232\7\2\0\210\0\300\0056\0\2\0\207\0\300\5<\0\2\0\211\0\300\5\232\7\2\0s\0\300\5"...,
>  540}, {NULL, 0}, {"", 0}], 3) = 540
> poll([{fd=7, events=POLLIN}], 1, -1)= 1 ([{fd=7, revents=POLLIN}])
> read(7, 
> "\34\0\241\6r\0\300\5\234\1\0\0\377\261\220\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"...,
>  4096) = 1472
> read(7, 0x29fa704, 4096)= -1 EAGAIN (Resource temporarily 
> unavailable)
> poll([{fd=7, events=POLLIN|POLLOUT}], 1, -1) = 1 ([{fd=7, revents=POLLOUT}])
> writev(7, [{"O\7\2\0\1\0\300\5<\0\2\0\0\0\300\5+\0\1\0", 20}, {NULL, 0}, {"", 
> 0}], 3) = 20
> poll([{fd=7, events=POLLIN}], 1, -1)= 1 ([{fd=7, revents=POLLIN}])
> read(7, 
> "\1\2\333\6\0\0\0\0\5\0\300\4\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 4096) 
> = 32
> read(7, 0x29fa704, 4096)= -1 EAGAIN (Resource temporarily 
> unavailable)
> close(7)= 0
> write(19, "\1\v\3\200\1\0\0\0\0\0\0\0\t\0\0\0", 16) = 16
> close(19)   = 0
> open("/proc/stat", O_RDONLY|O_CLOEXEC)  = 7
> read(7, "cpu  59482 54 13580 7506040 4761"..., 8192) = 2439
> close(7)= 0
> writev(15, [{"GIOP\1\2\1\5\0\0\0\0", 12}], 1) = 12
> close(15)   = 0
> writev(13, [{"GIOP\1\2\1\5\0\0\0\0", 12}], 1) = 12
> close(13)   = 0
> close(12)   = 0
> close(11)   = 0
> unlink("/tmp/orbit-klausf/linc-1282-0-6094bc6991603") = 0
> close(14)   = 0
> write(6, "@", 1)= 1
> close(6)= 0
> close(5)= 0
> rt_sigaction(SIGCHLD, {SIG_DFL, [], SA_RESTORER|SA_NOCLDSTOP, 
> 0x7f65d6b3b8f0}, {0x7f65d40a3860, [], SA_RESTORER|SA_NOCLDSTOP, 
> 0x7f65d6b3b8f0}, 8) = 0
> exit_group(0)   


and following when an error occurs:
> writev(16, 
> [{"<\10\2\0;\6\340\5F\6\5\0!\6\340\5\10\0\340\5\0\0\0\0U\0\33\0\232\7\2\0"...,
>  16380}, {NULL, 0}, {"", 0}], 3) = 16380
> read(16, 0xbc49d4, 4096)= -1 EAGAIN (Resource temporarily 
> unavailable)
> poll([{fd=16, events=POLLIN|POLLOUT}], 1, -1) = 1 ([{fd=16, revents=POLLOUT}])
> writev(16, 
> [{"\232\10\t\0\3\6\340\5R\6\340\5C\6\340\5=\6\340\5\0\0\0\0\0\0\0\0\2\0\2\0"...,
>  4256}, {NULL, 0}, {"", 0}], 

Re: segfault with small pyqt script

2010-08-11 Thread Gelonida
Jusy FYI:

I made further tests and can crash the python script even if I delete
the linesassigning strings  to variables a to f

On 08/12/2010 01:07 AM, Gelonida wrote:
> Hi Guys,
> I'm desperate. I'm having a real application, which fails rather often
> when finishing it. I'm not sure, whether any serious problem could be
> hidden behind it
> 
> The script is a pyqt script, which segfaults most of the time on my
> ubuntu 10.4 linux 64 bit and I'm having trouble to understand why.
> 
> Trying to create the smallest possible test case I ended up with
> following script, which I named dodo.py and which i made executable with
> chmod +x ./dodo.py
> 
> #!/usr/bin/env python
> from PyQt4.QtGui import
> QDialog,QGridLayout,QLabel,QComboBox,QPushButton,QApplication
> a = "one"
> b = "unused"
> c = "also unused"
> d= "ans also unused"
> e = "another var"
> f = "something"
> class MyForm(QDialog):
> def __init__(self,parent=None,config=None,ini_info=None):
> super(MyForm,self).__init__(parent=parent)
> grid = QGridLayout()
> quit_btn = QPushButton("Quit")
> quit_btn.clicked.connect(self.quit)
> grid.addWidget(quit_btn,0,0)
> name = "a_name"
> vals_box = QComboBox()
> vals_box.addItem("one")
> vals_box.addItem("two")
> grid.addWidget(vals_box,0,1)
> self.setLayout(grid)
> def quit(self):
> self.close()
> if __name__ == "__main__":
> app = QApplication([])
> myform = MyForm()
> myform.show()
> retcode = app.exec_()
> print "last"
> 
> 
> 
> In order to perform the test several times I typed on the command line:
> 
> a="" ; while [ "$a" = "" ] ; do ./dodo.py ; read -t 1 a ; done
> 
> As soon as the window shows up
> I click twice (slowly ) on 'one' and then on quit.
> 
> Sample output can be seen here:
> gelon...@mypc:/my/directory$ a="" ; while [ "$a" = "" ] ; do ./dodo.py ;
> read -t 1 a ; done
> last
> last
> Segmentation fault
> last
> last
> Segmentation fault
> last
> Segmentation fault
> last
> Segmentation fault
> last
> last
> last
> last
> last
> Segmentation fault
> last
> last
> Segmentation fault
> last
> Segmentation fault
> 
> 
> as you see the segfault happens rather often.
> 
> Does anybody see something suspicious with my code?
> Can anybody else reproduce this?
> as soon as I remove more lines the error seems to disappear.
> 
> What else could I do to debug this issue?
> 
> thanks for help or other ideas
> 
> 
> 
> If I run my script with strace ./dodo.py
> I get following last lines for a run without error
>> rt_sigaction(SIGINT, {SIG_DFL, [], SA_RESTORER, 0x7f65d6b3b8f0}, {0x4d9820, 
>> [], SA_RESTORER, 0x7f65d6b3b8f0}, 8) = 0
>> munmap(0x7f65c6344000, 622280)  = 0
>> brk(0x2d71000)  = 0x2d71000
>> poll([{fd=7, events=POLLIN|POLLOUT}], 1, -1) = 1 ([{fd=7, 
>> revents=POLLIN|POLLOUT}])
>> read(7, 
>> "\22\0\233\6\2\0\300\5\2\0\300\5\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"...,
>>  4096) = 384
>> writev(7, 
>> [{"\232\7\2\0\210\0\300\0056\0\2\0\207\0\300\5<\0\2\0\211\0\300\5\232\7\2\0s\0\300\5"...,
>>  540}, {NULL, 0}, {"", 0}], 3) = 540
>> poll([{fd=7, events=POLLIN}], 1, -1)= 1 ([{fd=7, revents=POLLIN}])
>> read(7, 
>> "\34\0\241\6r\0\300\5\234\1\0\0\377\261\220\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"...,
>>  4096) = 1472
>> read(7, 0x29fa704, 4096)= -1 EAGAIN (Resource temporarily 
>> unavailable)
>> poll([{fd=7, events=POLLIN|POLLOUT}], 1, -1) = 1 ([{fd=7, revents=POLLOUT}])
>> writev(7, [{"O\7\2\0\1\0\300\5<\0\2\0\0\0\300\5+\0\1\0", 20}, {NULL, 0}, 
>> {"", 0}], 3) = 20
>> poll([{fd=7, events=POLLIN}], 1, -1)= 1 ([{fd=7, revents=POLLIN}])
>> read(7, 
>> "\1\2\333\6\0\0\0\0\5\0\300\4\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 
>> 4096) = 32
>> read(7, 0x29fa704, 4096)= -1 EAGAIN (Resource temporarily 
>> unavailable)
>> close(7)= 0
>> write(19, "\1\v\3\200\1\0\0\0\0\0\0\0\t\0\0\0", 16) = 16
>> close(19)   = 0
>> open("/proc/stat", O_RDONLY|O_CLOEXEC)  = 7
>> read(7, "cpu  59482 54 13580 7506040 4761"..., 8192) = 2439
>> close(7)= 0
>> 

Re: segfault with small pyqt script

2010-08-13 Thread Gelonida
Lee,

On 08/13/2010 12:53 AM, Lee Harr wrote:
> 
>> I'm desperate. I'm having a real application, which fails rather often
>> when finishing it. I'm not sure, whether any serious problem could be
>> hidden behind it
>>
>> The script is a pyqt script, which segfaults most of the time on my
>> ubuntu 10.4 linux 64 bit and I'm having trouble to understand why.
> 
> 
> Looks to be a known issue:
> http://www.google.com/search?q=pyqt+segfault+on+exit
> https://launchpad.net/bugs/561303
> 
> The last activity on that bug is almost 2 months ago... 
> Hopefully the fix will be distributed soon.



This seems to be the problem.


In my case I can workaround the issue by adding one line.

if __name__ == "__main__":
app = QApplication([])
myform = MyForm()
myform.show()
retcode = app.exec_()
myform = None #  THIS IS THE WORK AROUND
print "last"


Thaks a lot


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


Re: segfault with small pyqt script

2010-08-13 Thread Gelonida
On 08/13/2010 09:11 AM, Gelonida wrote:
> Lee,
> 
> On 08/13/2010 12:53 AM, Lee Harr wrote:
>>
>>> I'm desperate. I'm having a real application, which fails rather often
>>> when finishing it. I'm not sure, whether any serious problem could be
>>> hidden behind it
>>>
>>> The script is a pyqt script, which segfaults most of the time on my
>>> ubuntu 10.4 linux 64 bit and I'm having trouble to understand why.
>>
>>
>> Looks to be a known issue:
>> http://www.google.com/search?q=pyqt+segfault+on+exit
>> https://launchpad.net/bugs/561303
>>
>> The last activity on that bug is almost 2 months ago... 
>> Hopefully the fix will be distributed soon.
> 
> 
> 
> This seems to be the problem.
> 
> 
> In my case I can workaround the issue by adding one line.
> 
> if __name__ == "__main__":
> app = QApplication([])
> myform = MyForm()
> myform.show()
> retcode = app.exec_()
> myform = None # <<<< THIS IS THE WORK AROUND
> print "last"
> 
For more complex multi widget examples it doesn't seem enough to just
destroy the main widget.
probably I had to recursively assign all widgets / dialogues sub widgets
to None.

So I'll just try to stay away from this pyqt release and stick with
older or newer ones.



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


Re: segfault with small pyqt script

2010-08-13 Thread Gelonida
On 08/13/2010 09:11 AM, Gelonida wrote:
> Lee,
> 
> On 08/13/2010 12:53 AM, Lee Harr wrote:
>>
>>> I'm desperate. I'm having a real application, which fails rather often
>>> when finishing it. I'm not sure, whether any serious problem could be
>>> hidden behind it
>>>
>>> The script is a pyqt script, which segfaults most of the time on my
>>> ubuntu 10.4 linux 64 bit and I'm having trouble to understand why.
>>
>>
>> Looks to be a known issue:
>> http://www.google.com/search?q=pyqt+segfault+on+exit
>> https://launchpad.net/bugs/561303
>>
>> The last activity on that bug is almost 2 months ago... 
>> Hopefully the fix will be distributed soon.
> 
> 
> 
> This seems to be the problem.
> 
> 
> In my case I can workaround the issue by adding one line.
> 
> if __name__ == "__main__":
> app = QApplication([])
> myform = MyForm()
> myform.show()
> retcode = app.exec_()
> myform = None # <<<< THIS IS THE WORK AROUND
> print "last"
> 
For more complex multi widget examples it doesn't seem enough to just
destroy the main widget.
probably I had to recursively assign all widgets / dialogues sub widgets
to None.

So I'll just try to stay away from this pyqt release and stick with
older or newer ones.



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


Re: segfault with small pyqt script

2010-08-16 Thread Gelonida
Hi Hans-Peter,


It seems, that my other posts did not get through.

On 08/15/2010 11:17 PM, Hans-Peter Jansen wrote:
> For a starter, tell us the versions of python-sip, and python-qt4 or however 
> they're called in Ubuntu. For the record, 
> python-sip-4.10.5-1.1
> python-qt4-4.7.4-1.1
> doesn't show this behavior.
> 
> Pete

The problem seems to be known for 4.7.2.
For simple code I managed to work around the issue.
For the real more complicated I didn't. So it seems
I'll have to avoid 4.7.2.

Please see below:

On 08/13/2010 09:11 AM, Gelonida wrote:
> > Lee,
> >
> > On 08/13/2010 12:53 AM, Lee Harr wrote:
>> >>
>>> >>> I'm desperate. I'm having a real application, which fails rather
often
>>> >>> when finishing it. I'm not sure, whether any serious problem
could be
>>> >>> hidden behind it
>>> >>>
>>> >>> The script is a pyqt script, which segfaults most of the time on my
>>> >>> ubuntu 10.4 linux 64 bit and I'm having trouble to understand why.
>> >>
>> >>
>> >> Looks to be a known issue:
>> >> http://www.google.com/search?q=pyqt+segfault+on+exit
>> >> https://launchpad.net/bugs/561303
>> >>
>> >> The last activity on that bug is almost 2 months ago...
>> >> Hopefully the fix will be distributed soon.
> >
> >
> >
> > This seems to be the problem.
> >
> >
> > In my case I can workaround the issue by adding one line.
> >
> > if __name__ == "__main__":
> > app = QApplication([])
> > myform = MyForm()
> > myform.show()
> > retcode = app.exec_()
> > myform = None # <<<< THIS IS THE WORK AROUND
> > print "last"
> >
For more complex multi widget examples it doesn't seem enough to just
destroy the main widget.
probably I had to recursively assign all widgets / dialogues sub widgets
to None.

So I'll just try to stay away from this pyqt release and stick with
older or newer ones.






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


controlling the mouse pointer on linux (or as vnc client)

2010-08-29 Thread Gelonida
Hi,

>From a python script I'd like to be able to move the mouse to certain
absolute coordinates on the screen.


There's no problems calling an external program with subprocess.popen,
as I do not want to perform many movements.

The mouse can jump it doesn't have to visibly move to the target coordinate.



What would you suggest to achieve this on Linux Ubuntu 10.4?

Lateron it would be intersting to acheive the same on a Windows PC


One idea, that I had (for a cross platform solution) would be to start a
VNC server on localhost and the current display and run a small custom
VNC client, which will only control the mouse.

However I have no idea how easy it would be to use a custom VNC client
for moving the mouse.


I read about python-vnc-viewer but don't know how complex it would be to
use it as a base for 'just moving the mouse'



Thanks for any suggestions and ideas



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


Re: controlling the mouse pointer on linux (or as vnc client)

2010-08-29 Thread Gelonida
Hi John,

> Hi,
> 
>>From a python script I'd like to be able to move the mouse to certain
> absolute coordinates on the screen.
> 
> 
> There's no problems calling an external program with subprocess.popen,
> as I do not want to perform many movements.
> 
> The mouse can jump it doesn't have to visibly move to the target coordinate.
> 
> 
> 
> What would you suggest to achieve this on Linux Ubuntu 10.4?
> 
> Lateron it would be intersting to acheive the same on a Windows PC
> 

On 08/29/2010 04:25 PM, John Bokma wrote:
> sudo apt-get install xautomation
> xte 'mousemove 200 200'
> 

Thanks a lot.

This solution is perfect for Linux.
Exactly what I was looking for. :-)


I guess for Windows it would be a little more complicated?


bye


G




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


Windows: getting notification about power state changes

2010-10-19 Thread Gelonida
Hi,


I wondered how I could achieve this.

I'd like to be notified about certain events and call certain python
functions depending on the event.

call a function:
- before (or after) the screen saver kicks in
- before (or after) the monitor is switched off
- before (or after) the hard disk is switched off
- before the PC enters stand by mode

- after the PC left stand by mode
- before (or after) the PC's hard disk was powered up
- before (or after) the monitor was switched on
- before (or after) the screen saver was stopped


Thanks a lot for any pointers

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


Re: Windows: getting notification about power state changes

2010-10-20 Thread Gelonida
Hi Tim,


Thanks a lot.
I'll look into it.

On 10/19/2010 11:30 AM, Tim Golden wrote:
> On 19/10/2010 10:06, Gelonida wrote:
>> I'd like to be notified about certain events and call certain python
>> functions depending on the event.
>>
>> call a function:
>> - before (or after) the screen saver kicks in
. . .
>> - before (or after) the screen saver was stopped
> 
> This should take you a certain amount of the way:
> 
>   http://timgolden.me.uk/python/win32_how_do_i/track-session-events.html
> 
> I honestly don't know if the OS even knows when the monitor's
> switched on / when the disk is spun up.
> 
> WMI has some power events:
> 
>   http://msdn.microsoft.com/en-us/library/aa394362%28v=VS.85%29.aspx
> 
> 
> http://timgolden.me.uk/python/wmi/cookbook.html#monitor-multiple-machines-for-power-events
> 
>


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


Re: lazy evaluation of a variable

2012-06-18 Thread Gelonida N

On 06/17/2012 11:35 PM, Gelonida N wrote:

Hi,

I'm not sure whether what I ask for is impossible, but would know how
others handle such situations.



I'm having a module, which should lazily evaluate one of it's variables.
Meaning that it is evaluated only if anybody tries to use this variable.

At the moment I don't know how to do this and do therefore following:


### mymodule.py ###
var = None

def get_var():
global var
if var is not None:
return var
var = something_time_consuming()



Now the importing code would look like

import mymodule
def f():
var = mymodule.get_var()

The disadvantage is, that I had to change existing code directly
accessing the variable.


I wondered if there were any way to change mymodule.py such, that the
importing code could just access a variable and the lazy evaluation
would happen transparently.

import mymodule
def f():
var = mymodule.var


Thanks everybody for your responses. This gave me quite some ideas.

It seems, that none of the solutions would allow to have the changes 
only in the module.


More out of curiosity than out of real necessity I wanted to know, 
whether it would be possible to hide the lazy evaluation from already 
existing code, that has already the import statement written.

So the question basically boiled down to
"can one make 'properties' for modules?"

It seems no.
Probably there aren't many real use cases except for monkey patching 
libraries or for logging accesses to a module's variable



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


Re: Conditional decoration

2012-06-19 Thread Gelonida N

On 06/19/2012 02:23 AM, Rob Williscroft wrote:

Roy Smith wrote in news:jro9cj$b44$1...@panix2.panix.com in
gmane.comp.python.general:


Is there any way to conditionally apply a decorator to a function?
For example, in django, I want to be able to control, via a run-time
config flag, if a view gets decorated with @login_required().

@login_required()
def my_view(request):
 pass


You need to create a decorator that calls either the original
function or the decorated funtion, depending on your condition,
Something like (untested):

def conditional_login_required( f ):
   _login_required = login_required()(f)

   def decorated( request ):
 if condition == "use-login":
   return _login_required( request )
 else:
   return f( request )

   return decorated

@conditional_login_required
def my_view(request):
   pass

Replace (condition == "use-login") with whatever your "run-time
control flag" is.



Your suggestion will unconditionally decorate a function and depending 
on the condition call the original function or not.


However if you want to evaluate the condition only once at decoration 
time, then you had probably to do something like (not tested)

> def conditional_login_required( f ):
>_login_required = login_required()(f)
>
>def decorated( request ):
>return _login_required( request )
>if condition:
> return decorated
>else:
>return f




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


Re: Finding absolute path of imported module?

2012-06-19 Thread Gelonida N

On 06/19/2012 09:32 PM, Christian Heimes wrote:

Am 19.06.2012 19:55, schrieb Roy Smith:

So, the question is, is there any way to dump all the *absolute*
pathnames of all the imported modules?  I can iterate over
sys.modules.values(), but that doesn't give me absolute pathnames, so
I can't tell which version of the symlink existed when the module was
imported.


You can use os.path.abspath(module.__file__) to get the absolute path of
a module. This works reliable unless you use os.chdir() in your code.

abspath() may not normalize symlinks (not sure about it) but you can
check for symlink with os.path.islink() (uses os.lstat) and resolve the
link with os.readlink().

If I remember well, os.path.realpath(module.__file__) should normalize 
the paths and resolve the symlinks


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


howto do a robust simple cross platform beep

2012-07-13 Thread Gelonida N

Hi,


I just want to use a beep command that works cross platform.


I tried the simplest approach (just printing the BEL character '\a' 
chr(7) to the console.



This fails on my Ubuntu 12.04 host, as the pcspkr is in the list of the 
blacklisted kernel modules.


I found another snippet trying to push a sine wave  directly to /dev/audio

but I don't have write permissions to /dev/audio.

Other solutions seem to suggest to play a wav file, but of course first 
I had to write code creating me a wav file.


How do others handle simple beeps?


I just want to use them as alert, when certain events occur within a 
very long running non GUI application.



Thanks for any info.


What I do at the moment is:

For Windows I use winsound.Beep

For Linux I create some raw data and pipe it into sox's
'play' command.

I don't consider this very elegant.











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


Re: howto do a robust simple cross platform beep

2012-07-24 Thread Gelonida N
On 07/15/2012 03:15 AM, rantingrickjohn...@gmail.com wrote:> On Friday, 
July 13, 2012 8:00:05 PM UTC-5, gelonida wrote:

>> I just want to use a beep command that works cross platform. [...] I
>> just want to use them as alert, when certain events occur within a
>> very long running non GUI application.
>
> I can see a need for this when facing a non GUI interface.
That's exactly my usecase.
A rather tiny script running for hours and telling the users when 
results are ready.


But even "IF" you do manage to play a sound in a cross platform manner; 
if the speaker volume is too low, or the speakers are turned off, or the 
computer does not have speakers connected, etc... your user will never 
hear the alert! In this case, beeping the built-in speaker has the 
fail-safe advantage.

>

Well the user starts the script, because he wants to get immediate 
notification while being able mimimize the window, work on a different a 
machine or doing some paperwork or discussions.

So it would be up to him to configure the volume appropraitely.

> Why not wrap up the functionality and release a module yourself? If 
you are not sure how to access the speaker on one or more OSs then ask 
on the list. I would love to see some community effort behind this.

>

I'm having no some ugly code, that is working on the platforms, that I 
am using.



I'm rather busy, and have no experience in publishing coe, that's good 
enough for the community.



I could try to use this a test case for learning to create communicty 
modules.


Is there any decent getting started guide.

Could I use github (as O know git already)?

Assuming, the module would achieve a state, where it could be usable by 
others. How would one register on Pypi?


> PS: Better make sure this module does not exist though ;-)
>

I didn't find one, that's why I asked here.


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


find out whether a module exists (without importing it)

2012-08-06 Thread Gelonida N

Is this possible.

let's say I'd like to know whether I could import the module
'mypackage.mymodule', meaning,
whther this module is located somewhere in sys.path

i tried to use

imp.find_module(), but
it didn't find any module name containing a '.'

Am I doing anything wrong?

Is there another existing implementation, that helps.

I could do this manually, but this is something I'd just like to do if 
necessary.



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


Re: find out whether a module exists (without importing it)

2012-08-06 Thread Gelonida N

On 08/06/2012 11:58 PM, Miki Tebeka wrote:

imp.find_module(), but
it didn't find any module name containing a '.'

The docs (http://docs.python.org/library/imp.html#imp.find_module) clearly say:

"This function does not handle hierarchical module names(names

> containing dots).
Thanks,
Well this explains.

>  In order to find P.M, that is, submodule M of package P, use 
find_module() and load_module() to find and load package P, and then use 
find_module() with the path argument set to P.__path__. When P itself 
has a dotted name, apply this recipe recursively."


See https://gist.github.com/3278829 for possible implementation.




Using imp and then iterating (as you suggested) is probably the fastest 
solution. This is what I will do.


Thanks again.

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


Re: find out whether a module exists (without importing it)

2012-08-07 Thread Gelonida N

Hi Michael,

On 08/07/2012 08:43 AM, Michael Poeltl wrote:

in my opinion, "without importing it" makes it unnecessarily complicated.


It does, but I think this is what I want, thus my question.
I tried to keep my question simple without explaining too much.

Well now here's a little more context.


There's two reasons why I sepcified the without importing it.
Some modules may have side effects when being imported,and sometimes I 
just want to check for a module's existence



Second:
Sometimes I only want to know, whether a module exists.
I do not want to know whether a module is syntactically correct or 
whether a module if imported  is capable of

importing all it's submodules

What I'd like to achieve at the moment is to distinguish three situations:
- a module with a given name does not exist
- a module with a given name exists and produces errors (might be 
ImportErors)

- a module with a given name exists and can be imported

In fact what I really want to achieve is:
import a module if it exists (and fail if it is broken)
if it doesn't exist import a 'default' module and go on.

The name of the module is stored in a variable and is not known prior to 
running the script so the code, that you suggested would be something like.



modulename = 'my.module'
cmd = 'import %s as amodule'
try:
exec(cmd)
print "imported successfully"
except ImportError:
   print "module doesn't exist or the module tries to " \
"import another module that doesn't exist"
   # if the module doesn't exist I'd like to import a 'fallback' module
   # otherwise I'd like to abort.
except Exception as exc:
print "module exists, but is broken"
raise exc

amodule.do_something()



You just want to know it module xyz exists, or better said can be found
(sys.path).

why not try - except[ - else ]

try:
 import mymodule
except ImportError:
 #  NOW YOU KNOW it does not exist
 #+ and you may react properly
??
* Gelonida N  [2012-08-06 22:49]:

Is this possible.

let's say I'd like to know whether I could import the module
'mypackage.mymodule', meaning,
whther this module is located somewhere in sys.path

i tried to use

imp.find_module(), but
it didn't find any module name containing a '.'

Am I doing anything wrong?

Is there another existing implementation, that helps.

I could do this manually, but this is something I'd just like to do
if necessary.


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


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


Re: save dictionary to a file without brackets.

2012-08-09 Thread Gelonida N

On 08/09/2012 10:11 PM, giuseppe.amatu...@gmail.com wrote:

Hi,
I have a dict() unique
like this
{(4, 5): 1, (5, 4): 1, (4, 4): 2, (2, 3): 1, (4, 3): 2}
and i want to print to a file without the brackets comas and semicolon in order 
to obtain something like this?
4 5 1
5 4 1
4 4 2
2 3 1
4 3 2
Any ideas?
Thanks in advance
Giuseppe


Boring explicit solution:

d = {(4, 5): 1, (5, 4): 1, (4, 4): 2, (2, 3): 1, (4, 3): 2}
for key, val in d.items():
v1,v2 = key
fout.write("%d %d %d\n" % (v1, v2, val))


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


Does anyone have an activate script for portable python?

2012-08-11 Thread Gelonida N

Hi,


In Pythons installed with virtualenv there is on windows an activate.bat 
script, that can be used to setup the cmd-shell such, that the search 
path for python and pythor elated tools (pip / easy_install) is setup 
properly.


Further there is the deactivate script to set the environment back to 
it's state before calling activate.


Do such a scripts also exist for Portable python?


If anybody wrote already such scripts, then couldn't they be added to 
the official portable python release?


I never used portable python so far but can't imagine, that I'm the only 
one who'd like such a script.




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


suggesting a launcher wrapper script for portable python

2012-08-11 Thread Gelonida N
I just started looking at portable Python and was rather surprised, that 
I didn't find any recommended method in the documentation of how to

launch scripts with portable python.
Creating py2exe scripts on ones own USB drive seems to be kind of overkill.

So here my own thoughts / suggestsions.
I'm interestted in feedback of how others use portable pythons
and how they run their scripts from a USB stick.


Let's assume I install portable python on my USB drive and then I'd like 
to store self written python scripts on this drive.


It would of course be greate if I could just click on the script and 
they'd be started.



However under windows this would not be the case.
The python script would either not be started at all or if the PC had 
his own python installed, then the script would be started with the PC's 
version of python.


Thus a tiny wrapper script would be needed.


Suggestion:
--
The current directory structore for portable python (2.7) is (assuming 
that %PP% is the base directory)


%PP%/Python-Portable.exe   # launches the python interactive shell
%PP%/PyScripter-Portable.exe   # launches some IDE
%PP%/App

Let's assume I add two more directories:
%PP%/myscripts# location of all callable scripts
%PP%/launchers# location with icons one can click on
  # to start the scripts in myscripts




if I wrote a script named %PP%/myscripts/test1.py,
and I created an aproprriate  named %PP%/launchers/test1.bat

then I could just click on test1.bat and the Python script test1.py 
would be started. If the wrapper script is written properly, then it can 
look at its own base name and call the related python script.


If I dragged and dropped some filenames on the bat file, then they would 
be passed to sys.argv of the script.


Running the script from command line would also work and the present 
working directory would be preserved (which might be useful in some cases)


If the script name would not be .py, but .pyw then it woudl be started 
with pythonw.

T

Below suggested script:



@echo off
REM 
=

REM script to start a python file with portable python
REM 
=


REM basepath of this .bat file
set basepath=%~dp0

REM create the name of the python file related to this bat file
REM Unfortunately I do not know how to normalyze %pyfile%,
REM so we got stuck with the '..'
set pyfile=%basepath%..\myscripts\%~n0.py

If EXIST "%pyfile%" (
REM a normal console python file with .py suffix
"%basepath%\..\App\python.exe" "%pyfile%"  %*
) ELSE (
If EXIST "%pyfile%w" (
REM a non  console python file with .pyw suffix
start "" "%basepath%\..\App\pythonw.exe" "%pyfile%w"  %*
) ELSE (
REM found neither a .py nor a .pyw file
echo found no python file %pyfile%
)
)
REM 
=

REM end of script
REM 
=



One minor drawback of my suggested script would be, that a console 
window pops up for a few seconds when starting a .pyw file.


This could be avoided by using either a small compiled C-file (which 
sounds like overkill though)

or by writing a windows scripting host .wsf file.
However I don't know this well enough to replicate my batch file.
AN article on SO mentions how to write such a script.
However it does not parse command line arguments nor does it
automatically determine the scripts file name.
So any help for creating a .wsf file starting a .pyw file with command 
line arguments would be appreciated.




An alternativce approach could be to provide a scipt named
mk_wrapper.bat
If one drags and drops a python script on it, then an apropriate wrapper 
file would be created in the launcher directory.


If well done, then this could be implemented such, that the script may 
be located in an arbitrary location on the same USB drive.




I think it would be great if the official portable python release 
contained some upport for launching scripts.

Perhaps it exists alrady and I just didn't find it?

If not,then I wouldn't mind if my script or a similiar sand a related 
README.txt cript were added to the official release









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


Re: suggesting a launcher wrapper script for portable python

2012-08-12 Thread Gelonida N

Hi Thomas,

On 08/12/2012 09:05 PM, Thomas Jollans wrote:

On 08/12/2012 02:49 AM, Gelonida N wrote:


One minor drawback of my suggested script would be, that a console
window pops up for a few seconds when starting a .pyw file.


(I'm no expert but) This should be avoidable if you use the Windows
Script Host instead of DOS command scripts to write the launchers.
I.e. use JScript or VBScript to do exactly the same thing. I don't know
much about Windows shortcut (*.lnk) files; if they can contain relative
paths, you could just create shortcuts that launch portable python with
the script.



You're absolutely right and I was rather sure, that I posted a link to 
an SO article with a wsf script avoiding this problem.


Only drawback of this script was, that it did not detect the name of 
it's own script and that it did not pass command line arguments down to 
the python script.


Well here is the link: http://preview.tinyurl.com/bu9rda5

The suggested script was:



set WshShell = WScript.CreateObject("WScript.Shell")
CMDFile = "App\\pythonw.exe App\\gui.py"
WshShell.Run CMDFile, 1



The question is how to extend it such, that it detects it's own name 
(nice to have) and that it passes command line args down to python 
(essential)


I know absolutely nothing about windows scripting.













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


Re: suggesting a launcher wrapper script for portable python

2012-08-12 Thread Gelonida N

On 08/12/2012 09:52 PM, Mark Lawrence wrote:

On 12/08/2012 01:49, Gelonida N wrote:




I think it would be great if the official portable python release
contained some upport for launching scripts.
Perhaps it exists alrady and I just didn't find it?

If not,then I wouldn't mind if my script or a similiar sand a related
README.txt cript were added to the official release



This might be a complete waste of time but can you use the new windows
launcher described here http://www.python.org/dev/peps/pep-0397/ ???



This might be interesting and I have to read a little more.

However on a very first glance I'd assume it had to be stalled on the 
PC, so it would not really be a portable solution (meaning self 
contained on a USB key),that can be executed on any WIndows host.


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


Re: Does anyone have an activate script for portable python?

2012-08-13 Thread Gelonida N

On 08/13/2012 02:12 AM, alex23 wrote:

On Aug 12, 9:09 am, Gelonida N  wrote:

In Pythons installed with virtualenv there is on windows an activate.bat
script, that can be used to setup the cmd-shell such, that the search
path for python and pythor elated tools (pip / easy_install) is setup
properly.
Do such a scripts also exist for Portable python?



Portable Python is just Python with some helper scripts for not
requiring a system installation.

So "command-line-command-to-run-portable-python virtualenv " should be all you need.


Hmm I guess I didn't express myself very well.

The idea is to easily create a cmd window, that the path is setup in 
order to point to portably python by default.


At a first glance at Portable Python it seemed to me, that this doesn't 
exist.


Having a small icon to click at, that opens a cmd window with the right 
setup or just a .bat file, that could be called to adapt the setup of an 
existing cmd window.



It's not too difficult to write such scipts, but I though it would be 
interesting to see whether I'm the only one missing such feature in 
portable Python.

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


Re: Looking for an IPC solution

2012-09-06 Thread Gelonida N

On 08/31/2012 11:05 PM, Antoine Pitrou wrote:

Laszlo Nagy  shopzeus.com> writes:





How about the standard multiprocessing module? It supports shared memory, remote
processes, and will most probably work under PyPy:
http://docs.python.org/library/multiprocessing.html


I always thought, that the multiprocessing module does NOT use shared 
memory (at least not under windows)


My understanding was, that it forks (or whateveri is closest to fork 
under windows) and uses sockets and pickle to communicate between the 
processes.


I would be very interested in a cross platform shared mem solution for 
python.

Could you please point me to the right section.






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


Re: Looking for an IPC solution

2012-09-06 Thread Gelonida N

On 08/31/2012 11:05 PM, Antoine Pitrou wrote:

Laszlo Nagy  shopzeus.com> writes:




How about the standard multiprocessing module? It supports shared
memory, remote processes, and will most probably work under PyPy:
http://docs.python.org/library/multiprocessing.html


I always thought, that the multiprocessing module does NOT use shared
memory (at least not under windows)

My understanding was, that it forks (or whateveri is closest to fork
under windows) and uses sockets and pickle to communicate between the
processes. However perhap s I just misunderstood I never spent time to 
dive into the internals of multiprocessing.



I would be very interested in a cross platform shared mem solution for
python.
Could you please point me to the right section.



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


Re: Looking for an IPC solution

2012-09-06 Thread Gelonida N

On 08/31/2012 11:05 PM, Antoine Pitrou wrote:

Laszlo Nagy  shopzeus.com> writes:





How about the standard multiprocessing module? It supports shared memory, remote
processes, and will most probably work under PyPy:
http://docs.python.org/library/multiprocessing.html


I always thought, that the multiprocessing module does NOT use shared 
memory (at least not under windows)


My understanding was, that it forks (or whateveri is closest to fork 
under windows) and uses sockets and pickle to communicate between the 
processes.


I would be very interested in a cross platform shared mem solution for 
Python.


The intention would be to excahnge mutexes and ctypes kind of data 
structures



Could you please point me to the right section.






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


how to run python2.6 module with absolute imports stand alone

2012-09-07 Thread Gelonida N

Hi,

many of my modules contain following section at the end


def main():
do_something()
if __name__ == '__main__':
main()

This allows me to run some basic example code
or some small test in a stand alone mode.


My new modules contain following line at the beginning:

from __future__ import absolute_import


I like this:
- It can reduce import name conflicts
- and second it allows 'relative' imports like
   from .othermodule import funcname
   from ..mod_one_level_higher import fdfsd


However If I try to run such a script from the command line it will now 
complain with


ValueError: Attempted relative import in non-package

Any tricks to work around this ???

The only idea, that I have is to have a script, that would take my 
modulename or path name as parameter, and try to import it and then call 
the main function of the imported module.



Not very elegant, but probably functional.

Thanks in advance for any other suggestions / ideas.

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


Re: Comparing strings from the back?

2012-09-08 Thread Gelonida N

On 09/06/2012 10:33 AM, Steven D'Aprano wrote:

On Wed, 05 Sep 2012 22:47:14 +, Oscar Benjamin wrote:

I may have been overly-conservative earlier when I said that on average
string equality has to compare half the characters. I thought I had
remembered that from a computer science textbook, but I can't find that
reference now, so possibly I was thinking of something else. (String
searching perhaps?).


Yeah I think you mixed it up with searching an entry in an unsorted list 
of length N



That's one of the most common N/2 cases, that one hits daily with many 
straight forward implementations



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


Re: Comparing strings from the back?

2012-09-08 Thread Gelonida N

On 09/07/2012 06:06 AM, Steven D'Aprano wrote:

On Thu, 06 Sep 2012 06:07:38 -0400, Dave Angel wrote:


Also of some interest is the best case: O(1) for unequal strings (they
differ at the first character) and O(N) for equal strings.


The worst case is O(N) or N characters
the average case is O(1) or two characters.

For denial of service attacks or systems, that are NEVER allowed to fail 
the worst case is important.


For most other cases the average complexity counts.

However I still wonder for how many applications the complexity of 
string comparisons would be the limiting factor.





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


Re: how to run python2.6 module with absolute imports stand alone

2012-09-08 Thread Gelonida N

On 09/08/2012 02:13 AM, Mark Lawrence wrote:

On 07/09/2012 23:04, Gelonida N wrote:

Hi,

many of my modules contain following section at the end


def main():
 do_something()
if __name__ == '__main__':
 main()

This allows me to run some basic example code
or some small test in a stand alone mode.


My new modules contain following line at the beginning:

from __future__ import absolute_import


I like this:
- It can reduce import name conflicts
- and second it allows 'relative' imports like
from .othermodule import funcname
from ..mod_one_level_higher import fdfsd


However If I try to run such a script from the command line it will now
complain with

ValueError: Attempted relative import in non-package

Any tricks to work around this ???

The only idea, that I have is to have a script, that would take my
modulename or path name as parameter, and try to import it and then call
the main function of the imported module.


Not very elegant, but probably functional.

Thanks in advance for any other suggestions / ideas.



I hope this helps
http://stackoverflow.com/questions/3616952/how-to-properly-use-relative-or-absolute-imports-in-python-modules


It seems the safest bet seems to be to not use relative imports.

What I did in the end however is write a wrapper script, that takes 
another script as parameter, converts it's path name to a module name, 
imports it, adapts sys.path and calls main of the imported module.


Perhaps a little overkill, but most convenient, as the script can even 
adapt sys.path prior to importing other files if required.












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


portable way of locating an executable (like which)

2012-09-20 Thread Gelonida N

I'd like to implement the equivalent functionality of the unix command
/usr/bin/which

The function should work under Linux and under windows.

Did anybody already implement such a function.
If not, is there a portable way of splitting the environment variable PATH?

Thanks for any sugestions


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


Re: portable way of locating an executable (like which)

2012-09-20 Thread Gelonida N

On 09/21/2012 12:21 AM, Chris Angelico wrote:

On Fri, Sep 21, 2012 at 7:47 AM, Mark Lawrence  wrote:

On 20/09/2012 22:06, Gelonida N wrote:


I'd like to implement the equivalent functionality of the unix command
/usr/bin/which

The function should work under Linux and under windows.

Did anybody already implement such a function.


Searching found nothing obvious to me :(


I was afraid so, but wanted to be sure



If not, is there a portable way of splitting the environment variable
PATH?

With os.sep ?


os.sep is the directory separator, but os.pathsep may be what you
want.


Thanks,
os.pathsep was the missing piece for portably splitting the searchpath


 Between that and os.getenv('path') you can at least get the
directories. Then on Windows, you also need to check out
os.getenv('pathext') and split _that_ on the semicolon, and try each
of those as a file extension. I'm not sure whether or not Windows will
add extensions from pathext if one is given on the command line - for
instance, if typing "foo.exe" will search for "foo.exe.bat" - but the
basics are there.

For what I am doing I can even skip trying the pathexts, the ext is 
already given, but good to know :-)




Alternatively, there may be a Win32 API funct5ion that does this.
Would be worth a look.


Yeah true, but ideally I'd like to avoid platform detection and
just have a generic function.




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


Re: portable way of locating an executable (like which)

2012-09-20 Thread Gelonida N

On 09/21/2012 12:04 AM, Jason Swails wrote:



Thanks a lot Jason,



I've used the following in programs I write:

def which(program):
def is_exe(fpath):
   return os.path.exists(fpath) and os.access(fpath, os.X_OK)

fpath, fname = os.path.split(program)
if fpath:
   if is_exe(program):
  return program
else:
   for path in os.getenv("PATH").split(os.pathsep):
  exe_file = os.path.join(path, program)
  if is_exe(exe_file):
 return exe_file
return None

IIRC, I adapted it from StackOverflow.  I know it works on Linux and Mac
OS X, but not sure about windows (since I don't know if PATH works the
same way there).


I'll try it, the script looks reasonably portable (using os.pathsep)
to really replicate which I had probably to add os.getenv('pathext')
as Chris mentioned.
However for my current use case this is not necessarily required.


HTH,
Jason






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


PIL questions: still supported? Problems on 2.7 for win? alternatives?

2012-09-24 Thread Gelonida N

Hi,

I'm trying to migrate a project with legacy code from 2.6 (with PIL 
1.1.6) to 2.7 with (PIL 1.1.7)

The SW should run on Windows.


PIL fails with an error concering '_imagingft'
This seems to be a known issue.

http://code.google.com/p/pythonxy/issues/detail?id=300
and the bug was never closed.

One suggestion is to download an alternative build from a non official site.

Looking at the activity of PIL ( 
http://www.pythonware.com/products/pil/index.htm ) it seems, that 
development stopped,
The latest build (with known bugs and missing functionality for python 
2.7.) seems to be from November 15, 2009.
In the net I read, that there's so little activity on PIL, because it's 
stable, which doesn't seem to be the case for the 2.7 binary package.


This all does not sound very comforting. Why is there no fix on the 
official site?


I wondered whether some of you have a little more insight into what's 
going on with PIL.


Short term: get PIL working on 2.7 windows?

My shortterm problem is migrating existing code to 2.7 and keeping the 
code, that uses PIL.
So I'll probably try to install the custom binary, but would like to 
know whether anybody has experience with this build.

http://www.lfd.uci.edu/~gohlke/pythonlibs/#pil

Alternatively how tricky is PIL to be compiled with mingw?



Mid term: What to use to manipulate images?


My midterm problem is to stay with Python 2.7 and to write occasinally 
new code, that does some basic image manipulations.


Can I still count on PIL? The fact, that the official devs don't even 
bother to fix some basic functionality of their binary release tells me 
that either very few people use PIL (or at least the broken 
functionality somehow related to the font libraries) on 2.7


What alternatives do exist for PIL?
We just need some lines drawn, some text drown, some scaling, 
transparency merging, . . . and PIL seend decent enough.


There seems to be freeimagepy, but the bindings seem to be 'only' ctypes 
bindings http://freeimagepy.sourceforge.net/

Any experience with this libraries?

Any other suggestions?



Longterm Will PIL officially exist for Python 3?
-

When really all libraries that the project  needs are supported
I''ll probably migrate to Python 3.

For Python 3 there is not even a broken official release, but only forks.

Why isn't any of these forks becoming 'official'?

If a package is not supported for Windows via official binary releases / 
easy_install, then I'm a little more afraid, that the package 
(maintainers included) will disappear in the near future.


Thanks a lot in advance for opinions / recommendations / clarifications









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


Re: PIL questions: still supported? Problems on 2.7 for win? alternatives?

2012-09-25 Thread Gelonida N

On 09/25/2012 01:38 AM, alex23 wrote:

On Sep 25, 6:04 am, Gelonida N  wrote:

This all does not sound very comforting. Why is there no fix on the
official site?


Has a bug been logged about the issue?

The Plone community keeps a fairly up-to-date fork called Pillow,
we've had a lot of success using that locally:

http://pypi.python.org/pypi/Pillow/


Thanks for all your answers.

So it seems to be safe to use either Christoph' binary PIL distribution 
or to use Pillow.


The fact, that pillow is accessable via PyPi / easy_install / PIP pushes 
me slightly towards pillow.



I assume it's best to uninstall PIL before installing pillow.


How much would I confuse easy_install / pip in a normal windows
non virutal environment if I didn't uninstall PIP before (or even worse 
if I installed PIL, then pillow and uninstalled then PIL)


(Just anticipating all the smart thigns, that my collegues (or myself) 
might do



On a Linux machine:
What would happen in a virtualenv with sitepackages (amonst them PIL 
installed and a pillow installed ontop of it?

I don't think I can uninstall PIL, as many distro packages depend on it.
I don't want to create a virtualenv without site packages, as I have 
many dependencies and some of them are a little tricky to compile.


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


mimetypes.guess_type broken in windows on py2.7 and python 3.X

2012-09-26 Thread Gelonida N

Hi,

I'm still experiencing the pleasure of migrating legacy code from Python 
2.6. to 2.7 which I expected to be much less painful.

(In fact migration on Linux is rather smooth, but Windows is another story)


Let's take the simple command

import mimetypes
print mimetypes.guess_type('a.jpg')


The result an old pythons ( 2.7)
is  ('image/jpeg', None)

Ther result on non windows platform is
for python 2.7 / 3.X is the same

However. The result for 2.7 / 3.x on windows is now
('image/pjpeg', None)  # pjpeg instead of jpeg

On Windows many file suffixes  will report wrong mime types.

The problem is know for about two years.
http://bugs.python.org/issue10551


The main reason is, that under wWindows default values are
fetched from Python and then 'updated' mime-types are
fetched from the Windows registry.
The major problem is, that almost ALL windows PCs have BROKEN mime 
types. so the good predefined mime types are just replaced with broken 
MS mime types.



I wonder how many applications, that will try to migrate to 2.7 / 3.0 
will fail due to this incompatibility in the mimetypes library



There is a workaround (but first people have to detect the problem and 
to find it):
Add these two lines somewhere in your code BEFORE any other imported 
library might have called a mimetypes function


import mimetypes
mimetypes.init([])

I still wonder if it wouldn't be better to have the default behaviour of 
2.7 / 3.0 on windows such, that all the users who're not aware of this 
issue will not have their code broken.


My suggestion for windows would be to have following default behaviour:

- !st read the mimetypes from the registry if possible
- 2nd read the Python default mimetypes and override the
   'broken' MS definitions

Only if a user explicitely calls mimetypes.init() they would have 
differente behaviour.


The new behaviour breaks portability of Python code between Windows and 
Linux and I think the attempt should be to be as cross platform as 
possible. and not to be. At least one of the reasons why I use pythin 
is, that it allows to be rather cross-platform


An alternative suggestion could be to never read the registry or 
/etc/mimetypes by default.


What would definitely be rather important is add a big warning in the 
documentation and a recommendation of how to write cross platform 
compatible code.


Somebody developing on Linux might not even know, that the code will not 
work on windows jsst because of this tiny issue.



The unfortunate fact, that this issue was not fixed two years ago means, 
that perhaps meanwhile some code is out, that relies on the current 
behaviour. However I'm not sure, that anybody relies on the fact, that 
code will not work the same way on windows and on Linux.


Any thoughts?









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


Re: PIL questions: still supported? Problems on 2.7 for win? alternatives?

2012-09-26 Thread Gelonida N

On 09/25/2012 02:42 PM, alex23 wrote:

On Sep 25, 6:25 pm, Gelonida N  wrote:

So it seems to be safe to use either Christoph' binary PIL distribution
or to use Pillow.

The fact, that pillow is accessable via PyPi / easy_install / PIP pushes
me slightly towards pillow.




I assume it's best to uninstall PIL before installing pillow.


I would expect you'd be fine. Being a different package, it's a
different namespace, so they shouldn't conflict.


This is what is confusing me.
if I start with a new python and I just install Pillow, then pillow is 
imported via

import PIL
so it does not seem to have a separate name space

If I had PIL and pillow installed, then I wouldn't even know how to 
choose which one to import.






On a Linux machine:
What would happen in a virtualenv with sitepackages (amonst them PIL
installed and a pillow installed ontop of it?
I don't think I can uninstall PIL, as many distro packages depend on it.
I don't want to create a virtualenv without site packages, as I have
many dependencies and some of them are a little tricky to compile.


Again, you should be fine, as it's in a separate namespace. You
definitely don't want to mess with PIL if you have other dependencies.


Well I'm slightly confused, but will play a little to see what exactly works




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


templating performance

2012-09-26 Thread Gelonida N

http://mindref.blogspot.fr/2012/07/python-fastest-template.html

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


Re: templating performance

2012-09-27 Thread Gelonida N

On 09/27/2012 02:17 AM, alex23 wrote:

On Sep 27, 7:50 am, Gelonida N  wrote:

http://mindref.blogspot.fr/2012/07/python-fastest-template.html


This is already being discussed on the list. See the thread "Fastest
template engine".


Apologies everybody,

I wanted to 'bookkmark' (forward this article to myself) and posted it 
accidentally once more to this group. (Can happen if not paying 
attention with Thunderbird :-( )





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



Re: SSH Connection with Python

2012-10-26 Thread Gelonida N

On 10/25/2012 12:47 PM, Kamlesh Mutha wrote:

You can use paramiko module. Very easy to use.




I also use paramiko for a small script.

However I'm a little hesitant to use paramik for new code.

The web page says: "last updated 21-May-2011"

and the github url  http://github.com/robey/paramiko/
yields me a 404

However I didn't really find any alternative.
For cross platform scripts  (Linux / windows)
subprocess is not such a good alternative.


Another problem is, that paramiko depends on pycrypto 2.1+
which doesn't exist as binary release for python 2.7


Is fabric capable of performing scp / sftp

Is there any other library as alternative?

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


Re: SSH Connection with Python

2012-10-27 Thread Gelonida N

On 10/27/2012 02:21 AM, Roy Smith wrote:

In article ,
  Gelonida N  wrote:


Another problem is, that paramiko depends on pycrypto 2.1+
which doesn't exist as binary release for python 2.7


I'm running paramiko-1.7.6 with python 2.7.3 on my Ubunto Precise box.
I'm reasonably sure all I did was "pip install paramiko".


Apologies.  I failed to mention, that I was talking about Windows not Linux.

I use Python for applications, that should work under Linux and under 
Windows.




But, keep in mind that fabric depends on paramiko.  If you can't get
paramiko installed, you probably can't get fabric either.

Thanks, that's good to know, so I don't have to bother looking at farbic 
(at least not as solution on windows python 2.7 without having to try to 
recompile pycrypto myself)



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


Re: attaching names to subexpressions

2012-10-27 Thread Gelonida N

On 10/27/2012 04:42 AM, Steve Howell wrote:
> I have been reading the thread "while expression feature proposal,"
> and one of the interesting outcomes of the thread is the idea that
> Python could allow you to attach names to subexpressions, much like C
> allows.  In C you can say something like this:
>
>tax_next_year = (new_salary = salary * (1 + raise)) * tax_rate
>
> To avoid the "=" pitfall, folks have proposed something like this for
> Python:
>
>tax_next_year = ((salary * (1 + raise)) as new_salary) * tax_rate
>print new_salary, tax_next_year
>
. . .
>
> If the problem statement is "How do I name subexpression?", then
> Python already has a clear path--break your code up into multiple
> lines.  I'm wondering where this simple solution really breaks down
> from a readability perspective.  Perhaps with short-circuited boolean
> expressions?
>

For me two places where expression assignemts can be useful are while 
loops and sometimes elif statements.



While example


line = complex_exression
while line:
do something with(line)
line = complex_expression

violates clearly the DRY principle  and the risk to change one line but 
not the other is high.



The 'canonical way'
while True:
line = complex_expression
if not line:
break
do_something_with(line)

avoids this problem, but I was never really convinced about the
beauty / readbility of this construct.

One misses the exit condition of the while loop on the first glance.
In my opinion I shouldn't be obliged to read any of the indented lines
of the while statement on a first 'visual' pass through somebody elses 
code and still be able to see what the loop iterates through.



Following looks in my opinion nicer.

while complex_expression as line:
do_something_with(line)

or the even more powerful suggestion:

while (complex_expression as line) is not None:
do_something_with(line)


Elif Example:
--

value1 = expression1
if (value1):
   do_something
else:
value2 = expression2
if(value2):
do_something_with(value2)
else:
value2 = expression3
if(value3):
do_something_with(value3)

Could be rewritten as

value1= expression1
if(value1):
do_something_with(value1)
elif(expression2 as value2):
do_something_with(value2)
elif(expression3 as value3):
do_something_with(value3)



However in all other cases I really think using this new syntax would 
reduce readability andit would be better to just split the statement 
into two lines.


for while / elif statements splitting up is not possible without doing 
some further acrobatics, which render in my opinion the code less readable.



If the new syntax were adopted, then one open question
would be scoping.

value=expression
if(value):
do_something_with(value)
elif(expression2 as value):
do_something_with(value)
elif(expression3 as value):
do_something_with(value)
print value # will value leak out of the elif statements or not

I never tried to use other 'as-variables' (e.g. from  'with' or 'except' 
statements) outside of their indented block,

so I never bothered to check how Python would react.






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


Re: SSH Connection with Python

2012-10-28 Thread Gelonida N

On 10/28/2012 02:35 AM, Cameron Simpson wrote:

On 27Oct2012 14:18, Gelonida N  wrote:
| On 10/27/2012 02:21 AM, Roy Smith wrote:
| > In article ,
| >   Gelonida N  wrote:
| >
| >> Another problem is, that paramiko depends on pycrypto 2.1+
| >> which doesn't exist as binary release for python 2.7
| >
| > I'm running paramiko-1.7.6 with python 2.7.3 on my Ubunto Precise box.
| > I'm reasonably sure all I did was "pip install paramiko".
|
| Apologies.  I failed to mention, that I was talking about Windows not Linux.
|
| I use Python for applications, that should work under Linux and under
| Windows.
|
| > But, keep in mind that fabric depends on paramiko.  If you can't get
| > paramiko installed, you probably can't get fabric either.
| >
| Thanks, that's good to know, so I don't have to bother looking at farbic
| (at least not as solution on windows python 2.7 without having to try to
| recompile pycrypto myself)

Many years ago we ran an ssh executable on Windows; it was a tiny
standalone kit consisting, IIRC, of the Cygwin libc and ssh. Or you
could just install Cygwin...

That would let you use Python's subprocess module to invoke ssh and
dispatch your command.


On all my work PCs cygwin is installed.

However when packaging something with py2exe I'd really prefer to not 
have to install additional .exe / .dll files just for the ssh client.
This is why I like the idea of Paramiko. which requires the crypto .dll, 
but that's it.


The only thing I'm concerned about paramiko is, that I don't see any 
activity on the paramiko site and that one library it depends on is not 
available is windows binary package for newer versions of python.


For the time being I stick with paramiko as I'm still on py2.6, but I 
wanted to have some feedback, whether this path can easily be followed 
in the mid term future or whther I ahd to fall back to a minimalist set

of ssh executables / dlls and a subprocess wrapper.



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


Re: SSH Connection with Python

2012-10-28 Thread Gelonida N

On 10/26/2012 05:22 AM, Jason Friedman wrote:

how can i create a SSH-Connection with python? I have to send some commands
to the remote host and parse their answers.


Consider also the sh module:
http://amoffat.github.com/sh/tutorials/2-interacting_with_processes.html.




Just a minor comment:  The sh module looks intersting, but it's not 
supported for Windows platforms.


Please note: I'm not the original poster, so perhaps this is no issue 
for him.


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


Re: SSH Connection with Python

2012-10-29 Thread Gelonida N

On 10/29/2012 04:18 PM, David Robinow wrote:

On Sun, Oct 28, 2012 at 4:09 PM, Gelonida N  wrote:

The only thing I'm concerned about paramiko is, that I don't see any
activity on the paramiko site and that one library it depends on is not
available is windows binary package for newer versions of python.


  I don't understand why this is a problem.
\python27\python setup.py install #for pycrypto & paramiko
\python27\python test.py   # for paramiko

Works for me.  Of course, you need  Visual C++ 2008, but the free
express edition is sufficient, and you should have that anyway if
you're doing Windows development. If that's too hard for you, try
http://www.serenethinking.com/bitlift/download.html
[not my site, no guarantees]


It's not a problem. It's an inconvenience.

We're having multiple PCs. Many of the PC owners don't want to write any 
C-code and don't want to be bothered with registering at Microsoft just 
to install a module and using a library.


Normally my preferred approach is, that somebody wanting to use any 
library, that I wrote)  can install all dependencies  by:


- Installing Python
- installing easy_install (and pip)
and be able to install all the rest with easy_install

Using a library, that forces users to have to install MS-VC or mingw or 
to install binaries from non-pypy sites is something I try to avoid.


My next preferred approach would be to bundle such dependencies by 
myself, but this would involve to check all the legal stuff of each 
library to see whether this is possible or not, etc . . .



Apart from that I consider the existence of Windows binary packages as
kind of an indicator of the health/popularity of a package and whether 
it has been used sufficiently under Windows to be considered working 
well under Windows.









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


Re: SSH Connection with Python

2012-10-29 Thread Gelonida N

On 10/29/2012 02:10 PM, Roy Smith wrote:

In article ,
  Gelonida N  wrote:


The sh module looks intersting, but it's not supported for Windows
platforms.


"The X module looks interesting but it's not supported for Windows" is
true for many values of X.  It's all part of the TCO of using a
brain-dead operating system.


If I write server side code, then I choose my server and my OS, so I 
won't encounter Windows


Unfortunately most the customers won't let me choose their client 
hardware / client OS.


Thus I decide to write my applications cross platform whenever possible 
and try to choose libraries accordingly.







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


windows question: default click action points to wrong python version

2012-11-21 Thread Gelonida N

Hi,

I installed python 2.6 and python 2.7 on a windows 7 machine.

At the moment Python 2.7 is the interpreter being used if I 'start' a 
python script without explicit interpreter.


I always thought, that 'repairing' Python 2.6 (reinstalling it) would 
set the default settings back to Python 2.6.


I also see with assoc / ftypes, that python 2.6. has now been configured 
as default.


However when I click on a script it is still started with 2.7.
(even after a full restart of the machine)

This is really surprising to me.
I thought ftype is the command to change file associations.

What am I missing?


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


Re: windows question: default click action points to wrong python version

2012-11-21 Thread Gelonida N

Hi Tim,


Thanks a lot for your answer.

On 11/21/2012 10:34 AM, Tim Golden wrote:

On 21/11/2012 08:23, Gelonida N wrote:

Hi,

I installed python 2.6 and python 2.7 on a windows 7 machine.

At the moment Python 2.7 is the interpreter being used if I 'start' a
python script without explicit interpreter.

I always thought, that 'repairing' Python 2.6 (reinstalling it) would
set the default settings back to Python 2.6.

I also see with assoc / ftypes, that python 2.6. has now been configured
as default.

However when I click on a script it is still started with 2.7.
(even after a full restart of the machine)

This is really surprising to me.
I thought ftype is the command to change file associations.



This area is a bit messy. There is a difference between: going to the
command line and typing "myscript.py"; and double-clicking on a file in
Explorer.

The former uses the result of merging the assoc/ftype registry keys:

HKEY_CURRENT_USER\Software\Classes\Python.File\shell\open\command

HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Python.File\shell\open\command


while the latter uses the Explorer registry keys at:


HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.py\UserChoice





Initially, I suppose, the two are in sync. But presumably they can get
out of sync, especially if you move backwards and forwards between
associations. I haven't bothered fishing around in the Shell API but I
presume that you can reconcile the two -- or just edit the registry,
obviously.


Hmm I don't mind changing the registry, now that I know the culprit.
Will try it tomorrow when being back to my Win PC.







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


Re: generate Windows exe on Linux

2012-02-22 Thread Gelonida N
On 02/22/2012 07:05 PM, Alec Taylor wrote:
> http://www.pyinstaller.org/
> 
> or
> 
> http://cx-freeze.sourceforge.net/
> 
> You can also run py2exe in WINE
> 

You want to say, that I could install python 2.6
some packages like win32api
PyQt and tand py2exe under Wine and then compile it.


Did you try this?

I didn't even think about trying this out,
but I know very little about the limits of Wine, so perhaps I
underestimate it.






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


Abort an HTTP request before the request timed out

2012-02-26 Thread Gelonida N
Hi,

I'm working in a small application, which tries to access data on a web
server.

Normally the request has a timeout of for example 60 seconds

conn = httplib.HTTPConnection(server_name, server_port, timeout=60)
while True:
conn.request("GET", "/my_url.php")
try:
resp = conn.getresponse()
except HaveToLookUpNameOfTimeOutException as exc:
print "timed out"
continue
parse_response(resp)

Sometimes I would like to abort the request from another thread and
force an immediate retry.

How would I do this best?
The other thread would be either a UI button or some other code knowing,
when it is not good to wait the ull minute.

Normally the timeout of 1 mintues is what I need though.

Thanks for any suggestion.

The solution should work on Windows and Linux



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


Re: pickle/unpickle class which has changed

2012-03-06 Thread Gelonida N
Hi Peter,

A related question.


Is there anyhing like a built in signature which would help to detect,
that one tries to unpickle an object whose byte code has changed?

The idea is to distinguish old and new pickled data and start some
'migration code' fi required


The only thing, that I thought about so far was adding an explicit
version number to each class in order to detect such situations.



On 03/06/2012 02:52 PM, Peter Otten wrote:
> Neal Becker wrote:
> 
>> What happens if I pickle a class, and later unpickle it where the class
>> now has added some new attributes?
> 
> - If the added attributes' values are immutable, provide defaults as class 
> attributes.
> 
> - Implement an appropriate __setstate__() method. The easiest would be
> 
> # untested
> def __setstate__(self, state):
> self.__dict__.update(newattr1=42, newattr2=[])
> self.__dict__.update(state)
> 


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


Re: pickle/unpickle class which has changed

2012-03-07 Thread Gelonida N
On 03/07/2012 09:04 AM, Peter Otten wrote:
> Gelonida N wrote:

> If you know in advance that your class will undergo significant changes you 
> may also consider storing more stable data in a file format that can easily 
> be modified, e. g. json.
> 
Good point, that's what I'm partially doing. I just wondered whether
there were already some kind of pre-existing data migration tools /
concepts / helpers like for example south for Django or whether I had to
roll my own migration scheme for persistent non DB data.





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


How to know that two pyc files contain the same code

2012-03-10 Thread Gelonida N
Hi,

I want to know whether two .pyc files are identical.

With identical I mean whether they contain the same byte code.

Unfortunately it seems, that .pyc files contain also something like the
time stamp of the related source file.

So though two pyc files contain the same byte code, they will not be
byte identical.

One option, that I found is to use
python -m unpyclib.application -d filename.pyc and check whether the
results are identical.


However even this will fail if the files were not compiled under the
same absolute path name as the source filename is contained twice  (at
least for my trivial example) in the disassemblers output.


Thanks a lot for any other idea.



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


How to know that two pyc files contain the same code

2012-03-10 Thread Gelonida N
Hi,

I want to know whether two .pyc files are identical.

With identical I mean whether they contain the same byte code.

Unfortunately it seems, that .pyc files contain also something like the
time stamp of the related source file.

So though two pyc files contain the same byte code, they will not be
byte identical.

One option, that I found is to use
python -m unpyclib.application -d filename.pyc and check whether the
results are identical.


However even this will fail if the files were not compiled under the
same absolute path name as the source filename is contained twice  (at
least for my trivial example) in the disassemblers output.


Thanks a lot for any other idea.



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


Re: How to know that two pyc files contain the same code

2012-03-10 Thread Gelonida N
Hi Steven,

On 03/10/2012 11:52 PM, Steven D'Aprano wrote:
> > On Sat, 10 Mar 2012 15:48:48 +0100, Gelonida N wrote:
> >
>> >> Hi,
>> >>
>> >> I want to know whether two .pyc files are identical.
>> >>
>> >> With identical I mean whether they contain the same byte code.
> >
> > Define "identical" and "the same".
Indeed! Identical is not that simple to define and depends on the context.

One definition of identical, that would suit me at the moment would be:

If I have two .pyc files, which were the result of a compilation of
two identical .py files, then I would like to treat these two .pyc files
as identical,
even if they were compiled at different times (absolutely necessary)
and with a different absolute path (would be nice)

Above definition of identical byte code would also mean, that any error
message about errors in a given line number would be identical for both
.pyc files

> >
> > If I compile these two files:
> >
> >
> > # file ham.py
> > x = 23
> > def func():
> > a = 23
> > return a + 19
> >
> >
> >
> > # file = spam.py
> > def func():
> > return 42
> >
> > tmp = 19
> > x = 4 + tmp
> > del tmp
> >
> >
> > do you expect spam.pyc and ham.pyc to count as "the same"?
> >
For most pythons I would not expect, that ham.py and spam.py would
result in the same byte code and would thus not even have the same
performance,

I agree, though that an efficient compiler might generate the same byte
code, though I wonder if an optimizing compiler would/should be allowed
to optimize away the global variable tmp, as it would be visible (though
only for a short time) in a multithreading environment.

If the byte code were different in two .pyc files. then I would
like to have them treated as different .pyc files.

If by coincidence, the generated btye code were the same, then I
wouldn't mind, if they were treated as identical,  but I wouldn't insist.

Up to my knowledge Python (or at least C-python) stores line numbers in
the .pyc files, so that it can report exact line numbers refering to the
originating source code in case of an exception or for back traces

So there is the choice to say, that two pyc files with exactly the same
byte code would be treated identical if white spaces / line numbers of
their sources were different or the choice to say, that they are
different.

Being conservative I'd treat them as different.

Ideally I'd like to be able depending on my use case to distinguish
following cases.
a) .pyc files with identical byte code
b) .pyc files with identical byte code AND source code line numbers
c) same as b) AND identical source file names.






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


  1   2   >