Parsing multipart HTTP response

2015-08-03 Thread Gilles Lenfant
ppreciated. -- Gilles Lenfant -- https://mail.python.org/mailman/listinfo/python-list

Re: Parsing multipart HTTP response

2015-08-03 Thread Gilles Lenfant
Le lundi 3 août 2015 17:01:40 UTC+2, Gilles Lenfant a écrit : > Hi, > > I searched without succeeding a Python resource that is capable of parsing an > HTTP multipart/mixed response stream, preferably as a generator that yields > headers + content for each part. > > Goog

Re: Parsing multipart HTTP response

2015-08-03 Thread Gilles Lenfant
Le lundi 3 août 2015 17:39:57 UTC+2, Mark Lawrence a écrit : > On 03/08/2015 16:01, Gilles Lenfant wrote: > > Hi, > > > > I searched without succeeding a Python resource that is capable of parsing > > an HTTP multipart/mixed response stream, preferably as a generat

[wanted] python-ldap for Python 2.3 / Win32

2011-10-25 Thread Gilles Lenfant
newer Python version. So, please don't tell me to upgrade ;) Many thanks by advance to the people who will help me. You can send this package via mail to gillesDOTlenfantATgmailDOTcom. -- Gilles Lenfant -- http://mail.python.org/mailman/listinfo/python-list

Re: [wanted] python-ldap for Python 2.3 / Win32

2011-10-25 Thread Gilles Lenfant
So many thanks for your valuable help Waldemar, this is exactly what I needed. I have no Windows machine to compile with the source bundle all this, and must install this directly in a production server. I'll keep these precious links and files in a trunk. Many thanks again -- Gilles Le

"Daemonizing" an application.

2013-02-27 Thread Gilles Lenfant
? Is it possible with standard packages only ? Thanks in advance fo any pointer. -- Gilles Lenant -- http://mail.python.org/mailman/listinfo/python-list

Re: "Daemonizing" an application.

2013-02-27 Thread Gilles Lenfant
Le mercredi 27 février 2013 11:52:19 UTC+1, Gilles Lenfant a écrit : > Hello, > Hello again, And thanks to all for your pointers and ideas. As the app is already tied to an Unix like OS, I'll go with signal handling first since I can do all I need through reconfiguration (SIGHUP).

Re: "Daemonizing" an application.

2013-02-27 Thread Gilles Lenfant
Le mercredi 27 février 2013 14:55:42 UTC+1, Tarek Ziadé a écrit : > On 2/27/13 11:52 AM, Gilles Lenfant wrote: > > > Hello, [...] > > > Thanks in advance fo any pointer. > > > > > You can have a look at Circus - https://circus.readthedocs.

[OT ?] (Pythonic) detection word protected files

2005-06-13 Thread Gilles Lenfant
and which ones are not. I can't use the COM interface for this because the utility must run on a Linux Samba server. I didn't find anything satisfying in M$ related sites (like msdn) or forums or google. Any hint ? Many thanks by advance. -- Gilles -- http://mail.python.org/mailman/listinfo/python-list

Re: [OT ?] (Pythonic) detection word protected files

2005-06-14 Thread Gilles Lenfant
Tim Golden a écrit : > [Gilles Lenfant] > | I'm building an utility that makes a catalog of M$ word files > | in a giant > | directory tree. The password protected files must be marked, and I > | didn't find how to guess which files are password protected and which >

Re: [OT ?] (Pythonic) detection word protected files

2005-06-14 Thread Gilles Lenfant
ryption information (protected or not) in the UNO API. Anyway UNO is somehow overkill to get something like a pair of bytes at some position in the file (4 or 5 python lines with the standard packages). Many thanks -- Gilles -- http://mail.python.org/mailman/listinfo/python-list

Re: Is Python Suitable for Large Find & Replace Operations?

2005-06-14 Thread Gilles Lenfant
Are this huge amount of data to rearch/replace stored in an RDBMS or in flat file(s) with markup (XML, CSV, ...) ? -- Gilles -- http://mail.python.org/mailman/listinfo/python-list

Subprocess and time-out

2005-06-16 Thread Gilles Lenfant
considered deadlocked) and to process the next file. Unfortunately, I didn't find any pythonic stuff to control the time spent runnning subprocesses (and kill'em if needed) launched with popen. An hint is welcome. Many thanks by advance. -- Gilles Lenfant -- http://mail.python.org/mai

GUI apps in Windows with native widgets?

2007-06-18 Thread Gilles Ganault
Hello I'd like to write a GUI app in Python exclusively for Windows. Apparently, development of PythonWin has stopped a long time ago. Is there another thin wrapper to write apps in Windows? I'd rather not have to ship eg. WxWidgets, GTK+, or QT. Thank you. -- http://mail.python.org/mai

[2.5] Script to POST to web page with cookies?

2007-07-19 Thread Gilles Ganault
Hello I need to write a script to automate fetching data from a web site: 1. using the POST method, log on, with login/password saved as cookies 2. download page and extract relevent information using regexes 3. log off 4. wait for a random number of minutes, and GOTO 1 I'm a bit confused with ho

[2.5] Regex doesn't support MULTILINE?

2007-07-21 Thread Gilles Ganault
Hello I'm trying to extract information from a web page using the Re module, but it doesn't seem to support MULTILINE: = import re #NO CRLF : works response = "Blablabla" #CRLF : doesn't work response = "Blablabla\r\n" pattern = "Bla.+?" p = re.compile(pattern,re.IGNORECASE|re.MULT

Re: [2.5] Regex doesn't support MULTILINE?

2007-07-21 Thread Gilles Ganault
On Sat, 21 Jul 2007 22:18:56 -0400, Carsten Haese <[EMAIL PROTECTED]> wrote: >That's your problem right there. RE is not the right tool for that job. >Use an actual HTML parser such as BeautifulSoup Thanks a lot for the tip. I tried it, and it does look interesting, although I've been unsuccessful

Building browser-like GET request

2007-04-21 Thread Gilles Ganault
Hello I'd like to download pages from a site, but it checks whether the requests are coming from a live user or a script; If the latter, the server returns a blank page. Using a proxy (Paros), I can see what information my script and FireFox send, and there are a lot of information that P

Re: Building browser-like GET request

2007-04-21 Thread Gilles Ganault
On 21 Apr 2007 14:47:55 -0700, Björn Keil <[EMAIL PROTECTED]> wrote: >Well, I am brand new to Python, so it takes me a lot of guessing, but >since it seems you're using urlib2: Thanks. Indeed, it looks like urlib2 is the way to go when going through a proxy. For those interested, here's how to d

[re.finditer] Getting all occurences in one go?

2007-04-22 Thread Gilles Ganault
Hello I'd like to make sure there isn't an easier way to extract all the occurences found with re.finditer: === req = urllib2.Request(url, None, headers) response = urllib2.urlopen(req).read() matches = re.compile("(\d+).html").finditer(response) # --- BEGIN for match

Re: [re.finditer] Getting all occurences in one go?

2007-04-22 Thread Gilles Ganault
On Sun, 22 Apr 2007 23:28:23 +0200, Gilles Ganault <[EMAIL PROTECTED]> wrote: >I'd like to make sure there isn't an easier way to extract all the >occurences found with re.finditer: Oops, s/match/item/: req = urllib2.Request(url, None, headers) response = urllib2.urlop

[SQLite] Recommended wrapper?

2007-04-23 Thread Gilles Ganault
Hello I browsed through the SQLite archives at Gname, but most threads regarding wrappers for Python date back to 2005, and for this ng, Google returns stuff from 2006 as the most relevant posts, so I figured I should ask here before diving in. There are several wrappers listed in the wik

Re: [re.finditer] Getting all occurences in one go?

2007-04-23 Thread Gilles Ganault
On 22 Apr 2007 15:33:37 -0700, Paul Rubin wrote: > mytable[item] = ','.join(m.group(1) for m in matches) Thanks, that did it. -- http://mail.python.org/mailman/listinfo/python-list

Re: [SQLite] Recommended wrapper?

2007-04-23 Thread Gilles Ganault
On Mon, 23 Apr 2007 16:03:05 +0200, Thomas Krüger <[EMAIL PROTECTED]> wrote: >It's all there: >http://docs.python.org/lib/module-sqlite3.html Thanks. -- http://mail.python.org/mailman/listinfo/python-list

Re: Building browser-like GET request

2007-04-24 Thread Gilles Ganault
On Sun, 22 Apr 2007 18:07:57 -0400, Steve Holden <[EMAIL PROTECTED]> wrote: >On a point of information, Wireshark wokrs very effectively under >Windows. The only thing you shouldn't expect to be able to do is tap >into the loopback network, and that's down to the Windows driver structure. Thanks

Re: [2.5] Regex doesn't support MULTILINE?

2007-07-23 Thread Gilles Ganault
On Sun, 22 Jul 2007 05:34:17 -0300, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: >Try to avoid using ".*" and ".+" (even the non greedy forms); in this >case, I think you want the scan to stop when it reaches the ending >or any other tag, so use: [^<]* instead. > >BTW, better to use a raw st

Why no maintained wrapper to Win32?

2007-07-28 Thread Gilles Ganault
Hello It looks like the development of the PyWin32 wrapper to the Win32 API stopped years ago, which is too bad because it means that writing GUI apps in Python even just for Windows means adding megabytes when using eg. wxWidgets. How come no one too over this project, or offered another

Re: Why no maintained wrapper to Win32?

2007-07-28 Thread Gilles Ganault
On Sat, 28 Jul 2007 18:05:34 +0200, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote: >Why does it mean that? The Win32 APIs for GUI are up-to-date; they >don't need further development. Win32 itself stopped years ago. >You can write GUI applications with PyWin32 just fine. Besides the total lack of do

Re: Why no maintained wrapper to Win32?

2007-07-29 Thread Gilles Ganault
On Sun, 29 Jul 2007 06:40:35 +0200, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote: >Why do you say that the Win32 API lacks documentation? I find the >documentation at msdn.microsoft.com to be quite useful. No, I meant documentation on how to write Win32 apps using PyWin. >Yes, there haven't been m

Re: Why no maintained wrapper to Win32?

2007-07-29 Thread Gilles Ganault
On Sun, 29 Jul 2007 19:33:40 -0700, sturlamolden <[EMAIL PROTECTED]> wrote: >You mean 'total lack of documentation' besides Mark Hammond's O'Reilly >book on Windows programming in Python? Sorry, I thought that book was way outdated because it uses Python 1.5. >Not to mention MSDN, Charles Petzold

Re: Why no maintained wrapper to Win32?

2007-07-30 Thread Gilles Ganault
On Sun, 29 Jul 2007 21:49:04 -0700, sturlamolden <[EMAIL PROTECTED]> wrote: >Why inflict suffering on yourself with MFC when you can use wxPython >or PyGTK? Because I'd like to avoid having to pack several MB + having to install the toolkit. Considering the size of the typical Python script, it se

[2.5] Reading a two-column file into an array?

2007-07-30 Thread Gilles Ganault
Hello I'm sure there's a much easier way to read a two-column, CSV file into an array, but I haven't found it in Google. Should I use the Array module instead? = a = [] i = 0 #itemitem p = re.compile("^(.+)\t(.+)$") for line in textlines: m = p.search(line) if m:

Re: Reading a two-column file into an array?

2007-08-02 Thread Gilles Ganault
On Tue, 31 Jul 2007 08:41:45 -0700, [EMAIL PROTECTED] (Alex Martelli) wrote: >That's what 2.5's with statement is all about...: Thanks everyone. Python power :-) from __future__ import with_statement import csv with open('import.csv', 'rb') as f: for item in list(csv.reader(f, delimiter=

[regex] Basic rewriting

2007-11-20 Thread Gilles Ganault
Hello I've been reading tutorials on regexes in Python, but I still don't get it: #!/usr/bin/python #myscript.py 0123456789 import sys,re #Turn 0123456789 into 01.23.45.67.89 p = re.compile('(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)') phone = p.sub('\1.\2.\3.\4.\5',sys.argv[1]) print pho

Re: [regex] Basic rewriting

2007-11-20 Thread Gilles Ganault
On Tue, 20 Nov 2007 21:57:43 -0500, "J. Clifford Dyer" <[EMAIL PROTECTED]> wrote: >Use raw strings for re expressions. Thanks guys for the prompt reply :-) Solved it. -- http://mail.python.org/mailman/listinfo/python-list

Clean way to get one's network IP address?

2007-11-21 Thread Gilles Ganault
Hello I need to get the local computer's IP address, ie. what's displayed when running "ifconfig" in Linux: # ifconfig eth0 Link encap:Ethernet HWaddr 00:15:58:A1:D5:6F inet addr:192.168.0.79 Bcast:192.168.0.255 Mask:255.255.255.0 I know about socket.gethostbyname, but this re

Re: Clean way to get one's network IP address?

2007-11-21 Thread Gilles Ganault
On Wed, 21 Nov 2007 07:20:45 -0800 (PST), Paul McGuire <[EMAIL PROTECTED]> wrote: >Be aware that it is very possible to have multiple IP addresses from >which to choose Yup, but this is the local host, and it only has a single interface. Should I look into os.environ() or something like that? --

Not forking?

2007-11-22 Thread Gilles Ganault
Hello I'd like to rewrite the following Perl script in Python: http://www.voip-info.org/wiki/view/Asterisk+NetCID It seems like the following doesn't actually fork, so Asterisk is stuck until the script ends: === import socket,sys,time,os def sendstuff(data): s.sendto(data,(

Re: Not forking?

2007-11-29 Thread Gilles Ganault
On Sat, 24 Nov 2007 14:33:34 +1300, greg <[EMAIL PROTECTED]> wrote: >What makes you think it's not forking? Chances are >it *is* forking, but something is going wrong later. You were right. There were scrambled characters in the script (copy/pasting from Windows), which kept the script from workin

Re: Is there *any* real documentation to PyWin32?

2007-12-21 Thread Gilles Ganault
On Thu, 20 Dec 2007 03:35:23 -0800 (PST), Benoit <[EMAIL PROTECTED]> wrote: >I understand that the Win32 has been said to be itself poorly >documented, so perhaps that the documentation that comes with the >modules is of similar quality is no coincidence. PyWin32 is free, and writing extensive doc

Re: Is there *any* real documentation to PyWin32?

2007-12-24 Thread Gilles Ganault
On Fri, 21 Dec 2007 17:56:25 -0800 (PST), sturlamolden <[EMAIL PROTECTED]> wrote: >If Benoit is having trouble using PyWin32, I think he is having >trouble using the Windows API. I wouldn't blame him :-) Besides, the point of writing Windows apps directly in Python, ie. without relying on an extra

[newbie] Read file, and append?

2007-12-25 Thread Gilles Ganault
Hello I'd just like to open each file in a directory with a given extension, read it to search for a pattern, and, if not found, append data to this file. The following doesn't work: == import glob,re f = open("activate.tmpl", "r") template = f.read() template = "\r\n" + template f.clos

Re: [newbie] Read file, and append?

2007-12-25 Thread Gilles Ganault
On Tue, 25 Dec 2007 01:14:37 -0800, Gary Herron <[EMAIL PROTECTED]> wrote: >Here's what I'd end up with. (This is untested.) Thanks a lot. It worked. I didn't suspect there could be so many errors in such a small sript :-D -- http://mail.python.org/mailman/listinfo/python-list

Re: [newbie] Read file, and append?

2007-12-26 Thread Gilles Ganault
On Tue, 25 Dec 2007 13:27:09 -0800, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: >Ignoring the question of the proper I/O mode, I believe the I/O >system MAY require one to perform a seek() when switching from read to >write and vice versa... I thought about this, but I don't understand why I woul

Re: [newbie] Read file, and append?

2007-12-27 Thread Gilles Ganault
On Wed, 26 Dec 2007 14:33:15 -0800, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: >Works for me, as long as one uses a seek() call when switching >between read and write... Thanks, Dennis. Worked :-) I just changed the access mode from binary to text so that Python handles the EOL character correct

[2.4.2] Compiling Python with packages?

2008-02-02 Thread Gilles Ganault
Hello I need to compile Python with the packages "socket,sys,time,os", but I've never done it before, and would like confirmation that this will work as planned: == make clean ./configure --with-socket --with-sys --with-time --with-os make make install == In addition, are there r

[2.4.2/Linux] Getting Python to fork?

2008-02-03 Thread Gilles Ganault
Hello I need to launch a Python script, and fork it so that the calling script can resume with the next step will the Python script keeps running. I tried those two, but they don't work, as the calling script is stuck until the Python script ends: sys.stdout = open(os.devnull, 'w')

Re: [2.4.2] Compiling Python with packages?

2008-02-03 Thread Gilles Ganault
On Sun, 03 Feb 2008 09:14:24 +0100, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote: >No, it won't. You don't give any arguments to configure normally, >when building Python. Instead, setup.py will detect what libraries >are on your system, and use them. Thanks for the tip. -- http://mail.python.org/

Re: [2.4.2/Linux] Getting Python to fork?

2008-02-13 Thread Gilles Ganault
On Mon, 04 Feb 2008 16:40:01 +0100, Rolf van de Krol <[EMAIL PROTECTED]> wrote: >To create a deamon, you indeed need to fork two times. Do I really need this much complication just to exit the script and let a child handle the pop-up? I've changed this line, and the parent still doesn't return, a

Re: wxPython/wxWidgets ok for production use ? (was Re: Quality assurance in Python projects containing C modules)

2008-03-10 Thread Gilles Ganault
On Mon, 10 Mar 2008 11:27:06 -0400, "Malcolm Greene" <[EMAIL PROTECTED]> wrote: >Any suggestions on an alternative Python client-side GUI library (pyQT >?) or tips on where I can find out more about wxPython/wxWidget >problems? One thing that bothers me is that it seems like there's no ecosystem a

Re: wxPython/wxWidgets ok for production use ? (was Re: Quality assurance in Python projects containing C modules)

2008-03-11 Thread Gilles Ganault
On Mon, 10 Mar 2008 22:17:16 -0700 (PDT), Frank Millman <[EMAIL PROTECTED]> wrote: >I do not know if this helps, but here is an extract from a recent post >to the wxPython mailing list from Robin Dunn, the main developer of >wxPython - I'll take a look. Thanks for the info. -- http://mail.python.

Re: wxPython/wxWidgets ok for production use ? (was Re: Quality assurance in Python projects containing C modules)

2008-03-12 Thread Gilles Ganault
On Tue, 11 Mar 2008 11:43:45 +0100, Stef Mientki <[EMAIL PROTECTED]> wrote: >Funny, compared to Delphi-7, >I found the grid in wxPython much richer ;-) You haven't tried the better alternatives I had in mind: http://www.x-files.pl http://www.bergsoft.net http://www.tmssoftware.com http://www.scal

Monitoring SSHd and web servers?

2008-03-13 Thread Gilles Ganault
Hello I'd like to monitor connections to a remote SSH and web server. Does someone have some code handy that would try to connect every 5mn, and print an error if the script can't connect? Thank you. -- http://mail.python.org/mailman/listinfo/python-list

[2.5.1] Comparing dates?

2009-02-02 Thread Gilles Ganault
Hello I have data in an SQL database where one column contains a date formated as DD/MM/Y. I need to select all rows where the date is before, say Feb 1st 2009, ie. 01/02/2009. Is there a command in Python that does this easily, or should I look into whatever date() function the SQL

Re: [2.5.1] Comparing dates?

2009-02-02 Thread Gilles Ganault
On Mon, 02 Feb 2009 20:06:02 +1100, Ben Finney wrote: >The Python data types for date and time are in the ‘datetime’ module >http://www.python.org/doc/2.6/library/datetime>. Create a >‘datetime’ object for each value you want, then compare them. Thanks guys. For those interested, here's how to pe

[Web 2.0] Added-value of frameworks?

2009-02-04 Thread Gilles Ganault
Hello If I wanted to build some social web site such as Facebook, what do frameworks like Django or TurboGears provide over writing a site from scratch using Python? Thank you for your feedback. -- http://mail.python.org/mailman/listinfo/python-list

Re: [2.5.1] Comparing dates?

2009-02-04 Thread Gilles Ganault
On Mon, 2 Feb 2009 22:00:53 +0100, Martin wrote: >as suggested, the DBA should seriously think about defining the >correct type of the column here, for intermediate use and getting >stuff to work you could use a view and define some stored procedures >on it so that inserting properly works... Rig

Using dictionary to hold regex patterns?

2008-11-23 Thread Gilles Ganault
Hello After downloading a web page, I need to search for several patterns, and if found, extract information and put them into a database. To avoid a bunch of "if m", I figured maybe I could use a dictionary to hold the patterns, and loop through it: == pattern = {} pattern["pattern1"] = ">.

Re: Using dictionary to hold regex patterns?

2008-11-23 Thread Gilles Ganault
On Sun, 23 Nov 2008 17:55:48 +, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: >But there is no reason why you should use a dictionary; just use a list >of key-value pairs: > >patterns = [ >("pattern1", re.compile(">.+?.+?>(.+?)"), Thanks for the tip, but... I thought that lists could only us

Re: Using dictionary to hold regex patterns?

2008-11-23 Thread Gilles Ganault
On Sun, 23 Nov 2008 17:55:48 +, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: >But there is no reason why you should use a dictionary; just use a list >of key-value pairs: Thanks for the tip. I didn't know it was possible to use arrays to hold more than one value. Actually, it's a better solutio

Re: Using dictionary to hold regex patterns?

2008-11-23 Thread Gilles Ganault
On Sun, 23 Nov 2008 23:18:06 +, MRAB <[EMAIL PROTECTED]> wrote: >A list is an ordered collection of items. Each item can be anything: a >string, an integer, a dictionary, a tuple, a list... Yup, learned something new today. Naively, I though a list was index=value, where value=a single piece

[2.5.1] ShiftJIS to Unicode?

2008-11-26 Thread Gilles Ganault
Hello I'm trying to read pages from Amazon JP, whose web pages are supposed to be encoded in ShiftJIS, and decode contents into Unicode to keep Python happy: www.amazon.co.jp But this doesn't work: == m = try.search(the_page) if m: #UnicodeEncodeError: 'charmap' codec can'

Re: [2.5.1] ShiftJIS to Unicode?

2008-11-27 Thread Gilles Ganault
On Thu, 27 Nov 2008 01:00:28 +, MRAB <[EMAIL PROTECTED]> wrote: >No problem here: > > >>> import urllib > >>> data = urllib.urlopen("http://www.amazon.co.jp/";).read() > >>> decoded_data = data.decode("shift-jis") > >>> Thanks, but it seems like some pages contain ShiftJIS mixed with some othe

[cookielib] How to add cookies myself?

2008-12-16 Thread Gilles Ganault
Hello I'm using urllib and urlib to download data from a web server that requires cookies. The issue I'm having, is the server uses JavaScript in the response to insert new cookies and send them with the next query, so I need to manually add a couple of cookies in the CookieJar, but I don't know

Are Django/Turbogears too specific?

2008-12-21 Thread Gilles Ganault
Hi I'd like to rewrite a Web 2.0 PHP application in Python with AJAX, and it seems like Django and Turbogears are the frameworks that have the most momentum. I'd like to use this opportunity to lower the load on servers, as the PHP application wasn't built to fit the number of users hammering the

[2.5.1] Str.Replace() doesn't work?

2008-12-26 Thread Gilles Ganault
Hello I need to parse an HTML file where records aren't homogenous, so I figured I could run a first loop to add an unused character at the beginning of each record, and then run a second loop to actually parse each record. I can't figure out why the script is not returning anything in th

Re: [2.5.1] Str.Replace() doesn't work?

2008-12-26 Thread Gilles Ganault
On Fri, 26 Dec 2008 15:16:49 +0100, Gilles Ganault wrote: >I can't figure out why the script is not returning anything in the >"for m in matches" block: Pfff, found it 5mn after posting ;-) s/reponse =/response =/ Sorry guys. -- http://mail.python.org/mailman/listinfo/python-list

[SQL] Right way to set a variable to NULL?

2008-12-26 Thread Gilles Ganault
Hello I use regexes to extract information from a text file. Some of the records don't have e-mails or www addresses, so those must match Null in SQL, but None doesn't work as expected: === if itemmatch: web = itemmatch.group(1).strip() else: we

[email/quoprimime.py] AttributeError: 'tuple' object has no attribute 'lstrip'

2009-01-04 Thread Gilles Ganault
Hello I successfully use the email package to send e-mail from Python scripts, but this script fails when I fetch addresses from an SQLite database where data is Unicode-encoded: == from email.MIMEText import MIMEText import smtplib,sys import apsw connection=apsw.Connection("test.

[http] Example with proxy + post + cookie?

2009-01-06 Thread Gilles Ganault
Hello I need to write a script that goes out through a proxy, connects with a POST query, and receives a cookie for a Session ID. I didn't find an example on the Net that did it all three, but only some of the features. Does someone have one handy by any chance? Thank you. -- http://mail.python.

Re: [email/quoprimime.py] AttributeError: 'tuple' object has no attribute 'lstrip'

2009-01-06 Thread Gilles Ganault
On Mon, 05 Jan 2009 17:54:19 -0500, Terry Reedy wrote: >> for email in rows: >> To = email Thanks guys. Turns out email is a tuple, so here's how to extract the columns: for email in rows: email=email[0] -- http://mail.python.org/mailman/listinfo/python-list

[urllib2] 302 -> can't get cookie

2009-01-07 Thread Gilles Ganault
Hello I'm using urllib2 to connect to a web server with POST, and then the server sends a cookie to hold the session ID, but also redirects the user to another page: === HTTP/1.1 302 Found Date: Wed, 07 Jan 2009 11:20:51 GMT Server: Apache Set-Cookie: PHPSESSID=4015f14eb04dc81159253a9533a7c590; p

[APSW] SELECT COUNT(*) not succesfull?

2008-10-22 Thread Gilles Ganault
Hello I'm trying to use the APSW package to access a SQLite database, but can't find how to check if a row exists. I just to read a tab-separated file, extract a key/value from each line, run "SELECT COUNT(*)" to check whether this tuple exists in the SQLite database, and if not, run an INSERT. T

Re: [APSW] SELECT COUNT(*) not succesfull?

2008-10-22 Thread Gilles Ganault
On Wed, 22 Oct 2008 18:35:35 +0200, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: >It is - the problem is that cursor.execute doesn't return what you >think... Truth is that according to the db-api specification, the return >value of cursor.execute is not defined (IOW : can be absolutely >anyth

[2.5.1] Converting string to int?

2008-10-23 Thread Gilles Ganault
Hello I'm using the APSW wrapper to SQLite, and I'm stuck at how to pass data from a dictionary to the database which expects an integer: #array filled by reading a two-column text file as input for (isbn,carton) in data.items(): #TypeError: int argument required sql = "INSERT INT

Re: [APSW] SELECT COUNT(*) not succesfull?

2008-10-23 Thread Gilles Ganault
On Thu, 23 Oct 2008 00:24:01 -0200, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: >In case you didn't notice, B.D. already provided the answer you're after - >reread his 3rd paragraph from the end. Yes, but it doesn't work with this wrapper (APSW version 3.5.9-r1): >> The recommended way is to

Re: [2.5.1] Converting string to int?

2008-10-23 Thread Gilles Ganault
On Thu, 23 Oct 2008 09:19:07 +0200, Gilles Ganault <[EMAIL PROTECTED]> wrote: >I'm using the APSW wrapper to SQLite, and I'm stuck at how to pass >data from a dictionary to the database which expects an integer: Found it: Apparently, this wrapper uses a different placeho

URL as input -> "IOError: [Errno 2] The system cannot find the path specified"

2008-10-24 Thread Gilles Ganault
Hello I'm trying to use urllib to download web pages with the GET method, but Python 2.5.1 on Windows turns the URL into something funny: url = "amazon.fr/search/index.php?url=search" [...] IOError: [Errno 2] The system cannot find the path specified: 'amazon.fr\\search\\index.php?url=

Re: URL as input -> "IOError: [Errno 2] The system cannot find the path specified"

2008-10-24 Thread Gilles Ganault
On 24 Oct 2008 18:02:45 GMT, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: >This "URL" lacks the protocol! Correct would be http://amazon.fr… (I >guess). Thanks, that did it :) -- http://mail.python.org/mailman/listinfo/python-list

Urllib vs. FireFox

2008-10-24 Thread Gilles Ganault
Hello After scratching my head as to why I failed finding data from a web using the "re" module, I discovered that a web page as downloaded by urllib doesn't match what is displayed when viewing the source page in FireFox. For instance, when searching Amazon for "Wargames": URLLIB: http://www.am

[newbie] Right way to access item in array?

2008-10-28 Thread Gilles Ganault
Hello I'd like to know what the right way is to access an item in a row as returned by a database: = import apsw connection=apsw.Connection("test.sqlite") cursor=connection.cursor() rows=cursor.execute("SELECT isbn,price FROM books WHERE price IS NULL") for row in rows: #Is this ri

Re: Urllib vs. FireFox

2008-10-28 Thread Gilles Ganault
On Fri, 24 Oct 2008 13:15:49 -0700 (PDT), Mike Driscoll <[EMAIL PROTECTED]> wrote: >On Oct 24, 2:53 pm, Rex <[EMAIL PROTECTED]> wrote: >> By the way, if you're doing non-trivial web scraping, the mechanize >> module might make your work much easier. You can install it with >> easy_install.http://ww

Re: [newbie] Right way to access item in array?

2008-10-28 Thread Gilles Ganault
On Tue, 28 Oct 2008 12:12:26 +0100, Gerhard Häring <[EMAIL PROTECTED]> wrote: >You can do it even in one step with APSW (and pysqlite, and others): > >for isbn, price in cur.execute("select isbn, price ..."): Thanks much guys. For those interested, here's some working code: == import apsw co

Re: [newbie] Right way to access item in array?

2008-10-28 Thread Gilles Ganault
On Tue, 28 Oct 2008 09:56:11 -0400, Steve Holden <[EMAIL PROTECTED]> wrote: >If you are dealing with a DB API-compliant module then the return value >from the cursor's execute method is undefined, and you need to call one >of the "fetch" methods to extract the retrieved data. Thanks for pointing i

[2.5.1] "UnicodeDecodeError: 'ascii' codec can't decode byte"?

2008-10-29 Thread Gilles Ganault
Hello I'm getting this error while downloading and parsing web pages: = title = m.group(1) UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 48: ordinal not in range(128) = >From what I understand, it's because some strings are Unicode, and hence contain character

[2.5.1] Building loop with some exceptions?

2008-11-04 Thread Gilles Ganault
Hello I need to call a URL through a loop that starts at 01 and ends at 99, but some of the steps must be ignored: = url = "http://www.acme.com/list?code="; p = re.compile("^(\d+)\t(.+)$") for i=01 to 99 except 04, 34, 40, 44, 48, 54, 57, 67, 76, 83, 89: f = urllib.urlopen(url + i)

Re: Building loop with some exceptions?

2008-11-04 Thread Gilles Ganault
On Tue, 4 Nov 2008 11:22:27 -0800 (PST), Aaron Brady <[EMAIL PROTECTED]> wrote: >> for i=01 to 99 except 04, 34, 40, 44, 48, 54, 57, 67, 76, 83, 89: > >sorted( list( set( domain ) - set( exceptions ) ) ) > >Set subtraction. Thanks a lot but... I don't know what the above means :-/ -- http://mail.p

Re: Building loop with some exceptions?

2008-11-04 Thread Gilles Ganault
On Tue, 4 Nov 2008 12:10:28 -0800 (PST), Matimus <[EMAIL PROTECTED]> wrote: >I would just do something like this (not tested): Thanks a lot guys :-) Worked first time. I just have the usual issue with ASCII/Unicode: === cursor.execute(sql) UnicodeDecodeError: 'ascii' codec can't decode b

[urllib2 + Tor] How to handle 404?

2008-11-07 Thread Gilles Ganault
Hello I'm using the urllib2 module and Tor as a proxy to download data from the web. Occasionnally, urlllib2 returns 404, probably because of some issue with the Tor network. This code doesn't solve the issue, as it just loops through the same error indefinitely: = for id in rows:

Re: [2.5.1] Building loop with some exceptions?

2008-11-07 Thread Gilles Ganault
On 04 Nov 2008 22:34:49 GMT, Steven D'Aprano <[EMAIL PROTECTED]> wrote: >for i in range(1, 100): >if i in (4, 34, 40, 44, 48, 54, 57, 67, 76, 83, 89): >continue >do_rest_of_processing Thanks for the sample. -- http://mail.python.org/mailman/listinfo/python-list

Re: Building loop with some exceptions?

2008-11-07 Thread Gilles Ganault
On Tue, 4 Nov 2008 15:55:06 -0800 (PST), alex23 <[EMAIL PROTECTED]> wrote: > exclusions = [04, 34, 40, 44, 48, 54, 57, 67, 76, 83, 89] > for i in (x for x in xrange(1,100) if x not in exclusions): Thanks guys. -- http://mail.python.org/mailman/listinfo/python-list

[Newbie] Strange output from list

2008-11-10 Thread Gilles Ganault
Hello I'm getting some unwanted result when SELECTing data from an SQLite database: == sql = 'SELECT id FROM master' rows=list(cursor.execute(sql)) for id in rows: sql = 'SELECT COUNT(code) FROM companies WHERE code="%s"' % id[0] result = list(cursor.execute(sql)) prin

Re: [Newbie] Strange output from list

2008-11-11 Thread Gilles Ganault
On Mon, 10 Nov 2008 20:02:39 -0600, Andrew <[EMAIL PROTECTED]> wrote: >sql = 'SELECT id FROM master' >rows=list(cursor.execute(sql)) >for id in rows: > sql = 'SELECT COUNT(code) FROM companies WHERE code="%s"' % id[0] > result = list(cursor.execute(sql)) > print "Code=%s, number=%

Re: Does Python mess with CRLFs?

2008-11-12 Thread Gilles Ganault
On Wed, 12 Nov 2008 12:04:07 +0100, Gilles Ganault <[EMAIL PROTECTED]> wrote: >I wonder if Python rewrites CRLFs when reading a text file with >open/read? For those seeing the same thing, the answer is yes: On Windows, the code above turns CRLF into LF. I tried "rb" i

Does Python mess with CRLFs?

2008-11-12 Thread Gilles Ganault
Hello I'm stuck at understanding why Python can't extract some bit from an HTML file using regexes, although I can find it just fine with UltraEdit. I wonder if Python rewrites CRLFs when reading a text file with open/read? Here's the code: == f = open("content.html", "r") content = f.r

[Array] Finding index that contains part of a string?

2008-11-12 Thread Gilles Ganault
Hello Out of curiosity, is there a better way in Python to iterate through an array, and return the index of each item that contains the bit somewhere in its value, ie. index() doesn't work because it only returns if the value only contains the item I'm looking for. This works: next = re

[Regex] Search and replace?

2008-11-13 Thread Gilles Ganault
Hello I need to iterate through a variable, and for each pattern that matches, replace this with something else. I read the chapter in www.amk.ca/python/howto/regex/, but the output is wrong: === #Extract two bits, and rewrite the HTML person = re.compile('.+?)>.+?', input) === Does som

[UnicodeEncodeError] Don't know what else to try

2008-11-14 Thread Gilles Ganault
Hello Data that I download from the web seems to be using different code pages at times, and Python doesn't like this. Google returned a way to handle this, but I'm still getting an error: print output.decode('utf-8') File "C:\Python25\lib\encodings\utf_8.py", line 16, in decode

Re: [UnicodeEncodeError] Don't know what else to try

2008-11-14 Thread Gilles Ganault
On Fri, 14 Nov 2008 11:01:27 +0100, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote: >Add >print type(output) >here. If it says "unicode", reconsider the next line > >> print output.decode('utf-8') In case the string fetched from a web page turns out not to

Proxy + cookie: urllib2? httplib2? Other?

2008-11-14 Thread Gilles Ganault
Hello I need a library that supports both going out through a proxy, and handling cookies automagically (the server uses a sessionID to keep track of the user). UrlLib2 supports the proxy part, httplib2 supports the cookie part but... Google didn't return code that shows both uses in the same lib

<    1   2   3   >