RE: Need to pass a class instance to a gettext fallback

2017-09-09 Thread Josef Meile
Hi Peter

>> language = kwargs['language']
>> del kwargs['language']
>
>Not really important, but there's a method for that:
>
>language = kwargs.pop("language")
Thanks, this looks better and I indeed think it is important. The "del ..." 
line looks ugly.

>>   def __init__(self, *args, **kwargs):
>> language = kwargs['language']
>> del kwargs['language']
>
>In Python 3 this can also be spelt with a keyword-only language argument:
>
>def __init__(self, *args, language, **kwargs):
>...  # no pop() or del
I'm using Python 2.7.10, but this also works there, so, I replace it with your 
suggestion.

And before you tell me that python 2.7 is old, the thing is that I'm writing a 
pluging for Gimp and this is the version they distribute :-(

Thanks for your valuable help

Best regards
Josef
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Need to pass a class instance to a gettext fallback

2017-09-08 Thread Josef Meile
Hi Peter

Your code worked, but I did some changes. First of all: I decided that I don't 
really needed to pass the py_plugin instance. I only needed an attribute 
called: self._language. Anyway, if I passed it without doing anything else, I 
got:
TypeError: __init__() got an unexpected keyword argument 'language'

In this call inside the MissingTranslationsFallback class.
super(MissingTranslationsFallback, self).__init__(*args, **kwargs)

The error is clear, the constructor of: "gettext.GNUTranslations" isn't 
expecting an argument called: 'language', so, I removed it before doing the 
call:
language = kwargs['language']
del kwargs['language']
super(MissingTranslationsFallback, self).__init__(*args, **kwargs)

And it worked. Thanks a lot for your help. Now it looks nice without those 
nasty global variables :-)

Here the resulting code:
class TranslationService(object):
  """...__init__ and other methods are defined here"""

  def install(self):
"""...some code goes here..."""
current_catalog = gettext.translation(plugin_name, localedir = 
locale_folder,
   class_= 
functools.partial(
   
MissingTranslationsFallback, 
   language 
= self._language
  ),
  languages 
= [current_language]
 )
current_catalog.install()

class MissingTranslationsFallback(gettext.GNUTranslations, object):
  def __init__(self, *args, **kwargs):
language = kwargs['language']
del kwargs['language']
super(MissingTranslationsFallback, self).__init__(*args, **kwargs)
self.add_fallback(MissingTranslationsLogger(language))

Best regards
Josef

-Original Message-
From: Python-list [mailto:python-list-bounces+jmeile=hotmail@python.org] On 
Behalf Of Peter Otten
Sent: Freitag, 8. September 2017 08:15
To: python-list@python.org
Subject: Re: Need to pass a class instance to a gettext fallback

Josef Meile wrote:

> Hi
> 
> I'm working with gettext and need to define a language Fallback. I got 
> this working, but with a global variable. I don't really like this and 
> I would like to pass this variable to the gettext Fallback's 
> contructor, but I don't know how. For simplicity, I won't put the 
> whole code here, just the important parts.
> 
> Before you look at it, I want to ask you: how can I pass the variable:
> "my_plugin" to the constructor of the "MissingTranslationsFallback" class?
> If you see, an instance of this class will be created automatically by 
> gettext. I don't create it. When calling the " add_fallback" method of 
> the gettext.GNUTranslations class, you have to pass a class and not an 
> instance.

Provided the class_ argument to gettext.translation() accepts an arbitrary 
callable the following may work:

import functools

> #Defining a global dict, which is ugly, I know MY_GLOBALS = {}
> 
> class TranslationService(object):
>   """...__init__ and other methods are defined here"""
> 
>   def install(self):
> """...some code goes here..."""
 
 current_catalog = gettext.translation(
 plugin_name, 
 localedir=locale_folder,
 class_=functools.partial(
 MissingTranslationsFallback, 
 py_plugin=self._py_plugin
 ), 
 languages=[current_language]
  )
> current_catalog.install()
> 
> class MissingTranslationsFallback(gettext.GNUTranslations, object):
>   def __init__(self, *args, **kwargs):

  py_plugin = kwargs.pop("py_plugin")

> super(MissingTranslationsFallback, self).__init__(*args, **kwargs)

> i18n_service = py_plugin.get_i18n_service()
> #Adds an instance to the class that will handle the missing
> #translations
> 
self.add_fallback(MissingTranslationsLogger(i18n_service.get_language()))


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


Need to pass a class instance to a gettext fallback

2017-09-07 Thread Josef Meile
Hi

I'm working with gettext and need to define a language Fallback. I got this 
working, but with a global variable. I don't really like this and I would like 
to pass this variable to the gettext Fallback's contructor, but I don't know 
how. For simplicity, I won't put the whole code here, just the important parts.

Before you look at it, I want to ask you: how can I pass the variable: 
"my_plugin" to the constructor of the "MissingTranslationsFallback" class? If 
you see, an instance of this class will be created automatically by gettext. I 
don't create it. When calling the " add_fallback" method of the 
gettext.GNUTranslations class, you have to pass a class and not an instance.

#Defining a global dict, which is ugly, I know
MY_GLOBALS = {}

class TranslationService(object):
  """...__init__ and other methods are defined here"""

  def install(self):
"""...some code goes here..."""
#Now the ugly part :-(
MY_GLOBALS['py_plugin'] = self._py_plugin
current_catalog = gettext.translation(plugin_name, localedir = 
locale_folder,
class_= MissingTranslationsFallback, languages = [current_language])
current_catalog.install()

class MissingTranslationsFallback(gettext.GNUTranslations, object):
  def __init__(self, *args, **kwargs):
super(MissingTranslationsFallback, self).__init__(*args, **kwargs)

#And here is where I need to access py_plugin :-(
py_plugin = MY_GLOBALS['py_plugin']
i18n_service = py_plugin.get_i18n_service()
#Adds an instance to the class that will handle the missing translations
self.add_fallback(MissingTranslationsLogger(i18n_service.get_language()))

class MissingTranslationsLogger(gettext.NullTranslations):
  def __init__(self, language):
self._language = language
self._missing = set()

  def gettext(self, message):
if (message not in self._missing):
  self._missing.add(message)
  print "Missing message: " + message + " current language: " + 
self._language
return message

Any help would be appreciated.

Best regards
Josef
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: MinGW and Python

2006-04-24 Thread Josef Meile
> Is there any specific reason for not using MinGW to build the official
> distribution of Python for Win32?
> A quick Google search did not reveal the answer to my question. If a
> link is available, please post it.
You may look at this thread:

* E02 - Support for MinGW Open Source Compiler
   http://tinyurl.com/lxfsz

There was a big polemic and it is really long, but there are some useful
posts there.

Regards,
Josef

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


Re: how to install PYCURL 7.15.2 on windows 2003?

2006-04-13 Thread Josef Meile

 > I download it from http://pycurl.sourceforge.net/
 > and then extract it to  D:\usr\pycurl-7.15.2
 > then
 > D:\usr\pycurl-7.15.2>setup.py install --curl-dir=d:\usr\pycurl-7.15.2
 > Using curl directory: d:\usr\pycurl-7.15.2
 > Traceback (most recent call last):
 >   File "D:\usr\pycurl-7.15.2\setup.py", line 197, in ?
 > assert os.path.isfile(o), o
 > AssertionError: d:\usr\pycurl-7.15.2\lib\libcurl.lib
I would say you need to install libcurl first. "--curl-dir"
isn't the directory where you want to install pycurl; it is
the location of the curl library, which isn't implemented in
python.

You can find the binaries (or the sources) here:
http://curl.haxx.se/dlwiz/

Regards
Josef

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


Re: Old Python Logo

2006-03-13 Thread Josef Meile
>>Can someone post a link or email me an image of the old Python logo?
>>I'd like to save a copy of it, I rather liked it - very retro.
> 
> 
> the dot matrix logo ?
> 
> you can get a copy from this page:
> 
>
That website is down. You could try the archive as well:
http://web.archive.org/web/20050401015445/http://www.python.org/

Regards
Josef

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


Re: writing IM bots

2005-12-13 Thread Josef Meile
Hi,

> I am trying to write an IM Bot, which automatically replies to a
> message, in Python.
> I was wondering If there are python modules for connecting to Yahoo!,
> msn networks ...
> ideally I would like to have a multithreaded module.
> 
> This is one I found for msn, if anyone has used it please comment,
> - http://users.auriga.wearlab.de/~alb/msnlib/
I haven't used that, but it looks cool ;-)

If you are interested in yahoo, then here is another python application
to connect to the yahoo messenger:

http://www.nongnu.org/curphoo/

Again, I haven't tried that one, but perhaps you could just test it.

I have other links to tools based in the libyahoo2[1] package, but
unfortunately all are written in C or java. Perhaps you could find a
python wrapper in google.

Regards,
Josef


[1] http://libyahoo2.sourceforge.net

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


Re: Overloading

2005-12-09 Thread Josef Meile
>>> In C++ you can overload functions and constructors. For example if I 
>>> have a
>>> class that represents a complex number, than it would be nice if I can
>>> write two seperate constructors
>>
>>
>>
>> Python doesn't support this, but it does support default arguments:
> 
> Yes, in part you are right since the python core doesn't include them.
> However they can be implemented with decorators:
> 
> * Subject: decorators and multimethods
>   Group:   comp.lang.python
>   Link:http://tinyurl.com/d45ym
There is even a better recipe, explained step by step from Guido:
* Five-minute Multimethods in Python
   Link: http://tinyurl.com/8ppd6

Regards
Josef

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


Re: Overloading

2005-12-09 Thread Josef Meile
>>In C++ you can overload functions and constructors. For example if I have a
>>class that represents a complex number, than it would be nice if I can
>>write two seperate constructors
> 
> 
> Python doesn't support this, but it does support default arguments:
Yes, in part you are right since the python core doesn't include them.
However they can be implemented with decorators:

* Subject: decorators and multimethods
   Group:   comp.lang.python
   Link:http://tinyurl.com/d45ym

Anyway, as you, I also use the default arguments.

Regards
Josef

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


Re: Sending an event from a python COM server to a VB COM client

2005-11-16 Thread Josef Meile
Hi Gary,

> I am trying to send an event from a Python COM server to a VB (or VB.NET) 
> COM client.
> I am a newbie both in VB and in python.
> Can anyone give me a simple (but complete) code example both of the Python 
> server side and the VB client side for raising a single event.
Do you mean interprocess communication? If so, then you could use the
WM_CopyData message from the Windows API. However, this will only work
if the two applications are running in the same machine and if at least
one of them (the receiver) has a Window were to send the messages.

I have been used the following application to comunicate two C#
applications:

* Simple Interprocess Communications using WM_COPYDATA
http://www.vbaccelerator.com/home/NET/Code/Libraries/Windows_Messages/Simple_Interprocess_Communication/article.asp

However, the zip contains a VB.Net example as well. I haven't ever done
this with python, so, I don't know how it works. However, you could take
a look at the following thread, which discuss how to implement this
with python:

* PyWin SendMessage
http://groups.google.ch/group/comp.lang.python/browse_frm/thread/cf7412ec873cd265/c362e88d9e5d7e80

I have also tried other approaches, but they didn't work on my case, or
they require you to have additional hardware (ie: a network card), or to
install additional software (ie: Microsoft Windwos Message Queuing).
However, they might work for you:

* Windows Sockets may be the easiest solution and you can find several
   examples of this with google. In my case, I didn't use them 'cause
   they require my users to have a network card and my system is just
   a single user application with several processes running on the same
   machine.

* Named Pipes, which are a feature of windows:
   - Inter-Process Communication in .NET Using Named Pipes, Part 1
 http://ivanweb.com/articles/namedpipes/index.cfm

   - How to use named pipes for interprocess communication in Visual
 Basic .NET
 http://support.microsoft.com/?kbid=871044

* Microsoft Windows Message Queuing (MSMQ) -> I don't have a VB/VB.NET
   example for this; only a C# example, but it may work in VB/VB.NET
   as well since if I'm not wrong, it also uses the Windows Api. Again,
   I didn't used it because it requires my users to install the MSMQ
   software from Microsoft, which is included with Windows.

   - Using MSMQ from C#
 http://www.codeproject.com/csharp/mgpMyQueue.asp

Unfortunatelly, I don't have python examples, but since they use the
Windows Api it may be possible to implement with the windows extensions
for python. You just have to look for them in the python list.

Regards,
Josef

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


Re: useradd command in Zope

2005-11-07 Thread Josef Meile
Sorry, I replied to the Wrong list :-(




Josef Meile wrote:
>> su zope (or whoever your zope runs)
>> ./yourmethod.py someuser somepass
>>
>> You will see it fail (apart from the fact you need
>> the #!/path/to/python.bin and set the execution bit
>> with chmod a+x before you try)
>>
>>
>>  >   i tried using another user outside of zope .
>>  working very well(adding user to system)
> 
> Perhaps the other user is either root or it belongs to the root's
> groups.
> 
>>  owner of external method is root and set_user_id bit is set.
>>  but problem is when i run attached app it is not adding user 
> 
> set_user_id only works with C binary files. So, here you have to use
> sudo.
> 
> Regards,
> Josef
> 


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


Re: useradd command in Zope

2005-11-07 Thread Josef Meile
> su zope (or whoever your zope runs)
> ./yourmethod.py someuser somepass
> 
> You will see it fail (apart from the fact you need
> the #!/path/to/python.bin and set the execution bit
> with chmod a+x before you try)
> 
> 
>  >   i tried using another user outside of zope .
>  working very well(adding user to system)
Perhaps the other user is either root or it belongs to the root's
groups.

>  owner of external method is root and set_user_id bit is set.
>  but problem is when i run attached app it is not adding user 
set_user_id only works with C binary files. So, here you have to use
sudo.

Regards,
Josef

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


Re: OpenSSL in Python

2005-11-01 Thread Josef Meile
>>First, is the PYTHON OpenSSL C wrapper what I need to get running.
> 
> 
> I think that first you have to get OpenSSL running. Only then can you
> think about wrapping it.
I think Sybren is allright here. After installing openssl, pyopenssl
won't be a problem. So, if you want to install openssl, you could
download the binaries for windows (google for them) or you could compile
it from source, which is the best approach for this kind of libraries.
The last approach is out of the scope of this list as Sybren said. You 
should try first to find the answer in the openssl documentation or in
its official list. Then if you aren't able to compile it, then you have
to ask there.

If on the other hand, you have already installed openssl, but the
pyopenssl fails to run, then you can first see if pyopenssl has a
mailing list and ask there. On the contrary, you can ask here.

Regards,
Josef

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


Re: Double replace or single re.sub?

2005-10-26 Thread Josef Meile
Hi Iain,

 > Would this be a quicker/better way of doing it?
I don't know if this is faster, but it is for sure more elegant:

http://groups.google.ch/group/comp.lang.python/msg/67b8767c793fb8b0

I really like it because of its simplicity an easy use. (Thanks to
Fredrik Lundh for the script). However, I suggested it once to replace
the approach you suggested in a web application we have, but it was
rejected because the person, who benchmarked it, said that it was OK for
small strings, but for larger ones performance were an issue. Anyway,
for my own applications, performance isn't an issue, so, I use it some
times.

By the way, the benchmarking, from which I don't have any information,
was done in python 2.1.3, so, for sure you will get a better performance
with 2.4.

Regards,
Josef


Iain King wrote:
> I have some code that converts html into xhtml.  For example, convert
> all  tags into .  Right now I need to do to string.replace calls
> for every tag:
> 
> html = html.replace('','')
> html = html.replace('','')
> 
> I can change this to a single call to re.sub:
> 
> html = re.sub('<([/]*)i>', r'<\1em>', html)
> 

> 
> Iain
> 


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


Re: Send password over TCP connection

2005-10-10 Thread Josef Meile
> Anyone know of a simple ssl api in python :-)
Perhaps pow may help:
http://sourceforge.net/projects/pow

or pyopenssl:
http://pyopenssl.sourceforge.net/

Regards,
Josef

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


Re: testing a website from python

2005-09-21 Thread Josef Meile
Hi,

> I just want to test that a given website is up or not from a python 
> script.  I thought of using wget as an os command.  Any better ideas?
Here is how I did it:

import urllib2
import socket
def checkUrl(url, timeout=1):
   """Checks an url for a python version greater
  than 2.3.3.

  Note: For me isn't important the kind of
HTTP Error. If you want to know it,
then take a look at the existent
solutions like CMFLinkChecker and
see how they extract the code from
the error message.
   """
   error={'code':1, 'msg':'Success'}
   defTimeOut=socket.getdefaulttimeout()
   socket.setdefaulttimeout(timeout)
   try:
 urllib2.urlopen(url)
   except (urllib2.HTTPError, urllib2.URLError,
   socket.error, socket.sslerror):
 error['code']=-2
 error['msg']="The link: \"${link}\" couldn't be validated"
   except:
 socket.setdefaulttimeout(defTimeOut)
 raise

   socket.setdefaulttimeout(defTimeOut)
   return error

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


Re: OCR librarys

2005-09-13 Thread Josef Meile
Hi Timothy

> i'm looking for ocr librarys with reasonably free licensing and the 
> ablity to use python with them. c library's that i can call from python 
> are acceptable.
This thread may give you an start:
http://groups.google.ch/group/comp.lang.python/browse_frm/thread/362ac64a3c3aece2/

It mentioned how to call simpleocr, which according to the website:
http://www.simpleocr.com

it is Royalty Free. I haven't tried it, so, I can say how accurate it
is.

Regards,
Josef


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


Re: OCR librarys

2005-09-12 Thread Josef Meile
Hi Timothy,

first at all, sorry if you receive this message twice, but I sent a
message five hours ago and I don't see it on
mail.python.org/python-list.

Now at least the OP will receive it since I included it in a CC.

This thread may give you an start:
http://groups.google.ch/group/comp.lang.python/browse_frm/thread/362ac64a3c3aece2/

It mentioned how to call simpleocr, which according to the website:
http://www.simpleocr.com

it is Royalty Free. I haven't tried it, so, I can say how accurate it
is.

Regards,
Josef


Timothy Smith wrote:
> i'm looking for ocr librarys with reasonably free licensing and the 
> ablity to use python with them. c library's that i can call from python 
> are acceptable.
> so far all i have run into is voodoo and wild claims. i've tried gocr, 
> and it wasn't very impressive. i'm like to be able to ocr handwriting 
> but it's not a major requirment. anyone with any pointers or idea's i'm 
> all ears. i'd really not like to have to use somthing like imagemagick 
> and start from scratch.


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


Re: Zope, Python 2.4 pythonScripts import problem

2005-08-13 Thread Josef Meile
Hi,

> I have installed brand new platform - Zope-2-7-6, Python 2.4.1, Plone
> 2.0.5, OS Debian 1:3.3.6-2.

You may then ask in a zope or plone list. This is a python specific
list. But I will answer you any way.

> After import a old Plone site from the following platform
> Zope-2-7-4, Python 2.3.3, Plone 2.0.3 to the new one, I get error when
> I visit PuthonScript in the ZMI.
 > "invalid syntax (Script (Python), line 1)"
 >
 > There 2 are examples of 1 line:
 > from DateTime import DateTime
 > and
 > request = container.REQUEST
 >
 > There is no syntax error!
 >
 > When I just save this script in ZMI then error disappers :)

So, you are exporting the plone site, then importing it? I had once some
problem like that and the solution was to call an script that compiled
all python scripts again. I'm not sure if this solves your problem, but
you may look at the first script here:

http://www.zope.org/Members/goppelt/2-4-3Upgrade

> What is the reason???

As I said, you may ask in a zope or plone list for a better answer. My
best guess is that somewhere there is some old compiled version of your
script.

> p.s I have the same problem when I import to the same platform but with
> Python 2.4.0

I just have to warn you that some persons in the zope list are going to
tell you "Python 2.4 isn't a supported option for zope". So, you may use
it only for testing and not in a production environment.

Regards,
Josef

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


Re: functions without parentheses

2005-07-29 Thread Josef Meile
Steven D'Aprano wrote:
> On Fri, 29 Jul 2005 06:37:52 +, Bengt Richter wrote:
> 
> 
>>I suggested in a previous thread that one could support such a syntax by
>>supporting an invisible binary operator between two expressions, so that
>>examine "string" translates to examine.__invisbinop__("string") if
>>examine as an expression evaluates to an object that has a __invisbinop__ 
>>method.
> 
> 
> Why would you want to?
> 
My best guest is that the OP uses VB, where you can do that. I
personally hate this feature because it just makes me do a lot of
mistakes. ie: In VB you can do:

fooFunction fooParameter

but if you want to assign this to a variable you **must** use this:

fooVer = fooFunction(fooParaMeter)

I really get confused because I automatically use the braces.

Regards,
Josef

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


Re: Web Framework Reviews

2005-07-19 Thread Josef Meile
> "barely use python with it" and "can only be used with these two" are
> not entirely true.  Zope development can be done in a through-the-web
> (TTW) fashion or via filesystem products.  When developing TTW, it
> is true that you are somewhat limited in the amount of Python that
> you will be able to use.
I just want to add that ZPT and DTML are only intended for the
presentation and not for the logic, which can be done all using python.
However, as you may see, there are some zope developers that use it
wrong and do lots of logic stuff within dtml or zpt.

Regards,
Josef

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


Re: String Manipulation

2005-07-13 Thread Josef Meile
Hi,

> for punctuation in punctuations:
> line=line.replace(punctuation,'')
I would use maketrans or even a regex instead. However, If you care
about speed, it is well known that in some cases regex take more
time than multiple replaces. Even the maketrans could take more time
(I don't know; you may benchmark it -> homework)

Regards,
Josef

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


Re: Office COM automatisation - calling python from VBA

2005-06-25 Thread Josef Meile
Hi guy,

> I'll be using COM, and I could probably make an application that
> controls Outlook (externally). But I'd also like to have this
> functionality exposed in OL itself. So I guess I'll need to use VBA,
> but I don't really like VBA - relax, please, it's just an opinion.. ;)
> 
> So, ideally, I'd like to program as much as possible in python (I'm
> pretty new to that, too, btw), and only use VBA if needed - say, to
> call python objects/methods (+ wxGUI, please).
You could try to do an addin/addon for Word, Excel, and Outlook. You
don't need to code with VBA. Here you just need a language from where
you can access the microsoft interop assemblies (ie: C++ or C#;
IronPython maybe?)

I'm now working in an addon for Visio, but I'm not using python. I'm
using C#. The main idea is that we have an exe application, which
creates a COM object, with the first running instance of visio (if some
is found). Then, I use a class (event handler) to catch some events
comming from visio (this is in part documented at the msdn). I even
embebbed a windows form in Visio (it was an example in the sdk).

So, I think in theory, you could do the same with python. I have heard
you can somehow create COM objects there. You could also try the new
version of python for net: IronPython. I guess you can from there access
all the assemblies to interact with office:

Microsoft.Office.Interop.Excel,
Microsoft.Office.Interop.Word, and
Microsoft.Office.Interop.Outlook

A good start is to see the SDK documentation of each office product you
need at each developer center in www.msdn.microsoft.com

Good luck,
Josef

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


Re: how to export data from ZODB to text files

2005-06-10 Thread Josef Meile
Hi again,

> I thought also about Python script like
> 
> 
>  //connect to database 
>  >>> from ZODB import FileStorage, DB
>  >>> storage = FileStorage.FileStorage('Data.fs') 
>  >>> db = DB(storage)
>  >>> conn = db.open()
>  >>> dbroot = conn.root()
I just found an information that may be useful for you:

* ZODB for Python Programmers By Michael Pelletier:
   http://www.informit.com/articles/article.asp?p=23413&rl=1

* A Simple ZODB viewer in wxPython:
   http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/409012

The first link contains some useful examples and explanations. The
second one could help you to see how your zodb is organized. In the
links that Peter post, there is also an useful powerpoint presentation.

According to the first link, the ZODB is a persistent dictionary that
you can access like:

 >>> db = DB(storage)
 >>> connection = db.open()
 >>> root = connection.root()

If I'm not wrong, you could see what objects are in root of your zodb by
doing:

 >>> print root.keys()

After that you could get your plone site by doing:

 >>> ploneSite = root['ploneFolder']

Where if I'm not wrong, "ploneFolder" may be a key in the root
dictionary. Then if plone is like CMF, it must have a "portal_catalog"
instance in it, so, you can get it by:

 >>> catalog = getattr(ploneSite,'portal_catalog',None)

If at this point catalog = None, then you have to print the objects in
the plone site by doing:

 >>> print ploneSite.objectIds()

Once you find the catalog object, you could try the script I post before
from the command line.

I haven't tested this, but I hope it helps.

Regards,
Josef Meile

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


Re: how to export data from ZODB to text files

2005-06-10 Thread Josef Meile
Hi Lucasz,

> Thank you so much. I will ask our Plone administrator to test your
> script and I will write about result here.
You are wellcome. I think it is one of the easiest way of doing it.

> I thought also about Python script like
> 
> 
>  //connect to database 
>  >>> from ZODB import FileStorage, DB
>  >>> storage = FileStorage.FileStorage('Data.fs') 
>  >>> db = DB(storage)
>  >>> conn = db.open()
>  >>> dbroot = conn.root()
> 
>  //here should be interation for DB which saves attributes output in
> to file
> 
> 
> I'm not able to write the second part, but I think that this shouldn`t
> be a problem for experienced Python developer. 
> 
> How complex will be script like above?
I have to say it would be interesting to do something like that with
ZODB. Specially if you only have the Data.fs and don't have access to
the original Plone site. But I don't know how to do it. You may ask in
the ZODB list:

http://lists.zope.org/mailman/listinfo/zodb-dev

Regards,
Josef

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


Re: how to export data from ZODB to text files

2005-06-08 Thread Josef Meile
Hi Lukasz,

> Yes, I'm traing to escape from Zope-land, to be more clarify I want to
> migrate from Plone to PHP Application, which uses MySQL database
> engine, so I have to move all data from ZODB to MySQL. I suppose that
> python script shouldn`t be so complex. I need just iterate ZODB and
> write attributes like "Intro", "Body" of article to file for example.
> I need export Plone content hierarchy like
> 
> 
> Home
>|
>| - - - Folder 1 (Title, Intro, Body)
>|| - - - Article (Title, Intro, Body)
>|   
>| - - - Folder 2 (Title, Intro, Body)
I haven't done that with Plone, but with CMF, which is the base of
Plone. So, I guess it would be almost the same. You even don't need
the product Peter suggested; you could do a python script inside your
plone site, which searches all the objects you want and print it in
form of a pipe '|' delimited list. Then, once you define your tables
in mysql, you can import the data by copying the output of your
script and saving it into a text file. This is how my script looks like:

catalog=context.portal_catalog
jobs=catalog(
 {
   'meta_type': 'Internship'
 }
  )
OID = 1
for metaJob in jobs:
   jobData=catalog.getobject(metaJob.data_record_id_)
   print "%i|%s|%s|%s|%s|%s|%s|%s|" % \
 (OID,
  jobData.companyName,
  jobData.companyVision,
  jobData.description,
  jobData.positionOffered,
  jobData.jobProfile,
  jobData.contact,
  jobData.country)
   OID += 1

return printed

Off course, this only work assuming that your fields aren't files like
images or PDFs.

Regards,
Josef

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


Re: circular import Module

2005-06-08 Thread Josef Meile
>>Circular import does not work on module level, but you can
>>import the module in a method:
>>
>>file1.py:
>>import file2
>>
>>
>>
>>file2.py:
>># import file1 # Does not work!
>>def foo():
>>import file1 # Does work
> 
> 
> Cool idea !
> 
> It works on local namespaces, wich dont cause trouble to the whole program.
> 
> +1
Yes, I also think is a good solution. Once I needed to do something like
that and ended by writting a third module with the shared functions that
the two conflicting modules needed. At that time I already knew that one
could import modules from functions; however, I didn't come up with that
solution :-(

Regards,
Josef

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


Re: PHPParser pod Zope

2005-05-04 Thread Josef Meile
George Sakkis wrote:
> Bruno Desthuilliers wrote:
> 
>>JZ a Ãcrit :
>>
>>>Probuje zainstalowac modul php pod zope i tam napisali dziwna rzecz
> 
> ze
> 
>>>potrzebuje "PHP CGI program" a nie PHP CLI. Kompilacja php 5.0.4
> 
> pod
> 
>>>linuksem daje mi w wyniku mod_php + 5 plikow binarnych: pear, php,
>>>php-config, phpextdist, phpsize. Zas lektura skryptu do zope jest
> 
> nizbyt
> 
>>>jasna. Napisali:
>>>
>>
>>(snip)
>>DÃsolÃ, ce groupe est anglophone, il serait donc trÃs probablement
> 
> 
>>prÃfÃrable (en tous cas pour toi, et si bien sÃr tu espÃres une
> 
> rÃponse,
> 
>>mais sinon je ne vois pas l'intÃrÃt de poster ici...) de nous
> 
> renvoyer
> 
>>Ãa en anglais dans le texte !-)
>>
>>I-too-can-speak-weird-foreign-languages-ly'yrs
>>Bruno
> 
> 
> ÎÏÎ Î ÎÏÏÏÎÎÏÎ ÎÎÏÎÏÏÎÏÎ ÏÎÏÎÎ ÏÎ
> ÎÎÏÎÎÎÏ ÏÏ, Î ÎÎÎ ÎÎ ÏÎÏÎÎ
> ÎÏÏÏ Î ÎÏÏ Î ÎÏÎÎÏ ÎÏ
> ÎÏÎÏÎÎÎÏ ÏÏÎ ÎÎÏÏÎ...
> 
> If-this-is-all-greek-to-you-you're-right-ly'yrs
> George
I don't find this two replies funy :-(. I think it is impolite to make
fun of the OP. You could say: "The official language is english" or
something like that. And if somebody knows the language he speaks, then
a pointer to an appropiate list would be usefull.

Best regards,
Josef

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

Re: Zope3 and Plone

2005-04-18 Thread Josef Meile
Hi Mir,
you are asking in the wrong place. This is a python specific list. You
can find a suitable list here:
http://mail.zope.org/mailman/listinfo
Regards,
Josef
Mir Nazim wrote:
Hi,
I wanted to know what will happen to plone once Zope3 will be official
version. Is plone being ported to Zope3. I googled it but did not come
accross anything stating the plone's migration to zope3.
I am thinking to take up a project. plone is a candidate for it. should
i want to take  benifit of zope3 features too.
what should be done. 

Please comment
thanks

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


Re: check interpreter version before running script

2005-04-05 Thread Josef Meile
Is there a recommended or 'Best Practices' way of checking the version 
of python before running scripts? I have scripts that use the os.walk() 
feature (introduced in 2.3) and users running 2.2 who get errors. 
Instead of telling them, 'Upgrade you Python Install, I'd like to use 
sys.version or some other way of checking before running.

Whatever I do, I need it to work on Linux, Mac and Windows.
I thought of sys.version... but getting info out of it seems awkward to 
me. First 5 chars are '2.4.1' in string format have to split it up and 
convert it to ints to do proper checking, etc. It doesn't seem that 
sys.version was built with this type of usage in mind. So, what is the 
*best* most correct way to go about this?

What's about:
>>> import sys
>>> print sys.version_info
(2, 1, 3, 'final', 0)
Regards,
Josef
--
http://mail.python.org/mailman/listinfo/python-list


Re: IronPython 0.7 released!

2005-03-24 Thread Josef Meile
well that's nice, but I don't do blogs and certainly don't do M$ 
Passport logins which it seems the gotdotnet site requires.
I agree, even for reading the FAQ and the Readme you need a password :-(
--
http://mail.python.org/mailman/listinfo/python-list


Re: fastest postgresql module

2005-03-18 Thread Josef Meile
my only issue with psycopg, is last time i looked they had no win32 port?
Not completely true. Since long time ago there is a website with
unofficial psycopg binaries:
http://www.stickpeople.com/projects/python/psycopg/
Regards,
Josef
--
http://mail.python.org/mailman/listinfo/python-list


Re: Web framework

2005-03-14 Thread Josef Meile
Hi Joe,
Not wrong. I am aware of this, but it's not like that many development
tools can work through FTP or WebDav... Besides, how to have the
source code under source control if it's stuck in the ZODB?
I guess you are reffering to "Python Scripts" and "ZClasses", which
indeed are stuck in the ZODB. But in fact you can write external python
products for zope, which reside on your file system. What is stuck in
the ZODB would be the instances of those products.
Regards,
Josef
--
http://mail.python.org/mailman/listinfo/python-list


Re: capturing text from a GUI window

2005-03-10 Thread Josef Meile
Hi Earl,
Anyone know how to capture text from GUI output?  I need to process
information returned via a GUI window.
Earl
Assuming Windows, then these guys have an interesting tool:
   http://www.skesoft.com/textcatch.htm
It's not free, but you can try it before you buy it.
You will need COM to control it from Python.

This sounds like just what I need.  What is COM, and where do I get it? 
(I'm really a Linux guy. I don't ken the mysteries of Window very well.)
You may also try WATSUP - Windows Application Test System Using Python:
http://www.tizmoi.net/watsup/intro.html
Now the website seems to be down, but perhaps there is a mirror
somewhere.
Regards,
Josef
--
http://mail.python.org/mailman/listinfo/python-list


Re: split a directory string into a list

2005-02-28 Thread Josef Meile
The most obvious case where it wouldn't work would be for a UNC path name. 
Using the string split method gives two empty strings:


os.path.normpath(r'\\machine\share').split(os.path.sep)
['', '', 'machine', 'share']

whereas the splitpath function I proposed gives you:

splitpath(r'\\machine\share')
['', 'machine', 'share']
So to find out the type of path (relative, absolute, unc), you only have to 
consider the first element with my function but you have to look at the 
first two elements if you just naively split the string.
Thanks for the explanation. I forgot that you could do thinks like that
on windows.
Also a relative windows path with a drive letter doesn't get fully split:

os.path.normpath(r'c:dir\file').split(os.path.sep)
['c:dir', 'file']
splitpath(r'c:dir\file')
['c:', 'dir', 'file']
Again, I forgot it.
If you really are worried about speed (and are sure you aren't optimising 
prematurely), then you could combine some special case processing near the 
start of the string with a simple split of the remainder.
No, I'm not worried about speed. Actually, the original post wasn't
mine. I was just curious about your answer.
Regards,
Josef
--
http://mail.python.org/mailman/listinfo/python-list


Re: split a directory string into a list

2005-02-25 Thread Josef Meile
Hi Duncan,
This should work reasonably reliably on Windows and Unix:

somestring = '/foo/bar/beer/sex/cigarettes/drugs/alcohol/'
os.path.normpath(somestring).split(os.path.sep)
['', 'foo', 'bar', 'beer', 'sex', 'cigarettes', 'drugs', 'alcohol']
However a better solution is probably to call os.path.split repeatedly 
until it won't split anything more:


somestring = r'C:\foo\bar\beer'
def splitpath(p):
res = []
while 1:
p, file = os.path.split(p)
if not file:
break
res.append(file)
res.append(p)
res.reverse()
return res

splitpath(somestring)
['C:\\', 'foo', 'bar', 'beer']
splitpath('foo/bar')
['', 'foo', 'bar']
The first component is an empty string for relative paths, a drive letter 
or \ for absolute Windows paths, \\ for UNC paths, / for unix absolute 
paths.
I don't understand why the second approach is better than the first
one. In my opinion it is the contrary:
On the first approach, you only scan the string twice:
when you do "os.path.normpath(somestring)" and finally when splitting
the string. On the other hand, the second approach goes through the
string several times, when doing the os.path.split. Finally when doing
the res.reverse(). Or am I wrong? I also saw you said:
"This should work ***reasonably*** reliably on Windows and Unix". Are
there any cases when it does not work?
Regards,
Josef
--
http://mail.python.org/mailman/listinfo/python-list


Re: - E02 - Support for MinGW Open Source Compiler

2005-02-18 Thread Josef Meile
It looks like here the only worth words are yours. Didn't
you close this thread?
I will refresh your mind with your own unpolite way:
"""
Ilias Lazaridis wrote:
[...]
closing thread
http://groups-beta.google.com/group/comp.lang.python/msg/f2ae9cdbe16676d1
"""
Anyway, I will add some comments:
The defined "extra effort" is the effort to provide the patches for the
main source-code base?
If you can send me an email of how to do this, I would take this effort.
Good for you.
of course I must first know, that the python-team would accept those
patches (technical applicability provided).
There is no guaranty. Did you forget the reply from Tim Peters:
> [...] A problem is that a
> patch won't get reviewed unless a volunteer does a review, and we've
> got an increasing backlog of unreviewed patches because of that.  The
> most effective way for a person P to get their patch reviewed now is
> for P to volunteer to review 5 other patches first.  There are a few
> Python developers who have promised, in return, to review P's patch
> then.
So, you will have to review some patches first.
>Ilias> Now, can you please tell me the process I have to follow to
>Ilias> suggest the following (to the PSF or to the programmers or to
>Ilias> the decision takers),possibly to get at least a vote on it:
>Tim> No such thing will happen -- forget that.  For MinGW to be
>Tim> supported forever, it's necessary and sufficient that a specific
>Tim> person volunteer to support MinGW forever.  If that person goes
>Tim> away, so does the support they provided; it's the same story for
>Tim> Cygwin, and even for Linux and native Windows.
So, it is not just making the patch. You will have to compromise to
support it and not just go away.
Regards,
Josef
--
http://mail.python.org/mailman/listinfo/python-list


Re: Testing web applications

2005-02-11 Thread Josef Meile
Zope + Formulator is a nice combination to validating and designing
forms and add some functionality. If you want a more complicated content
management framework, then you can additionally install plain CMF or
Plone, which is based on CMF. There is also something called Silva, but
it doesn't have many products as the other two; however, it is also
nice.
I have heard also about CherryPy, Quixote, Twisted Matrix and Webware,
but I haven't tested them. Once I saw that somebody posted a link, which
compares some of them, but I lost that thread :-(
I found it:
http://www.cmsmatrix.org/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Testing web applications

2005-02-11 Thread Josef Meile
Hi Achim,
I'm looking for frameworks to make testing web applications - i.e. 
parsing and filling out forms - easier. I found Puffin, which looks good 
but not very usable in the current state. I know that I once read about 
other nice frameworks, but could not find one via google. Any hints?
Zope + Formulator is a nice combination to validating and designing
forms and add some functionality. If you want a more complicated content
management framework, then you can additionally install plain CMF or
Plone, which is based on CMF. There is also something called Silva, but
it doesn't have many products as the other two; however, it is also
nice.
I have heard also about CherryPy, Quixote, Twisted Matrix and Webware,
but I haven't tested them. Once I saw that somebody posted a link, which
compares some of them, but I lost that thread :-(
Regards,
Josef
--
http://mail.python.org/mailman/listinfo/python-list


Re: Curses on Windows

2005-02-08 Thread Josef Meile
Hi Peter,
Last November I posted a message asking for advice on using simple
screen handling techniques under Windows.  Since then I have been
occupied with family / job /Christmas /living  and trying to
understand curses under linux (it works, seems very complex, sure I'm
missing something ...).  Only now am I returning to my original query.
One reply (in fact the only reply - thanks Tim Golden) suggested I
look at http://flangy.com/dev/python/curses/
There was a similar thread last month. See my reply for more links. I
haven't tested them, but they may help.
how to ncurses on win32 platform:
http://mail.python.org/pipermail/python-list/2005-January/262511.html
Just tried that and got the message
"You don't have permission to access
/dev/python/curses/files/wcurses-0.1-py2.4.zip on this server."
Yes, I also have problems.
Regards,
Josef
--
http://mail.python.org/mailman/listinfo/python-list


Re: Possibly OT: Controlling winamp with Python

2005-02-04 Thread Josef Meile
Hi Brent,
Brent W. Hughes wrote:
The Python program won't decide whether a commercial is playing, I will.  At 
that point, I will run my program which will press mute, wait 20 seconds, 
and then press mute again.

Actually, I could leave the program running but minimized to the task bar. 
When I hear the advertisement, I just click on the program in the task bar. 
It knows what to do from there.
You don't need python for this. You can use auto-it to achieve the same
thing. You can download it at:
http://www.hiddensoft.com/AutoIt/
It is easy to program and it works nicely. There is also some similar
thing for python. Perhaps a litle bit more complicated (I haven't
tested it):
WATSUP - Windows Application Test System Using Python
http://www.tizmoi.net/watsup/intro.html
Regards,
Josef
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.4 binaries for accessing PostgreSQL from Windows?

2005-02-04 Thread Josef Meile
Hi Frank
I tried the psycopg site, but it does not seem to have binaries at all.
Does anyone know if either of these will be available in binary form
for Python 2.4 on Windows?
For psycopg, there is a site with binaries for windows:
http://www.stickpeople.com/projects/python/psycopg/
Regards,
Josef
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to ncurses on win32 platform

2005-01-26 Thread Josef Meile
Hi Brane,
I was wondering about the same thing some days
ago. I found the following alternatives:
* Curses for Windows for Python (It was previously
mentioned on a follow-up. there are some missing
features):
http://flangy.com/dev/python/curses/
* PDCurses (It looks promissing):
http://pdcurses.sourceforge.net/
* The Console Module:
http://www.effbot.org/zone/console-handbook.htm
* Windows CONsole I/O for Python:
http://newcenturycomputers.net/projects/wconio.html
Please note that I haven't tested any of the mentioned
packages, so, I don't know if they are really a good
replacement for ncurses, so, it's up-to-you to test
them.
Regards,
Josef
--
http://mail.python.org/mailman/listinfo/python-list