Re: Using SimpleXMLRPCServer in a Windows Service

2006-11-28 Thread Rudy Schockaert
I found the problem.
Actually both pieces of code work now. The problem was that when I run
the SimpleXMLRPCService in a Windows Service, the STDERR needs to be
redirected to a real file. I guess some kind of buffer overflow occurs
when you don't do this.

I added the following lines:

snip
def SvcStop(self):
sys.stdout = self.stdout
sys.stderr = self.stderr
.


def SvcDoRun(self):
self.stdout = sys.stdout
self.stderr = sys.stderr
sys.stdout = file(c:/temp/my.log, a+, 0)
sys.stderr = sys.stderr

/snip


On11/25/06, Gabriel Genellina [EMAIL PROTECTED] wrote:
 At Thursday 23/11/2006 06:52, Rudy Schockaert wrote:

 After some Googling I found a post of someone who wanted to do exactly
 as what I want to do now.
 There is however a problem in his code that makes the service fails
 after the first connection. I slightly modified his code and now I can
 run the service longer before I run into trouble.
 I then tried making the SimpleXMLRPCServer multi-threaded, hoping the
 problem would disappear, but no avail.
 The code is as follows:
 The commented part in the while loop is from the original code.

 The original (commented-out) code should be fine. You have to wait
 for 2 events: the service stop signal, or an incoming connection.
 Anyway, you always have to catch exceptions; override handle_error at least.

 Another approach (not involving events) would be to set a (not so
 big) timeout on the socket, and test for self.stop_requested on each 
 iteration.

  server = ThreadedSimpleXMLRPCServer((, 8080))
  object = OBJECT()
  server.register_instance(object)
  self.socket = server.socket
 
  while 1:
  #win32file.WSAEventSelect(server,
 self.hSockEvent,win32file.FD_ACCEPT)
  #rc =
 win32event.WaitForMultipleObjects((self.hWaitStop,self.hSockEvent), 0,
 win32event.INFINITE)
  #if rc == win32event.WAIT_OBJECT_0:
  #break
  #else:
  #server.handle_request()
  #win32file.WSAEventSelect(server,self.hSockEvent, 0)
  ##server.serve_forever()  ## Works, but breaks the


 --
 Gabriel Genellina
 Softlab SRL

 __
 Correo Yahoo!
 Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
 ¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar


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


Using SimpleXMLRPCServer in a Windows Service

2006-11-23 Thread Rudy Schockaert
After some Googling I found a post of someone who wanted to do exactly
as what I want to do now.
There is however a problem in his code that makes the service fails
after the first connection. I slightly modified his code and now I can
run the service longer before I run into trouble.
I then tried making the SimpleXMLRPCServer multi-threaded, hoping the
problem would disappear, but no avail.
The code is as follows:
The commented part in the while loop is from the original code.
CODE


## XML-RPC Service
import sys
import win32serviceutil
import win32service
import win32event
import win32evtlogutil
import win32file
import servicemanager
import SimpleXMLRPCServer
import SocketServer
import select

class OBJECT:
def hello(self, text):
return Hello World (%s) % text

class ThreadedSimpleXMLRPCServer(SocketServer.ThreadingMixIn,
SimpleXMLRPCServer.SimpleXMLRPCServer): pass

class XMLRPCSERVICE(win32serviceutil.ServiceFramework):
_svc_name_ = XMLRPCSERVICE
_svc_display_name_ = XMLRPCSERVICE
_svc_description_ = XMLRPCSERVICE

def __init__(self, args):
win32evtlogutil.AddSourceToRegistry(self._svc_display_name_,
sys.executable, Application)
win32serviceutil.ServiceFramework.__init__(self, args)

self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
self.hSockEvent = win32event.CreateEvent(None, 0, 0, None)
self.stop_requested = 0

def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
self.stop_requested = 1
win32event.SetEvent(self.hWaitStop)

def SvcDoRun(self):
## Write a started event
servicemanager.LogMsg(
servicemanager.EVENTLOG_INFORMATION_TYPE,
servicemanager.PYS_SERVICE_STARTED,
(self._svc_name_, ' (%s)' % self._svc_name_))

server = ThreadedSimpleXMLRPCServer((, 8080))
object = OBJECT()
server.register_instance(object)
self.socket = server.socket

while 1:
r, w, x = select.select([self.socket],[],[],10)
if r == [self.socket]:
server.handle_request()
if self.stop_requested:
self.socket.close()
break


#win32file.WSAEventSelect(server,
self.hSockEvent,win32file.FD_ACCEPT)
#rc =
win32event.WaitForMultipleObjects((self.hWaitStop,self.hSockEvent), 0,
win32event.INFINITE)
#if rc == win32event.WAIT_OBJECT_0:
#break
#else:
#server.handle_request()
#win32file.WSAEventSelect(server,self.hSockEvent, 0)
##server.serve_forever()  ## Works, but breaks the

## Write a stopped event
win32evtlogutil.ReportEvent(self._svc_name_,
servicemanager.PYS_SERVICE_STOPPED,0,
servicemanager.EVENTLOG_INFORMATION_TYPE,
(self._svc_name_,))

if __name__ == '__main__':
win32serviceutil.HandleCommandLine(XMLRPCSERVICE)


/CODE

I tested with the following:

CODE

import xmlrpclib
import time

server = xmlrpclib.ServerProxy(http://localhost:8080;)
for i in range(100):
print server.hello(%d % i)
time.sleep(1)

/CODE

The loop ends with the following error:

OUTPUT
Hello World (0)
...
Hello World (44)
Traceback (most recent call last):
  File C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py,
line 310, in RunScript
exec codeObject in __main__.__dict__
  File C:\DATA\TestSoap.py, line 6, in ?
print server.hello(%d % i)
  File C:\Python24\lib\xmlrpclib.py, line 1096, in __call__
return self.__send(self.__name, args)
  File C:\Python24\lib\xmlrpclib.py, line 1383, in __request
verbose=self.__verbose
  File C:\Python24\lib\xmlrpclib.py, line 1137, in request
headers
ProtocolError: ProtocolError for localhost:8080/RPC2: -1 
/OUTPUT

Can someone help me in creating a windows service that allows me to
handle XMLRPC request?

Thanks in advance,

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


Problem binding to Active Directory

2006-03-24 Thread Rudy Schockaert
I use the following script:from win32com.client import GetObject, Dispatchuser=''password=''default_naming_context = GetObject(LDAP://rootDSE).Get(defaultNamingContext)ad = GetObject(LDAP:).OpenDSObject(LDAP://%s % default_naming_context, user, password, 1 + 512)
If user  password contain a correct value the script works. According to the ADSI documentation, replacing user and password with NULLstrings should use the credentials of the currently logged on user. In _vbscript_ this works, but in Python I get different errormessages depending on what I pass as value to these parameters.
Can somebody tell me how to do this? How can I pass a NULL-string hereThanks in advance,Rudy
-- 
http://mail.python.org/mailman/listinfo/python-list

CSV module and UNICODE

2006-02-23 Thread Rudy Schockaert
I'm having problems writing unicode to a csv file.I use the following code:-import codecsimport csvcsvfile = csv.writer(codecs.open('filename.csv','w+','utf-8'))a = u'\xc9'
csvfile.writerow([a,a])
-It fails with the message: UnicodeEncodeError: 'ascii' codec can't encode .Is there any way I can solve this.PEP 305
What about Unicode?  Is it sufficient to pass a file object gotten
from codecs.open()?  For example:
csvreader = csv.reader(codecs.open(some.csv, r, cp1252))csvwriter = csv.writer(codecs.open(some.csv, w, utf-8))

In the first example, text would be assumed to be encoded as cp1252.
Should the system be aggressive in converting to Unicode or should
Unicode strings only be returned if necessary?
In the second example, the file will take care of automatically
encoding Unicode strings as utf-8 before writing to disk.
Note: As of this writing, the csv module doesn't handle Unicode
data.
/PEP 305PEP 305 was last modified on Wed, 11 Aug 2004 Has something changed in between?


Thanks in advance,Rudy
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: CSV module and UNICODE

2006-02-23 Thread Rudy Schockaert
Forgot to mention that I work on Windows XP and Windows 2003.On 2/23/06, Rudy Schockaert [EMAIL PROTECTED]
 wrote:I'm having problems writing unicode to a csv file.I use the following code:
-import codecsimport csvcsvfile = csv.writer(codecs.open('filename.csv','w+','utf-8'))a = u'\xc9'
csvfile.writerow([a,a])
-It fails with the message: UnicodeEncodeError: 'ascii' codec can't encode .Is there any way I can solve this.PEP 305
What about Unicode?  Is it sufficient to pass a file object gotten
from codecs.open()?  For example:
csvreader = csv.reader(codecs.open(some.csv, r, cp1252))csvwriter = csv.writer(codecs.open(some.csv, w, utf-8))

In the first example, text would be assumed to be encoded as cp1252.
Should the system be aggressive in converting to Unicode or should
Unicode strings only be returned if necessary?
In the second example, the file will take care of automatically
encoding Unicode strings as utf-8 before writing to disk.
Note: As of this writing, the csv module doesn't handle Unicode
data.
/PEP 305PEP 305 was last modified on 
Wed, 11 Aug 2004 Has something changed in between?


Thanks in advance,Rudy

-- It is not economical to go to bed early to save the candles if the result is twins. - Chinese Proverb 
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: CSV module and UNICODE

2006-02-23 Thread Rudy Schockaert
Thanks a lot Skip. Sure that this will help.

Learned two things: how to do it and to look at the docs for 2.5 also.

These samples are not in the 2.4.2 reference guide.

RudyOn 2/24/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
Rudy I'm having problems writing unicode to a csv file.Rudy I use the following code:...Have you tried the example UnicodeReader and UnicodeWriter classes in themodule documentation:
http://www.python.org/dev/doc/devel/lib/node631.htmlWhile the csv module is 8-bit clean it knows nothing about Unicode, so yourUnicode data has to be encoded before it hits the csv module code.Your
code is expecting the Unicode to go through the csv module and be encoded toutf-8 downstream in the by the eventual file object.If there are people reading this who would like to tackle something forPython 
2.5, I am sure a patch that Unicodifies the csv module would bewelcome.Skip-- It is not economical to go to bed early to save the candles if the result is twins. - Chinese Proverb 

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

Re: Seaching Active Directory via ADO

2006-02-17 Thread Rudy Schockaert
You could also use the excellent active_directory module of Tim Golden (http://tgolden.sc.sabren.com/python/active_directory.html)Your query would then become:
import active_directoryfor person in active_directory.search (objectClass='user',name='Roger*'):  print person.displayName
On 2/17/06, Roger Upole [EMAIL PROTECTED] wrote:
Here's a short example that uses ADO to search for auser by wildcard.import win32com.clientc = win32com.client.Dispatch(ADODB.Connection)c.Open(Provider=ADSDSOObject)rs,rc=
c.Execute(SELECT adspath, title, nameFrom 'LDAP://DC=yourdomain, DC=COM'where objectClass='user' and name='Roger*')while not rs.EOF:for f in rs.Fields
:print f.Name, f.Valuers.MoveNext()hthRogerLittlePython [EMAIL PROTECTED] wrote in messagenews:[EMAIL PROTECTED]
... Thanks but I was looking more for ADO com object than ADSI or ldap. For some strange reason it is very hard to locate any working scripts that use ADOto connect and search AD. Is there an issue with ADO and python
 when connecting to AD? I have try to build one myself with no luck. I think my problem is with adodb.command calls. Thanks for your response. alex23 
[EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]  Heya,   There are a couple of examples on the O'Reilly site. These two are
  taken from 'Active Directory Cookbook', the first uses a COM object  while the second uses a native LDAP module:  
http://www.rallenhome.com/books/adcookbook/src/18.6-rootdse_python_com.py.tx t http://www.rallenhome.com/books/adcookbook/src/18.6-rootdse_python_ldap.py.t
 xt   This might give you a start.   - alex23 == Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups= East and West-Coast Server Farms - Total Privacy via Encryption =--
http://mail.python.org/mailman/listinfo/python-list-- It is not economical to go to bed early to save the candles if the result is twins. - Chinese Proverb 
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Difference between ActivePython and Python.org

2005-12-14 Thread Rudy Schockaert
Activestate just bundles teh standard python with the pywin32 module of Mark Hammond and provides the documentation in a handy one-file CHM format.Besides that there is no difference as far as I know.
On 12/14/05, S.Chang [EMAIL PROTECTED] wrote:
Hi,Anyone knows the difference(s) between the Python binaries fromActiveState and Python.org?Cheerssc--
http://mail.python.org/mailman/listinfo/python-list-- You don't stop laughing because you grow old. You grow old because you stop laughing.-- Michael Pritchard
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: AJAX = APAX? Or: is there support for python in browsers?

2005-11-15 Thread Rudy Schockaert
Indeed, and a huge success in the TurboGears project. Check it out.On 11/15/05, Larry Bates [EMAIL PROTECTED]
 wrote:Roger Erens wrote: Hello, I remember that the first time I read about Python as a programming
 language was when reading the W3C's HTML 4.01 specification a few years ago. In the section on objects, images and applets (http://www.w3.org/TR/html401/struct/objects.html
) an example was given like POBJECT classid="" href="http://www.miamachina.it/analogclock.py">http://www.miamachina.it/analogclock.py PARAM name=height value=40 valuetype=data
 PARAM name=width value=40 valuetype=data This user agent cannot render Python applications. /OBJECT It's also in the XHTML2.0 specification. Now, is this just a theoretical
 example? Or is there a browser that _does_ support python scripts? Or do we have to place our bets on the Mozilla 1.9 milestone with hard work being done by Mark Hammond? I'm asking because of all the AJAX hype going on. I'd like rather not
 delve too deep into _javascript_ and use Python instead. Any insights to be shared? Cheers, RogerTake a look at this kit:http://www.mochikit.com/
It seems that this is a python programmer that has created _javascript_functions that feel a lot like Python.May just be a transitionalway to go, but I thought it was interesting anyway.
-Larry Bates--http://mail.python.org/mailman/listinfo/python-list-- You don't stop laughing because you grow old. You grow old because you stop laughing.-- Michael Pritchard
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Perl's documentation come of age

2005-09-21 Thread Rudy Schockaert
snip• Do think clearly before writing. 
/snipYou should start thinking before you write something. Do you really think anyone takes you serious the way you talk?I haven't seen anything constructive yet from your side. You always have to comment, why don't you start writing documentation yourself if it bothers you so much. Write it the way you think it should be written and show the rest of the community you are capable of doing anything else but fucking qwasting others peoples time.
Rudy
-- 
http://mail.python.org/mailman/listinfo/python-list