473,508 Members | 2,342 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Python2.2 + mailbox. Bug????

Hi

This is my program:

#!/usr/bin/python
import sys
from mailbox import PortableUnixMailbox
tmp = sys.stdin
mbox = PortableUnixMailbox(tmp)
mbox.next()
....
....

When I execute: "./program.py < mboxfile.txt", there's no problem

But, if I execute: "cat mboxfile.txt | program.py" ... too bad!

the error:

Traceback (most recent call last):
File "./prueba.py", line 8, in ?
mbox.next()
File "/usr/lib/python2.2/mailbox.py", line 23, in next
self.fp.seek(self.seekp)
IOError: [Errno 29] Illegal seek

Why????? Thanks ALL!!
Jul 18 '05 #1
2 1519
hector wrote:
Hi

This is my program:

#!/usr/bin/python
import sys
from mailbox import PortableUnixMailbox
tmp = sys.stdin
mbox = PortableUnixMailbox(tmp)
mbox.next()
...
...

When I execute: "./program.py < mboxfile.txt", there's no problem

But, if I execute: "cat mboxfile.txt | program.py" ... too bad!

the error:

Traceback (most recent call last):
File "./prueba.py", line 8, in ?
mbox.next()
File "/usr/lib/python2.2/mailbox.py", line 23, in next
self.fp.seek(self.seekp)
IOError: [Errno 29] Illegal seek

Why????? Thanks ALL!!


Hello,
I assume that when you write "./program.py < mboxfile.txt", Python knows
that sys.stdin is a regular file, so it can do seek on it (for example,
go back to its beginning). When you write "cat mboxfile.txt |
program.py", the program cat outputs the file mboxfile.txt into
sys.stdin byte by byte, so you can't do seek on it.

Bye,
Noam
Jul 18 '05 #2
Am Freitag, 21. Mai 2004 18:18 schrieb Noam Raphael:
I assume that when you write "./program.py < mboxfile.txt", Python knows
that sys.stdin is a regular file, so it can do seek on it (for example,
go back to its beginning).
It's not Python that knows that you can do a seek on the file, but what the
shell does when you pipe a file to a program is to call filefd =
open(file,"r"); fdup2(filefd,0) (0 = stdin) just before the shell forks to
start the program. sys.stdin is always just connected to the filedescriptor 0
which was passed in, which in turn is connected to a file file-descriptor by
the shell, which in turn is seekable.
When you write "cat mboxfile.txt |
program.py", the program cat outputs the file mboxfile.txt into
sys.stdin byte by byte, so you can't do seek on it.


Now, when you pipe something into another program, exactly this gets
generated: a pipe is generated using readfd, writefd = pipe() whose write end
is connected to the stdout (fdup2(writefd,1); fd 1 = stdout) of the first
program when the shell forks to start it, and whose read end is connected to
stdin (fdup2(readfd,0); fd 0 = stdin, as before) of the second program, again
when the shell forks to start it. This means that sys.stdin of the Python
program, which again is connected to filedescriptor 0 is now connected to a
pipe file-descriptor. Pipes are not seekable, and that's exactly what the
exception is telling you.

So, what do we learn from this? The mbox format needs a filedescriptor which
is seekable to be able to parse it (err, I guess it wouldn't need this, but
who knows, look at the source luke!), so you need to pass a reference to a
file-like object which implements seek (or at least a file-descriptor which
is seekable, which pipes are not).

HTH!

Heiko.

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3063
by: Adil Hasan | last post by:
Hello, I'm having problems trying to use ZSI to connect to a https url. I give the command and I get prompted for my X509 cert pass-phrase, but the program dies with an openssl error. Here's my...
6
7704
by: chuck amadi | last post by:
Hi , Im trying to parse a specific users mailbox (testwwws) and output the body of the messages to a file ,that file will then be loaded into a PostGresql DB at some point . I have read the...
0
1262
by: David Stockwell | last post by:
Hi, After looking at http://docs.python.org/lib/module-mailbox.html I am a bit confused. The bottom of the page refers to some shortcut usage for getting a mail box import email import...
5
4859
by: Michael | last post by:
Hello, I've created an ASP web page where users in our organization can create Active Directory computer accounts. The web page is running on a Server 2003 SP1 IIS 6 installation. The...
15
5534
by: Christopher Taylor | last post by:
RHEL comes with Python2.3 installed. A program I need to install requires Python2.4 So I got Python2.4 from source and compiled it up. I configured it with --prefix=/usr --exec-prefix=/usr...
0
2382
by: arjen1984 | last post by:
I want to create a mailbox-enabled mailbox. First i have used the toturial from microsoft: http://support.microsoft.com/kb/313114 Then my homeMDB string was incorrect. I saw an article , link:...
0
1426
by: jesse.k.rosenthal | last post by:
Dear all, I'm trying to figure out if mailbox will let me get the flags of a Maildir message without running get_message on it, and reading the whole message. It seems like it should work by...
2
1998
by: tinnews | last post by:
I am trying to write a utility to remove empty maildir mailboxes. It sounds like this should be very simple but it's proving really difficult. I'm doing this on a Fedora 7 system with python...
3
2893
by: Ice Vato | last post by:
Hi there, i am trying to get the size of a user's mailbox Outlook 2003, using visual studio2005 , C#... The problem is i get an error when running the foll code... NOTE: servername = name of...
0
7229
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7129
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7398
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5637
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3208
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1566
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.