How do I implement two decorators in Python both of which would eventually want to call the calling function
Hi all, I am trying to simply my Web application handlers, by using Python decorators. Essentially I want to use decorators to abstract code that checks for authenticated sessions and the other that checks to see if the cache provider (Memcache in this instance) has a suitable response. Consider this method definition with the decorators: @auth.login_required @cache.clear def post(self, facility_type_id = None): auth.login_required checks to see if the user is logged in, otherwise returns an appropriate error message, or executes the original function. cache.clear would check to to see if the cache has a particular key and drop that, before it executes the calling method. Both auth.login_required and cache.clear would want to eventually execute the calling method (post). >From what I've read both, doing what I am doing now would execute the calling method (post) twice. My question, how do I chain decorators that end up executing the calling method, but ensure that it's only called once. Appreciate any pointers and thanks for your time. -- http://mail.python.org/mailman/listinfo/python-list
ActiveRecord for Python/MySQL
Hi everyone, My application uses MySQL as a backend and am using the MySQL/Python bindings. Are there any libraries that provide a database abstraction layer like Activerecords for Python?' Any resources/links will be appreciated. Thanks for your time. -- http://mail.python.org/mailman/listinfo/python-list
Re: ActiveRecord for Python/MySQL
Thanks On Aug 26, 5:26 pm, EuGeNe Van den Bulke <[EMAIL PROTECTED]> wrote: > Devraj wrote: > > My application uses MySQL as a backend and am using the MySQL/Python > > bindings. Are there any libraries that provide a database abstraction > > layer like Activerecords for Python?' > > SQLObject > SQLAclhemy > DejaVu > Storm > > Google for Python ORM you may find more! > > EuGeNe --http://www.3kwa.com -- http://mail.python.org/mailman/listinfo/python-list
urllib.ProxyHandler HTTPS issues
Hi everyone, I have been reading various documents/posts on the web about handling proxy options in urllib2. Some of them suggest that urllib2 doesn't handle HTTPS and others say it does. I have successfully written code that relays HTTP connections via a proxy but have failed to do the same for HTTPS connections. Can anyone confirm if urllib2 can handle HTTPS, also if someone can spare any code samples it will be much appreciated. Thank you for your time Python developers :) --- The code in question is available for download at http://code.google.com/p/gdatacopier/ -- http://mail.python.org/mailman/listinfo/python-list
Re: urllib.ProxyHandler HTTPS issues
Thanks John. Will investigate sending the CONNECT command to handle proxies. Do you recommend doing this for HTTP proxies as well or should I just use the ProxyHandler for HTTP proxies? On Oct 12, 4:29 am, [EMAIL PROTECTED] (John J. Lee) wrote: > Devraj <[EMAIL PROTECTED]> writes: > > Hi everyone, > > > I have been reading various documents/posts on the web about handling > > proxy options in urllib2. Some of them suggest that urllib2 doesn't > > handle HTTPS and others say it does. I have successfully written code > > that relays HTTP connections via a proxy but have failed to do the > > same for HTTPS connections. > > urllib2 does not support "HTTPS proxies" (it does not support use of > the CONNECT method). > > > Can anyone confirm if urllib2 can handle HTTPS, > > Yes, it can. > > John -- http://mail.python.org/mailman/listinfo/python-list
urlgrabber cookie handling?
Hi everyone, I have been battling to make my code work with a HTTPS proxy, current my code uses urllib2 to to most things and works well, except that urllib2 doesn't handle HTTPS proxies. Urlgrabber (http://linux.duke.edu/projects/urlgrabber/help/ urlgrabber.grabber.html) looks very promising except that I can find a way to handle cookies in urlgrabber. Is there a way urlgrabber can use a HTTPCookieProcess or cookielib.CookieJar object to handle cookies? Thanks for sparing your time. Thanks. -- Code referenced in this email is available at http://code.google.com/p/gdatacopier -- http://mail.python.org/mailman/listinfo/python-list
Re: urlgrabber cookie handling?
Hi John, Thanks for getting back to me. I did find the ASPN article. If I figure this out then I will make sure I post the code somewhere for public consumption. On Oct 18, 6:13 am, [EMAIL PROTECTED] (John J. Lee) wrote: > Devraj <[EMAIL PROTECTED]> writes: > > Hi everyone, > > > I have been battling to make my code work with a HTTPS proxy, current > > my code uses urllib2 to to most things and works well, except that > > urllib2 doesn't handle HTTPS proxies. > > > Urlgrabber (http://linux.duke.edu/projects/urlgrabber/help/ > > urlgrabber.grabber.html) looks very promising except that I can find a > > way to handle cookies in urlgrabber. Is there a way urlgrabber can use > > a HTTPCookieProcess or cookielib.CookieJar object to handle cookies? > > I don't see a nice way. But then I don't see any HTTPS proxy support > in urlgrabber... (I looked at version 3.1.0). > > There is a recipe or two on ASPN showing how to support HTTPS proxies > with urllib2, which gives an idea how to do it, though the code is a > bit rough (I'd post some code myself, but I did it for work). > > John -- http://mail.python.org/mailman/listinfo/python-list
Re: Best Python Linux distribution
I would recommend a Debian based distribution like Ubuntu or Debian itself :) On Oct 17, 10:29 pm, Anthony Perkins <[EMAIL PROTECTED]> wrote: > Hi everyone, > > What is the best GNU/Linux distribution (or the most preferred) for > developing Python applications? Ideally I would like one with both > Python *and* IDLE included on the install media (neither Ubuntu nor SUSE > have IDLE on the CDs), so that I can use it on machines without a > network connection. > > Thanks, > > -Anthony > > -- > Anthony Perkins > muzz.be -- http://mail.python.org/mailman/listinfo/python-list
HTTPS Proxy authentication
Hi Everyone, I have successfully used the ConnectHTTPSHandler class published at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/456195 to handle HTTPS proxy connections. Has anyone implemented a Basic authentication handler for ConnectHTTPSHandler? Or can I use urllib2 to handle the authentication? If someone can share their code/suggestions it would be greatly appreciated. Thanks for your time. -- http://mail.python.org/mailman/listinfo/python-list
urllib2 weirdness when https_proxy environment variable is exported
Hi Everyone, I have been extensively using Python's urllib2 while developing a project with the Google Data API. The Google Data API uses httplib to place all of its requests. However I have been using urllib2 and some handlers that I discovered in an ASPN article to handle HTTPS proxies in my code. The Google Data API relies on an environment variable called https_proxy to get information about the proxy to be used. However urllib2 starts spitting out the BadStatusLine exception if the https_proxy environment variable is found. Has anyone experienced similar things with urllib2? Is this a bug in the urllib2 libraries or am I completely missing something here? Attached is a dump of the error messages. Any experiences/information/ finding are welcome. Thanks for your time. Regards, Devraj -- Notice the BadStatusLine exception at the end of the error messages, the https_proxy variable is not even used by the code in anyway. I have also implemented simpler examples of the code to demonstrate the same. [EMAIL PROTECTED]:/data/gdatacopier# export https_proxy="http://proxy2:8080"; [EMAIL PROTECTED]:/data/gdatacopier# ./gdoc-cp.py --username [EMAIL PROTECTED] --list-all gdoc-cp.py version 1.0, content copy & backup utility for Google documents & spreadsheets Distributed under the GNU/GPL v2, Copyright (c) De Bortoli Wines <http://debortoli.com.au> Password: Logging into Google server as [EMAIL PROTECTED] ...Traceback (most recent call last): File "./gdoc-cp.py", line 352, in main() File "./gdoc-cp.py", line 347, in main parse_user_options() File "./gdoc-cp.py", line 298, in parse_user_options handle_login(_username, _password) File "./gdoc-cp.py", line 137, in handle_login _copier.login(username, password) File "/media/disk/gdatacopier/gdatacopier.py", line 310, in login response = self._open_https_url(prepared_auth_url, login_data) File "/media/disk/gdatacopier/gdatacopier.py", line 555, in _open_https_url response = opener.open(target_url, urllib.urlencode(post_data)) File "/usr/lib/python2.5/urllib2.py", line 381, in open response = self._open(req, data) File "/usr/lib/python2.5/urllib2.py", line 399, in _open '_open', req) File "/usr/lib/python2.5/urllib2.py", line 360, in _call_chain result = func(*args) File "/usr/lib/python2.5/urllib2.py", line 675, in meth(r, proxy, type)) File "/usr/lib/python2.5/urllib2.py", line 698, in proxy_open return self.parent.open(req) File "/usr/lib/python2.5/urllib2.py", line 381, in open response = self._open(req, data) File "/usr/lib/python2.5/urllib2.py", line 399, in _open '_open', req) File "/usr/lib/python2.5/urllib2.py", line 360, in _call_chain result = func(*args) File "/usr/lib/python2.5/urllib2.py", line 1107, in http_open return self.do_open(httplib.HTTPConnection, req) File "/media/disk/gdatacopier/gdatacopier.py", line 195, in do_open return urllib2.HTTPHandler.do_open(self, ProxyHTTPConnection, req) File "/usr/lib/python2.5/urllib2.py", line 1080, in do_open r = h.getresponse() File "/usr/lib/python2.5/httplib.py", line 924, in getresponse response.begin() File "/usr/lib/python2.5/httplib.py", line 385, in begin version, status, reason = self._read_status() File "/usr/lib/python2.5/httplib.py", line 349, in _read_status raise BadStatusLine(line) httplib.BadStatusLine Exporting the http_proxy variable does what one would expect [EMAIL PROTECTED]:/data/gdatacopier# export http_proxy="http://proxy2:8080"; [EMAIL PROTECTED]:/data/gdatacopier# ./gdoc-cp.py --username [EMAIL PROTECTED] --list-all gdoc-cp.py version 1.0, content copy & backup utility for Google documents & spreadsheets Distributed under the GNU/GPL v2, Copyright (c) De Bortoli Wines <http://debortoli.com.au> Password: Logging into Google server as [EMAIL PROTECTED] ...Traceback (most recent call last): File "./gdoc-cp.py", line 352, in main() File "./gdoc-cp.py", line 347, in main parse_user_options() File "./gdoc-cp.py", line 298, in parse_user_options handle_login(_username, _password) File "./gdoc-cp.py", line 137, in handle_login _copier.login(username, password) File "/media/disk/gdatacopier/gdatacopier.py", line 292, in login self._gd_client.ProgrammaticLogin() File "/usr/lib/python2.5/site-packages/gdata/service.py", line 307, in ProgrammaticLogin auth_connection.endheaders() File "/usr/lib/python2.5/httplib.py", line 856, in endheaders self._send_output() File "/usr/lib/python2.5/httplib.py", line 728, in _send_output self.send(msg) File "/usr/lib/python2.5/httplib.py", line 695, in send self.connect() File "/usr/lib/python2.5/httplib.py", line 1130, in connect sock.connect((self.host, self.port)) File "", line 1, in connect socket.gaierror: (-2, 'Name or service not known') -- http://mail.python.org/mailman/listinfo/python-list
Re: urllib2 weirdness when https_proxy environment variable is exported
Hi John, Thanks for that. Do you have any web urls that I can see an example of the hack? On Oct 28, 3:50 am, [EMAIL PROTECTED] (John J. Lee) wrote: > Devraj <[EMAIL PROTECTED]> writes: > > I have been extensively using Python's urllib2 while developing a > > project with the Google Data API. The Google Data API uses httplib to > > place all of its requests. However I have been using urllib2 and some > > handlers that I discovered in an ASPN article to handle HTTPS proxies > > in my code. > > > The Google Data API relies on an environment variable called > > https_proxy to get information about the proxy to be used. However > > urllib2 starts spitting out the BadStatusLine exception if the > > https_proxy environment variable is found. > > [...] > > This is because urllib2 does not support HTTPS proxies (neither does > urllib). See Python cookbook for a hack to get it working. > > John -- http://mail.python.org/mailman/listinfo/python-list
Writing GTK UI for Python apps in XUL
Hi everyone, Is it possible to write UI code in XUL for a GTK Python application? I found NuFox, which does the reverse (lets me write Python to generate XUL) Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Help needed
Sorry to diverge from the topic, but is there a reason you need to develop something like again? I would assume that there would be numerous utilities that would do this for you. If you want these features in your applications, why don't you consider incorporating existing tools/libraries into your program. Just trying to reason why you would want to write a network metrics program over again. On Jan 11, 1:15 pm, tijo <[EMAIL PROTECTED]> wrote: > Hi mate > > i need o do a python program to connect 2 systems using TCP/IP and > UDP. Also i need to check the performance of these two protocols (how > many bytes received and how much time took). I havent worked in python > earlier and have no idea of this. Could someone pls help me. I created > a program which can connect between 2 systems using these UDP and TCP/ > IP protocols. I dont know how to check the rest like how many bytes > send or how much time taken > since this is part of my course work could someone please help me > thanks in advance. > > tijo -- http://mail.python.org/mailman/listinfo/python-list
Detecting OS platform in Python
Hi everyone, My Python program needs reliably detect which Operating System its being run on, infact it even needs to know which distribution of say Linux its running on. The reason being its a GTK application that needs to adapt itself to be a Hildon application if run on devices like the N800. I have been searching around for an answer to this, and did find some messages on a lists that suggested the use of sys.platform to detect platform, with counter posts saying that it didn't work on Windows etc. Can anyone please shed some light on this? Thanks a lot. -- http://mail.python.org/mailman/listinfo/python-list
Re: open excel file while it is being used.
Hi Barry,
Obviously what you are trying to do is detect file locks. I am not
exactly sure how to do this in Python but from previous system
administration jobs here are some scenarios that you might want to
watch out for.
- I know for one that if you are accessing the file on a Samba share,
file locking with OpenOffice or Excel have strange things happen to
them
- I am also aware that the same thing works different if the files are
shared from a Windows server and accessed on a Linux machine, and
depends on the version of Samba/Linux kernel you are running
On Jan 11, 7:38 am, [EMAIL PROTECTED] wrote:
> Hi,
>
> I have a python program that constantly updates an excel spreadsheet.
> I would like to be able to view its updates while using excel to edit
> other excel files. Below are the test codes I have:
>
> --
> from time import sleep
> import win32com.client as w32c
>
> def test():
> w32c.pythoncom.CoInitialize()
> print w32c.pythoncom._GetInterfaceCount()
> app1 = w32c.Dispatch("Excel.Application")
> #app1.Visible=False
> #app1.Interactive = False
> wb=app1.Workbooks.Open("c:\\temp\\Book1.xls")
>
> sleep(3)
> sh=wb.Sheets("Sheet1")
> sh.Cells(2,1).Value = "Hello, world!"
> sh = None
>
> wb.Save()
> wb = None
> app1 = None
> w32c.pythoncom.CoUninitialize()
> print w32c.pythoncom._GetInterfaceCount()
> -
>
> If the user just looks at the file then it's fine, but if the user
> double clicks one cell, which will have a cursor flashing in the cell,
> then it will lead to a crash of the program with error: "Call was
> rejected by callee." I can make the program keep trying to access the
> file, but if the user doesn't make the flashing cursor disappear, the
> program will wait forever!
>
> I know excel has the fuction such that when a user is accessing a file
> and other users open that file, it will prompt for options of opening
> it as read-only or sending notification. I have been trying to
> implement that in the program, but don't know how.
>
> So, any suggestion will be greatly appreciated!
>
> - Barry
--
http://mail.python.org/mailman/listinfo/python-list
Where do glade files go?
Hi everyone, I am writing an application using Python/GTK/Hildon/Glade. I will be creating a debian package as the final distribution mechanism for the package. What would be the ideal place to put glade files that my application uses on the target system? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problems installing Python on server
Also be careful and setup all the paths that is required for compiling various Python modules etc. On Jan 29, 8:28 am, Yansky <[EMAIL PROTECTED]> wrote: > I asked my hosting company if they would upgrade Python on my server > to the latest version. They responded with: > > "Sorry no. We tend to stick with what comes packaged with the unix > distribution to ease maintenance issues. > > There is nothing stopping you from running your own version of python > from within your own account. Download the source and compile it and > install it into your own space. Adjust the fist line of your python > scripts to reflect the location of YOUR python binary: > > #! /home/youraccount/yourlibs/python > > and you should be all set." > > The build instructions for Python are: > To start building right away (on UNIX): type "./configure" in the > current directory and when it finishes, type "make". This creates an > executable "./python"; to install in usr/local, first do "su root" and > then "make install". > > The problem is, I don't have root access to the server so I can't do > the "make install". I have ubuntu on my computer, but from what I > understand I can't compile it on that and upload it because the server > runs Red Had and the ./configure would have made it incompatible > right? > > So how can I build Python without root access? -- http://mail.python.org/mailman/listinfo/python-list
