[issue18620] multiprocessing page leaves out important part of Pool example
New submission from Chris Curvey: on http://docs.python.org/2/library/multiprocessing.html, there is a bit about how to use a Pool properly, which looks like this pool = Pool(processes=4) # start 4 worker processes result = pool.apply_async(f, [10]) What this neglects to mention is that only one process will get any of the work. If you really want four processes in the pool to work, you have to call apply_async four times. For example: results = [] pool = Pool(processes=4) for i in xrange(4): results.append(pool.apply_async(f, [10])) hat tip to http://stackoverflow.com/questions/12483512/python-multiprocessing-apply-async-only-uses-one-process -- assignee: docs@python components: Documentation messages: 194115 nosy: Chris.Curvey, docs@python priority: normal severity: normal status: open title: multiprocessing page leaves out important part of Pool example type: enhancement ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue18620 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
c-based version of pyPdf?
I'm a long-time user of the pyPdf library, but now I'm having to work with bigger volumes -- larger PDFs and thousands of them at a shot. So performance is starting to become a problem. Does anyone know of an analogue to pyPdf that is faster? (Maybe something based on C with Python bindings?) -- http://mail.python.org/mailman/listinfo/python-list
subprocess.check_call() fails ... but only on my production machine
I've got a python program running on windows that executes a command- line script. The command being executed is: print cmd C:\Program Files\ImageMagick-6.6.1-Q16\convert.exe -density 72x72 c: \temp\choicepoint 2010-01 Stmt_p1.pdf -quiet -region (612.0x70.0+0+0 - blur 0x3) -region (612.0x709.0+0+83.0 -blur 0x3) \\fs4\w \13\132651\BILLING_PROOFS\132651_choicepoint 2010-01 Stmt_p1_r1.pdf subprocess.check_call(cmd, shell=True) if I run the command thru python subprocess.check_call() on my Windows 7 (development) machine, it works fine. if I run the command in a command in a command window on my windows 2007 server (production) machine, it works fine. if I run the command thru python subprocess.check_call() on my Windows 2007 server (production) machine, it fails. I'm running both the Python script and the command window as the same user. Can anyone give me a hint as to what might be happening...or a way to get more information about what the error is? (All I get is Command returned non-zero exit status 1) -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess.check_call() fails ... but only on my production machine
just a note that the Windows 2007 Server is actually a Windows 2008 Server (despite the fact that Control Panel-System tells me it's 2007...but that's a different discussion) -- http://mail.python.org/mailman/listinfo/python-list
sorting ascending/descending with operator.attrgetter
I must be having a brain cramp. Given a list of objects, how can I sort the list on one attribute in descending order, then sort within each group in ascending order on another attribute. For example: class Foo: def __init__(self, a, b, c): self.a = a self.b = b self.c = c I can do allmyfoos.sort(operator.attrgetter('a','b')) to sort ascending on both attributes, but how could i sort by a, descending, then b, ascending)? -- http://mail.python.org/mailman/listinfo/python-list
find text location (in pixels) using python (pyPdf)
Has anyone ever tried to find the pixel (or point) location of text in a PDF using Python? I've been using the pyPdf libraries for other things, and it seems to me that if I can find the bounding box for text, I should be able to calculate the location. What I want to do is take a PDF of one of our vendor invoices and blur everything in it except the block that's related to a single customer. So if I have an invoice that looks like: Alfred Annoying 123 Elm St Somewhere, NJ $100 Barbie Bonehead 456 Pine St Elsewhere, NJ $125 Charlie Clueless 789 Beech St. Everywhere, NJ $150 I want to show Barbie just her section of the invoice (with the header intact, so that she can tell it's a real invoice) but with Alfred and Charlie's information blurred out. I was going to convert the PDF to a JPG or PNG and do the blurring with ImageMagick/PythonMagick. But that requires me to know the pixel location of the regions that I want blurred and left alone. I'm also open to other ideas if I'm going about this the hard way -- http://mail.python.org/mailman/listinfo/python-list
Re: PyPDF and print restrictions
On Jul 27, 4:16 pm, Chris Curvey ccur...@gmail.com wrote: Has anyone out there been able to enforce print restrictions on a PDF document by usingPyPDF? The documentation for encrypt states: # @param user_pwd The user password, which allows for opening and reading # the PDF file with the restrictions provided. But there is no parameter for providing a restriction, and I can't find a reference to any kind of restriction besides this comment in the docs. Thanks in advance! I found some (I think old-ish) documentation on encryption and permissions (of course, I've lost the link). I think there are additional permissions that have been implemented since the doc that I found, but this patch works for me. Index: C:/Documents and Settings/ccurvey/PyPDF/pyPdf/pdf.py === --- C:/Documents and Settings/ccurvey/PyPDF/pyPdf/pdf.py(revision 1) +++ C:/Documents and Settings/ccurvey/PyPDF/pyPdf/pdf.py(revision 2) @@ -118,7 +118,10 @@ # @param use_128bit Boolean argument as to whether to use 128bit # encryption. When false, 40bit encryption will be used. By default, this # flag is on. -def encrypt(self, user_pwd, owner_pwd = None, use_128bit = True): +# @param perm_mask bitmask of the permissions that should be granted. +# Defaults to -1, which is everything permitted +def encrypt(self, user_pwd, owner_pwd = None, use_128bit = True, +perm_mask=-1): import md5, time, random if owner_pwd == None: owner_pwd = user_pwd @@ -130,8 +133,8 @@ V = 1 rev = 2 keylen = 40 / 8 -# permit everything: -P = -1 + +P = perm_mask O = ByteStringObject(_alg33(owner_pwd, user_pwd, rev, keylen)) ID_1 = md5.new(repr(time.time())).digest() ID_2 = md5.new(repr(random.random())).digest() Index: C:/Documents and Settings/ccurvey/PyPDF/pyPdf/__init__.py === --- C:/Documents and Settings/ccurvey/PyPDF/pyPdf/__init__.py (revision 1) +++ C:/Documents and Settings/ccurvey/PyPDF/pyPdf/__init__.py (revision 2) @@ -1,2 +1,11 @@ from pdf import PdfFileReader, PdfFileWriter + +PERM_NONE = 0 +PERM_PRINT = 2 +PERM_MODIFY = 4 +PERM_COPY_TEXT = 8 +PERM_ANNOTATE = 16 + +PERM_ALL = PERM_PRINT | PERM_MODIFY | PERM_COPY_TEXT | PERM_ANNOTATE + __all__ = [pdf] -- http://mail.python.org/mailman/listinfo/python-list
PyPDF and print restrictions
Has anyone out there been able to enforce print restrictions on a PDF document by using PyPDF? The documentation for encrypt states: # @param user_pwd The user password, which allows for opening and reading # the PDF file with the restrictions provided. But there is no parameter for providing a restriction, and I can't find a reference to any kind of restriction besides this comment in the docs. Thanks in advance! -- http://mail.python.org/mailman/listinfo/python-list
Re: capture stdout and stderror from within a Windows Service?
On May 14, 11:57 am, Chris Curvey ccur...@gmail.com wrote: I'm trying to get this invocation right, and it is escaping me. How can I capture the stdout and stderr if I launch a subprocess using subprocess.check_call()? The twist here is that the call is running from within a Windows service. I've tried: check_call(mycmd.exe, stdout=subprocess.PIPE) [raises an exception An integer is required] check_call(mycmd.exe, stdout=file(c:\\temp\\foobar.txt, w)) [raises an exception An integer is required] Ahhh, Blake put me on the right track. If you want any of the streams, you have to supply values for all of them, like so: p = subprocess.Popen(step, shell=True stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE) (stdout, stderr) = p.communicate() and, incidentally, it appears that you have to use UNC paths in your Popen call -- drive letters won't work. so dir \\foobar\myshare\mydir will work, but dir j:\mydir will not. Many thanks for all your assistance. -- http://mail.python.org/mailman/listinfo/python-list
capture stdout and stderror from within a Windows Service?
I'm trying to get this invocation right, and it is escaping me. How can I capture the stdout and stderr if I launch a subprocess using subprocess.check_call()? The twist here is that the call is running from within a Windows service. I've tried: check_call(mycmd.exe, stdout=subprocess.PIPE) [raises an exception An integer is required] check_call(mycmd.exe, stdout=file(c:\\temp\\foobar.txt, w)) [raises an exception An integer is required] -- http://mail.python.org/mailman/listinfo/python-list
Re: how to make a python windows service know it's own identity
On Feb 1, 2:10 pm, Larry Bates [EMAIL PROTECTED] wrote: Chris Curvey wrote: Hi all, I have used the win32com libraries to set up a service called MyService under Windows. So far, so good. Now I need to run multiple copies of the service on the same machine. I also have that working. For monitoring and logging, I'd like each instance of the service to know it's own identity (MyService1, MyService2, etc.) But I can't quite seem to grasp how to do this. In the code below, the command line parameter -i gives the service an identity, but how do I get the service to understand it's identity when it is started? Many thanks! class MyService(win32serviceutil.ServiceFramework): NT Service. _svc_name_ = MyService _svc_display_name_ = My Service _id_ = '' def SvcDoRun(self): provider = MyServiceClass(identifier=self._id_) provider.start() # now, block until our event is set... win32event.WaitForSingleObject(self.stop_event, win32event.INFINITE) # __init__ and SvcStop snipped ### if __name__ == '__main__': import optparse parser = optparse.OptionParser() parser.add_option(-i, --identifier, dest=identifier) (opts, args) = parser.parse_args() if opts.number is not None: MyService._svc_name_ += opts.identifier MyService._svc_display_name_ += opts.identifier MyService._provider_id_ = opts.identifier win32serviceutil.HandleCommandLine(MyService, customInstallOptions=i:) What is your use case for this? Why not make a single server process multiple providers (store them in a list or other container)? -Larry Bates The use case is that I have a queue of jobs that need to run. My service connects to a central distributor server, which hands out jobs to complete. I'd like to be able to run multiple copies of the distributed service so that I can make the most use of each machine where they run. (I'm not certain of the thread safety of some of the libraries I'm using, so I'm leery of going the multi-threaded route) Anyway, when my service gets a job to process, I'd like to know which copy of the service is working on which job. So I want my log messages to look like this: Job 123: Host: alpha Service: MyService A Job 124: Host: alpha Service: MyService B Job 124: Host: beta Service: MyService C Is that clear, or have I muddied the waters? -- http://mail.python.org/mailman/listinfo/python-list
how to make a python windows service know it's own identity
Hi all, I have used the win32com libraries to set up a service called MyService under Windows. So far, so good. Now I need to run multiple copies of the service on the same machine. I also have that working. For monitoring and logging, I'd like each instance of the service to know it's own identity (MyService1, MyService2, etc.) But I can't quite seem to grasp how to do this. In the code below, the command line parameter -i gives the service an identity, but how do I get the service to understand it's identity when it is started? Many thanks! class MyService(win32serviceutil.ServiceFramework): NT Service. _svc_name_ = MyService _svc_display_name_ = My Service _id_ = '' def SvcDoRun(self): provider = MyServiceClass(identifier=self._id_) provider.start() # now, block until our event is set... win32event.WaitForSingleObject(self.stop_event, win32event.INFINITE) # __init__ and SvcStop snipped ### if __name__ == '__main__': import optparse parser = optparse.OptionParser() parser.add_option(-i, --identifier, dest=identifier) (opts, args) = parser.parse_args() if opts.number is not None: MyService._svc_name_ += opts.identifier MyService._svc_display_name_ += opts.identifier MyService._provider_id_ = opts.identifier win32serviceutil.HandleCommandLine(MyService, customInstallOptions=i:) -- http://mail.python.org/mailman/listinfo/python-list
ISAPI filter
Hi all, I'm trying to write an ISAPI filter in Python, using the examples that come in the isapi directory of the win32com package. The installation program itself runs fine, but when I examine the properties of my web server, my filter has a big red down arrow next to it. But I can't seem to figure out where I should be looking to find the trouble. If anyone can point me to the right place (or see an obvious error in the code below), I'd appreciate it. -Chris from isapi import isapicon, threaded_extension from isapi.simple import SimpleFilter import sys import traceback import urllib ## class ImageProtectFilter(SimpleFilter): Image Protection Filter filter_flags = isapicon.SF_NOTIFY_AUTHENTICATION def HttpFilterProc(self, fc): return isapicon.SF_STATUS_REQ_HANDLED_NOTIFICATION # # The entry points for the ISAPI filter. def __FilterFactory__(): return ImageProtectFilter() if __name__=='__main__': # If run from the command-line, install ourselves. from isapi.install import * params = ISAPIParameters() # Setup all filters - these are global to the site. params.Filters = [ FilterParameters(Name=ImageProtectFilter, Description=ImageProtectFilter.__doc__), ] HandleCommandLine(params) -- http://mail.python.org/mailman/listinfo/python-list
ensuring valid latin-1
Hey all, I'm trying to write something that will fail fast if one of my users gives me non-latin-1 characters. So I tried this: testString = \x80 foo = unicode(testString, latin-1) foo u'\x80' I would have thought that that should have raised an error, because \x80 is not a valid character in latin-1 (according to what I can find). Is this the expected behavior, or am I missing something? I'm on Windows, but I have explicitly set the character set to be latin-1 in sitecustomize.py import sys sys.getdefaultencoding() 'latin-1' -- http://mail.python.org/mailman/listinfo/python-list
makepy, ADO and dynamic.py
I'm trying to track down a performance issue in my Windows code, and hotshot is telling me that the most time and calls are spent in these methods ncalls tottime percall cumtime percall filename:lineno(function) 75975 63982.7790.842 124464.4191.638 c:\python24\lib\site-packages\win32com\client\dynamic.py:285(_make_method_) 71294 47871.4240.671 50629.2240.710 c:\python24\lib\site-packages\win32com\client\__init__.py:444(_ApplyTypes_) If I understand correctly, running makepy on the appropriate COM class should get rid of the dynamic stuff and let it be called directly. I use ADODB to talk to my database server, and I've run makepy for Microsoft Active X Data Objects 2.8 Library [1] and on Microsoft ActiveX Data Objects Recordset 2.8 Library, but I'm still seeing the call to the dynamic.py class. Am I right that seeing the calls in dynamic.py implies that I'm running makepy on the wrong thing? Any idea what I should be running makepy on? [1] I seem to have a bunch of versions of Microsoft ActiveX Data Objects Library, is there a chance that another ADO library is being used? -- http://mail.python.org/mailman/listinfo/python-list
2.4.3, unittest and socket logging
Hi all, I just upgraded to 2.4.3 (from 2.4.1) on Windows. Now each time I run my unit tests, they always throw this error at the end of the test run: Error in atexit._run_exitfuncs: Traceback (most recent call last): File c:\python24\lib\atexit.py, line 24, in _run_exitfuncs func(*targs, **kargs) File c:\python24\lib\logging\__init__.py, line 1333, in shutdown h.close() File c:\python24\lib\logging\handlers.py, line 448, in close logging.Handler.close(self) File c:\python24\lib\logging\__init__.py, line 674, in close del _handlers[self] KeyError: logging.handlers.SocketHandler instance at 0x00C41A58 The classes that are being tested do use socket handlers for logging, but I'm not sure if I should have been expecting this error, or what I should be doing to make it stop. (It's not critical, but it sure is annoying.) -- http://mail.python.org/mailman/listinfo/python-list
shared logs and multiple configurations
Hi all, I've apparently tied myself up a bit using the logging package. In my project, I have a core set of model and controller classes that set up their logging using logging.fileConfig(). So far, so good. But I use these core classes from a bunch of different places. Sometimes from within a CherryPy server, sometimes batch jobs run from a command line, sometimes from Windows services (also written in Python). Ah, the beauty of OO design. I would like to have a series of logs: a shared log for the core classes (which would log messages from the core classes, regardless of how they were invoked), a different one for CherryPy related stuff, a third one for batch jobs run from the command line, a fourth for the windows services. I'd alsolike to have the logs rotate automatically using the TimedRotatingFileHandler classes. Oh, and I'd like to do as much setup thru the configuration files and logging.fileConfig() as possible. So my questions are: 1) Can I share log files between processes? Log messages seem to get written, but when it comes time to roll over a log, I generally get a IO operation on closed file error. (I'm thinking that I may have to set up a logging service if I want to do this, but I'm hoping there's a simpler way.) 2) When I want to use logging from within a multi-threaded server (built using the Threading module), do I create one global logger reference, and then have each thread refer to that instance, or do I have each thread grab it's own reference using getLogger()? 3) It seems like you can't make multiple calls to logging.fileConfig(). If I call this twice with different ini files, it appears that any handlers set up in the first call are silently dropped when the second call is made. (Strangely, log messages sent to loggers set up in the first call seem to just be silently dropped.) Am I diagnosing this behavior properly? Is there a way to work around it? Platform is Python 2.4.2 on Windows. Many thanks! Chris -- http://mail.python.org/mailman/listinfo/python-list
example of logging w/ user-defined keywords?
Several things that I've read lead me to think this is possible, but I can't figure out how to do it. I have some information (a job number) that I would like logged on every log message, just like the time or the severity. I saw some mail threads that suggested that there was an easy way to do this, but I havent' found any examples. Is there a simple way to do this, or do I need to write my own logger subclass? -- http://mail.python.org/mailman/listinfo/python-list
warning users of problems with logging
The following code exists in logging/config.py handlers[hand] = h except: #if an error occurs when instantiating a handler, too bad pass#this could happen e.g. because of lack of privileges The problem here is that if something did go wrong instantiating the handler, you have no idea what the problem was (permissions, syntax error, wrong parameters), and later on you get a message like: Traceback (most recent call last): File c:\python24\lib\logging\config.py, line 151, in fileConfig log.addHandler(handlers[hand]) KeyError: 'default' I propose that we change the code so that we have a fighting chance of figuring out what's going on, like this: handlers[hand] = h except Exception, e: #if an error occurs when instantiating a handler, too bad print e #this could happen e.g. because of lack of privileges But I'm not sure if a print statement is the best way to go about it. Any thoughts? -- http://mail.python.org/mailman/listinfo/python-list
Re: warning users of problems with logging
So it is. Great! -- http://mail.python.org/mailman/listinfo/python-list
Re: socket.ssl with key files?
thanks for the info. 1) Am I correct that I should just be splitting the files? 2) The passphrase question was in the back of my mind, but I guess I need to move it to the front. Hopefully someone here will have an idea. (I wonder if M2Crypto handles that?) I guess it's better to know that the code is fairly untested, rather than finding that out on my own. -Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: socket.ssl with key files?
Rats, you beat me to it. It seems to work if I just give the same, combined file as the argument to both the key_file and cert_file parameters. (that's not to say that it doesn't work if I do something else). In my case, the passphrase is packaged up in the xml payload and sent over. Thank you everyone. -- http://mail.python.org/mailman/listinfo/python-list
socket.ssl with key files?
I need to use socket.ssl() to open a connection using key files. I have been provided with a text file called cert_key_pem.txt containing my keys that looks like this: -BEGIN RSA PRIVATE KEY- MIICXgIBAAKBgQDKwLuk/UpICOnZvH3mf9rFQvCkDPA8XQZLpa80Z0liMVYu4GQT snip -END RSA PRIVATE KEY- -BEGIN CERTIFICATE- MIICkTCCAfqgAwIBAgICNqUwDQYJKoZIhvcNAQEFBQAwgZ8xCzAJBgNVBAYTAlVT snip -END CERTIFICATE- I see that socket.ssl takes keyfile and certfile parameters. So do I just take the text file that I've been given and break it into two files, then specify those file names when I open the connection? At the moment, I'm getting File /usr/local/lib/python2.4/httplib.py, line 1070, in connect ssl = socket.ssl(sock, self.key_file, self.cert_file) File /usr/local/lib/python2.4/socket.py, line 74, in ssl return _realssl(sock, keyfile, certfile) socket.sslerror: (1, 'error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure') Many thanks for any ideas! -Chris -- http://mail.python.org/mailman/listinfo/python-list
paypal SOAP API from ZSI or SOAPpy?
Anyone had any luck with this? (Or can anyone just warn me off it right now?) I'm trying to just set up the service proxy via WSDL, and I'm getting either a runaway process that's chewing up tons of memory or a very quick stack trace. I've tried both ZSI and SOAPpy (both stable and release candidate versions) -- http://mail.python.org/mailman/listinfo/python-list
Re: importing a method
why not just have your user subclass soandso and override the definition of custom? from soandso import soandso class MyClass(soandso): def custom(self): self.theother = 3 c = MyClass() -- http://mail.python.org/mailman/listinfo/python-list
Re: mxODBC sql MSAccess
mxODBC implements the Python DB-API spec, which states that each row of query results is returned as a tuple. If you want the data displayed differently, you can do it yourself. for row in rows: print \t.join(row) should do it. -- http://mail.python.org/mailman/listinfo/python-list
Re: Tricky Areas in Python
I usually start by asking how you make variables private within classes. That seems to tell me if they understand something about the design of the language and it's a quick filter to tell if they know something about the syntax. The other question that I use is asking about 3rd party libraries that they have found useful. That can lead into some good questions about what they like about those libraries and what they dislike. That question helps me understand whether they've thought at all about how to design in Python. If I can't get a good conversation started with either of those, I'll ask what they don't like about Python, to see if they've actually used it to solve a real problem, or if they've just read the tutorial. As always, the best interview questions are open-ended, and give the candidate some room to really show their stuff (or give them enough rope to hang themselves). -- http://mail.python.org/mailman/listinfo/python-list
Re: 1 Million users.. I can't Scale!!
I guess I'd look at each part of the system independently to be sure I'm finding the real bottleneck. (It may be Python, it may not). Under your current system, is your python program still trying to send messages after 5 seconds? 30 seconds, 300 seconds? (Or have the messages been delivered to SMS and they're waiting in queue there?) If your python program is still streaming out the messages, what is it spending time on? At a gross level, is your machine CPU-bound? If you time out each step in your program after the content is generated, where is all the time going (message assembly, sending over the network, waiting for a response)? Just by some back-of-the-envelope calculations, 1 million messages at 100 bytes each is 100Mb. That's a bunch of data to push over a network in 2-3 seconds, especially in small chunks. (It's possible, but I'd look at that.) Can the SMS gateway handle that kind of traffic (incoming and outgoing)? Multi-threading may help if your python program is spending all it's time waiting for the network (quite possible). If you're CPU-bound and not waiting on network, then multi-threading probably isn't the answer. -- http://mail.python.org/mailman/listinfo/python-list
Re: send mail through webmail
If you have to do it thru the web, I would use one of the browser packages (mechanize, mechanoid, PAMIE, or IshyBrowser). Then you can scrape the site, fill out the forms, press the buttons, etc. This will be a *lot* more painful than using SMTP -- http://mail.python.org/mailman/listinfo/python-list
brain cramp: emulating cgi.FieldStorage
I can't be the first person to want to do this, but I also can't seem to find a solution. (Perhaps my Google skills are poor today.) How can I emulate cgi.FieldStorage() for my unit tests so that I don't have to put a web server in the way? what I'd like to do is something like fs = cgi.FieldStorage() fs[foo] = bar functionToBeTested(fs) Any hints/leads/suggestions? -- http://mail.python.org/mailman/listinfo/python-list
Re: brain cramp: emulating cgi.FieldStorage
figured it out... os.environ[QUERY_STRING] = foo=bar fs = cgi.FieldStorage() functionToBeTested(fs) -- http://mail.python.org/mailman/listinfo/python-list
job scheduling framework?
Has anyone seen a simple open source job-scheduling framework written in Python? I don't really want to reinvent the wheel. All I need is the ability to set up a series of atomic jobs as a stream, then have the system execute the jobs in the stream one-at-a-time until all the jobs in the stream are complete or one of them reports an error. (If it tied into a really simple grid-style computing farm, that would be worth double points!) -Chris -- http://mail.python.org/mailman/listinfo/python-list
__del__ pattern?
I need to ensure that there is only one instance of my python class on my machine at a given time. (Not within an interpreter -- that would just be a singleton -- but on the machine.) These instances are created and destroyed, but there can be only one at a time. So when my class is instantiated, I create a little lock file, and I have a __del__ method that deletes the lock file. Unfortunately, there seem to be some circumstances where my lock file is not getting deleted. Then all the jobs that need that special class start queueing up requests, and I get phone calls in the middle of the night. Is there a better pattern to follow than using a __del__ method? I just need to be absolutely, positively sure of two things: 1) There is only one instance of my special class on the machine at a time. 2) If my special class is destroyed for any reason, I need to be able to create another instance of the class. -- http://mail.python.org/mailman/listinfo/python-list
Re: client server question
import threading import logging ## class Reader(threading.Thread): def __init__(self, clientsock): threading.Thread.__init__(self) self.logger = logging.getLogger(Reader) #- def run(self): self.logger.info(New child %s % (threading.currentThread().getName())) self.logger.info(Got connection from %s % (clientsock.getpeername())) # set up a socket to listen for incoming connections from our clients s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.bind((host, port)) s.listen(1) while True: try: clientsock, clientaddr = s.accept() except KeyboardInterrupt: raise except: traceback.print_exc() continue client = Reader(clientsock) client.setDaemon(1) client.start() -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Path Setting
http://www.python.org/doc/2.4.1/inst/search-path.html#SECTION00041 -- http://mail.python.org/mailman/listinfo/python-list
Re: login website that using PHP
I'll add a plug for PAMIE (another set of Python classes that drive IE) http://pamie.sourceforge.net/ -- http://mail.python.org/mailman/listinfo/python-list
Re: separate IE instances?
the good news is that if run the ShellExecute bit twice, I get two instances of explorer in Task Manager The bad news is that the line ioObj = hwnds[1] tells me either This object does not support enumeration (if I have not used makepy to generate the classes) or object has no attribute __getitem__ (if I have used makepy) looking at the hwnds itself, it appears to be a win32com.gen_py.Microsoft Internet Controls.IWebBrowser2 instance If I call hwnds.Navigate(http://www.google.com;), I don't get an error, but I also don't see anything change in IE. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to use 8bit character sets?
Check out sitecustomize.py. http://diveintopython.org/xml_processing/unicode.html -- http://mail.python.org/mailman/listinfo/python-list
Re: separate IE instances?
thanks for all the help. I'll give the ShellExecute() approach a try in the morning. The short version of what I'm trying to do is Have my website login to a 3rd party website on behalf of my customer, fill out a form, and submit it. I'm just using CGI to keep things simple, but overlapping requests from different customers are the problem. The 3rd party site uses a lot of javascript, so mechanize isn't going to work. I could use some kind of locking mechanism and single-thread access to IE, but that won't scale. I guess the next approach would be to queue the requests and have a pool of worker processes (running as different users) process the requests and report back. -- http://mail.python.org/mailman/listinfo/python-list
Re: help with sending mail in Program
Maybe you could give us a little more info about where you're getting messed up. The message body is just a string, so if you can build a string out of variables, you should be able to do it. -- http://mail.python.org/mailman/listinfo/python-list
separate IE instances?
I need to create a set of IE instances that have different sets of session cookies. I thought that using the win32com.DispatchEx function would do this, but it doesn't seem to. In other words ie1 = win32com.DispatchEx(InternetExplorer.Application) ie2 = win32com.DispatchEx(InternetExplorer.Application) gives me two IE windows, but only one IEXPLORE process in Task Manager. And if I login to a site that uses session cookies to track sessions using ie1, when I move ie2 to the same site, ie2 is already logged in. Any help appreciated. -Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: weird cgi problem w/ apache
could it be the umask? -- http://mail.python.org/mailman/listinfo/python-list
win32com and apache and permissions
I'm trying to have a Python script (which is being launched by Apache as a CGI) control Internet Explorer. I have this working on my development box, but when I moved the code to my integration test box, I get Access Denied when trying to launch IE. This only seems to happen when running Apache as a service. If I run apache as a console app, everything works fine. In summary: User Method Dev Box Integration Box AdministratorConsole Works Works AdministratorService Works Access Denied Apache Console Works Works Apache Service Not permitted Not permitted So somewhere, somehow, I think I've granted some permission on the dev box that I have not granted on the integration box. Can anyone think of what it might be? -Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: win32com and apache and permissions
found the answer five minutes after posting the question. Isn't that always the way? I had not granted the Apache user permission to launch IE. To do so: * launch DCOMCNFG.exe * choose internet explorer and click properties * choose the security tab and and custom launch permissions * edit permissions, then add * choose Users, then click show users * choose the apache user and click add * OK your way out of there. -- http://mail.python.org/mailman/listinfo/python-list
CGIHTTPServer on Windows?
Hi all, I'm trying to work around my cgi-driving-IE problem by creating my own server, but CGIHTTPServer on Windows (python 2.3.5) seems to be having troubles. Trying to run a hello world CGI gives me: COMPAQ.ANTIQUES - - [11/May/2005 07:18:50] GET /cgi-bin/hello.py HTTP/1.1 200 - COMPAQ.ANTIQUES - - [11/May/2005 07:18:50] command: c:\program files\python235\p ython.exe -u C:\Documents and Settings\chris\My Documents\cgi-bin\hello.py COMPAQ.ANTIQUES - - [11/May/2005 07:18:50] 'c:\program' is not recognized as an internal or external command, operable program or batch file. COMPAQ.ANTIQUES - - [11/May/2005 07:18:50] CGI script exit status 0x1 I tried hacking the source of do_POST to put quotes around the name of the python executable and the script, but that didn't get me anywhere. Is there a solution to this, or does this approach require me to use pathnames without embedded spaces? -- http://mail.python.org/mailman/listinfo/python-list
FutureWarning in win32com?
Hi all, When trying to automate IE thru win32com (using PAMIE), I'm getting this message out C:\Program Files\Plone 2\Python\lib\site-packages\win32com\client\dynamic.py:463 : FutureWarning: %u/%o/%x/%X of negative int will return a signed string in Pyth on 2.4 and up debug_attr_print(Getting property Id 0x%x from OLE object % retEntry.dispid) The underlying code works fine (the browser ends up where it's supposed to), but this warning seems to be actually sent to stdout or stderr -- it's not a raised exception that I can catch. How can I suppress this message? -- http://mail.python.org/mailman/listinfo/python-list
win32com and ADO
I'm having one of those weeks. I have this pattern all over my code. result = conn.execute(select * from foo) while not result.EOF: doSomething() result.MoveNext() So recently I got around to running makepy on all of the Microsoft ActiveX Data Objects, and now every call to that pattern is returning: 'tuple' object has no attribute EOF can anyone tell me how I'm supposed to be using EOF? can anyone point me to the file that has the function lists? can anyone tell me how to undo what I've done? -- http://mail.python.org/mailman/listinfo/python-list
Re: win32com and ADO
Thanks Peter. I found the files that makepy generated (in $PYTHON_HOME/Lib/site-packages/win32com/gen_py). I've tried deleting the individual files, and the entire directory, and I'm still getting the error. (Maybe something was changed in the registry?) [Fun side note -- after deleting the files, I thought I would look in them for the EOF, but they stubbornly refused to regenerate, giving an error about This file has already been processed. The only way I could regenerate the files was by deleting the win32com package via the control panel and re-installing.] In the generated files, I did find a reference to EOF (all caps) in something called _prop_map_get_. (I had tried a few different variations on Eof, but none of them worked.) At this point, the only way that I can get to the EOF property is to force the dynamic dispatch by importing from com.win32.client.dynamic, AND coding like this: rs = Dispatch(ADODB.RecordSet) rs.ActiveConnection = conn rs.Open(select * from foo) while not rs.EOF: doSomething() rs.MoveNext() I hope someone can lend me a clue before I edit all of these query instances... -- http://mail.python.org/mailman/listinfo/python-list
Re: win32com and ADO
Achim, Bingo. The recordset is in item 0. And that appears to work even on systems where makepy has not been run. Thanks so much. -- http://mail.python.org/mailman/listinfo/python-list
Re: win32com and ADO
it was working fine before running makepy, once I ran makepy, I had to add the array index to make it work. -- http://mail.python.org/mailman/listinfo/python-list
win32com Dispatch() and SetPriorityClass()
if I'm using Dispatch() to manage a COM object (IE), is there a way to get ahold of the process handle so that I can bump it's priority? -- http://mail.python.org/mailman/listinfo/python-list
win32com and IIS
Hi all, I have a python script that uses the PAMIE libraries to drive IE. It runs fine from the command line, but it appears to have some permissions problem when I run it via CGI. Here's the stack trace that I'm getting. File c:\documents and settings\chris\my documents\cms\com\artfact\cms\model\cPAMIE.py, line 54, in __init__ self._ie = DispatchEx('InternetExplorer.Application') File C:\Program Files\Plone 2\Python\lib\site-packages\win32com\client\__init__.py, line 112, in DispatchEx dispatch = pythoncom.CoCreateInstanceEx(clsid, None, clsctx, serverInfo, (pythoncom.IID_IDispatch,))[0] com_error: (-2147024891, 'Access is denied.', None, None) I found this thread in the archives, but the changes made there don't seem to have helped. http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/3273ca109892b275/0da814cb9f341568?q=win32com+iisrnum=2#0da814cb9f341568 Any suggestions? -- http://mail.python.org/mailman/listinfo/python-list
Re: win32com and IIS
my OS is Win2K (server, I think) if that makes any difference. -- http://mail.python.org/mailman/listinfo/python-list
ANN: Boston Python Interest Group Meeting
Thursday, 7PM Harvard Science Center 1 Oxford St Room 507 Cambridge, mA 02101 'Nuff said. -- http://mail.python.org/mailman/listinfo/python-list
Re: include apythonscript.py
the PHP include doesn't have an exact match in Python, but I think you can do what you intend. To follow the first example from php.net, this would work vars.py color = 'green' fruit = 'apple' test.py from vars import * print A , color, fruit HTH -- http://mail.python.org/mailman/listinfo/python-list
Re: xmlrpclib and decoding entity references
yep, I'm using SimpleRPCServer, but something is getting messed up between the receipt of the XML stream and the delivery to my function. The normal entity references (like lt; and amp;) are handled OK, but the character references are not working. For instance, Andr#xe9; is received by the server, but it's delivered to the function as Andr; I've figured out how to parse through the string to find all the character references and convert them back, but that seems to be causing a ProtocolError. Hopefully someone can lend me a clue; I really don't want to have to switch over to SOAP and end up in WSDL hell. -- http://mail.python.org/mailman/listinfo/python-list
Re: xmlrpclib and decoding entity references
Here is the solution. Incidentally, the client is Cold Fusion. import re import logging import logging.config import os import SimpleXMLRPCServer logging.config.fileConfig(logging.ini) class LoggingXMLRPCRequestHandler(SimpleXMLRPCServer.CGIXMLRPCRequestHandler): def __dereference(self, request_text): entityRe = re.compile(((?Per#x)(?Pcode..)(?Psemi;))) for m in re.finditer(entityRe, request_text): hexref = int(m.group(3),16) charref = chr(hexref) request_text = request_text.replace(m.group(1), charref) return request_text #--- def handle_xmlrpc(self, request_text): logger = logging.getLogger() #logger.debug() #logger.debug(request_text) try: #logger.debug(-) request_text = self.__dereference(request_text) #logger.debug(request_text) request_text = request_text.decode(latin-1).encode('utf-8') #logger.debug() except Exception, e: logger.error(request_text) logger.error(had a problem dereferencing) logger.error(e) SimpleXMLRPCServer.CGIXMLRPCRequestHandler.handle_xmlrpc(self, request_text) class Foo: def settings(self): return os.environ def echo(self, something): logger = logging.getLogger() logger.debug(something) return something def greeting(self, name): return hello, + name # these are used to run as a CGI handler = LoggingXMLRPCRequestHandler() handler.register_instance(Foo()) handler.handle_request() -- http://mail.python.org/mailman/listinfo/python-list
Re: anybody have a CGIXMLRPCRequestHandler example?
here's the simple example, for posterity import os import SimpleXMLRPCServer class Foo: def settings(self): return os.environ def echo(self, something): return something def greeting(self, name): return hello, + name handler = SimpleXMLRPCServer.CGIXMLRPCRequestHandler() handler.register_instance(Foo()) handler.handle_request() and here's an example of the client that has to speak with it. My mistake was trying to call the server thru a web browser. The textcall shows you the format of the incoming request (which I suppose I could have built by hand by reading the spec). import xmlrpclib server = xmlrpclib.ServerProxy(http://127.0.0.1/cms/Foo.py;) yoonikode = u'Sacr\xe9 Bleu' tup = tuple([yoonikode]) print tup textcall = xmlrpclib.dumps(tup,(server.echo)) print textcall print server.echo(hi) print server.greeting(dilbert) print server.greeting(yoonikode) -- http://mail.python.org/mailman/listinfo/python-list
xmlrpc server running behind IIS as a CGI
Here's my server: import os import SimpleXMLRPCServer class Foo: def settings(self): return os.environ def echo(self, something): return something def greeting(self, name): return hello, + name handler = SimpleXMLRPCServer.CGIXMLRPCRequestHandler() handler.register_instance(Foo()) handler.handle_request() If I run this behind Apache/CGI, everything works fine. If I run this behind IIS/CGI, everything hangs when I call the server (I have confirmed that a hello world program runs fine thru CGI when called via a web browser). Here's the client program: import xmlrpclib server = xmlrpclib.ServerProxy(http://127.0.0.1:81/cms/Foo.py;) print server.settings() -- http://mail.python.org/mailman/listinfo/python-list
Re: modes for AES encryption?
Chris Curvey wrote: I'm trying to use the AES module in the Python Cryptography Toolkit. I need to set the mode to ECB/NoPadding, and there's a reference to a Mode parameter in the new() function, but no examples for AES. Who can point me in the right direction? Answering my own question for posterity...ECB is your *only* option for AES, and you have to do your own padding (pad with \0 to emulate NoPadding). -- http://mail.python.org/mailman/listinfo/python-list
cgi and multipart/form-data?
I have a form like this: form method=post enctype=multipart/form-data input type=file name=myFile input type=text name=foo input type=submit /form When I submit this form to my Python script using the CGI module, I seem to get the myFile variable, but I don't seem to the foo variable. Interestingly, if I take out the myFile variable (or specify a much smaller file) I do get the value for foo. The files that I'm trying to handle are 400-500Kb in size...is there something I need to do (cgi.maxlen?) to let cgi handle big files? -- http://mail.python.org/mailman/listinfo/python-list
Re: cgi and multipart/form-data?
Chris Curvey wrote: I have a form like this: form method=post enctype=multipart/form-data input type=file name=myFile input type=text name=foo input type=submit /form When I submit this form to my Python script using the CGI module, I seem to get the myFile variable, but I don't seem to the foo variable. Interestingly, if I take out the myFile variable (or specify a much smaller file) I do get the value for foo. The files that I'm trying to handle are 400-500Kb in size...is there something I need to do (cgi.maxlen?) to let cgi handle big files? man, was I on the wrong track. turns out the problem was that I was uploading a Excel file and something in there was getting thought of as an end-of-file marker. To fix: import msvcrt msvcrt.setmode(0, os.O_BINARY) # stdin = 0 msvcrt.setmode(1, os.O_BINARY) # stdout = 1 (credit where it's due: I found this on ASPN.) -- http://mail.python.org/mailman/listinfo/python-list
modes for AES encryption?
I'm trying to use the AES module in the Python Cryptography Toolkit. I need to set the mode to ECB/NoPadding, and there's a reference to a Mode parameter in the new() function, but no examples for AES. Who can point me in the right direction? -- http://mail.python.org/mailman/listinfo/python-list
python reading excel thru ADO ?
Windows-specific question for you all... I've been reading http://www.mayukhbose.com/python/ado/ad-connection.php , which seems to infer that I can read an Excel file using the ADO interface with Python on Windows. Unfortunately, the usual problem with ADO -- connection strings -- is raising it's ugly head. Has anyone made this work, and would you share the connection string that you used? Thanks! -Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: python reading excel thru ADO ?
Chris Curvey wrote: Windows-specific question for you all... I've been reading http://www.mayukhbose.com/python/ado/ad-connection.php , which seems to infer that I can read an Excel file using the ADO interface with Python on Windows. Unfortunately, the usual problem with ADO -- connection strings -- is raising it's ugly head. Has anyone made this work, and would you share the connection string that you used? Thanks! -Chris Chalk up a brain fart for me! I was doing connection.open(), not connection.Open(), and the error message made me think that there was a problem with the connection string. Thanks all! -Chris P.S. The proper URL above ends with ado-connection.php -- http://mail.python.org/mailman/listinfo/python-list