[issue10574] email.header.decode_header fails if the string contains multiple directives

2010-11-28 Thread Roy H. Han

New submission from Roy H. Han starsareblueandfara...@gmail.com:

email.header.decode_header fails for the following message subject:
::


email.header.decode_header('=?UTF-8?B?MjAxMSBBVVRNIENBTEwgZm9yIE5PTUlO?==?UTF-8?B?QVRJT05TIG9mIFZQIGZvciBNZW1iZXJz?==?UTF-8?B?aGlw?=')


If the directives are removed and the padding problems are fixed, the subject 
parses correctly.
::

email.header.decode_header('=?UTF-8?B?%s==?=' % 
'=?UTF-8?B?MjAxMSBBVVRNIENBTEwgZm9yIE5PTUlO?==?UTF-8?B?QVRJT05TIG9mIFZQIGZvciBNZW1iZXJz?==?UTF-8?B?aGlw?='.replace('=?UTF-8?B?',
 '').replace('?', '').replace('=', ''))

--
components: Library (Lib)
messages: 122772
nosy: starsareblueandfaraway
priority: normal
severity: normal
status: open
title: email.header.decode_header fails if the string contains multiple 
directives
type: behavior
versions: Python 2.6, Python 2.7, Python 3.1

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10574
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1598] unexpected response in imaplib

2009-03-24 Thread Roy H. Han

Roy H. Han starsareblueandfara...@gmail.com added the comment:

I'm also getting the same error retrieving a message through IMAP from a
Lotus Notes server.


Traceback (most recent call last):
  File mail.py, line 152, in module
if 'setup' == argument: setup()
  File mail.py, line 61, in archive
for message in imapBox.read(includes=includes,
excludes=[mail_store_imap.folder_trash]):
  File /var/www/pylons/scout/scout/lib/mail_store_imap.py, line 89, in
read
returnCode, data = self.server.fetch(messageIndex, '(RFC822)')
  File /usr/lib/python2.5/imaplib.py, line 437, in fetch
typ, dat = self._simple_command(name, message_set, message_parts)
  File /usr/lib/python2.5/imaplib.py, line 1055, in _simple_command
return self._command_complete(name, self._command(name, *args))
  File /usr/lib/python2.5/imaplib.py, line 887, in _command_complete
raise self.abort('command: %s = %s' % (name, val))
imaplib.abort: command: FETCH = unexpected response: ')'

--
nosy: +starsareblueandfaraway

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1598
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1598] unexpected response in imaplib

2009-03-24 Thread Roy H. Han

Roy H. Han starsareblueandfara...@gmail.com added the comment:

Using a different format, it seems the message involves cryptographic
keys signed by Lotus Notes?

 server.fetch(407, '(BODY.PEEK[HEADER] FLAGS)')

To: pers...@place.com
Subject: subject
Message-ID: x...@place.com
Date: Tue, 28 Oct 2008 17:53:22 -0400
From: per...@place.com
Content-Type: multipart/mixed; boundary==_mixed 007839E2852574F0_=
MIME-Version: 1.0
X-Mailer: Lotus Notes Release 7.0.2 September 26, 2006
X-MIMETrack: S/MIME Sign by Notes Client on Person(Release
7.0.2|September 26, 2006) at 10/28/2008 05:53:11 PM,Serialize by Notes
Client on Person(Release 7.0.2|September 26, 2006) at 10/28/2008
05:53:11 PM,Serialize complete at 10/28/2008 05:53:11 PM,S/MIME Sign
failed at 10/28/2008 05:53:11 PM: The cryptographic key was not
found,S/MIME Sign by Notes Client on Person(Release 7.0.2|September 26,
2006) at 10/28/2008 05:53:19 PM,Serialize by Notes Client on
Person(Release 7.0.2|September 26, 2006) at 10/28/2008 05:53:19
PM,Serialize complete at 10/28/2008 05:53:20 PM,S/MIME Sign failed at
10/28/2008 05:53:20 PM: The cryptographic key was not found

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1598
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Using xreadlines

2009-02-27 Thread Roy H. Han
Brett,

I'm not sure what exactly you're trying to do, but you can keep track
of line numbers using itertools.

import itertools
for lineIndex, line in itertools.izip(itertools.count(1), open('text.txt')):
print lineIndex, line


Here is sample code for breaking on a word and returning the previous line

def breakOnWord(filePath, word):
previousLine = ''
for line in open(filePath):
if word in line:
return previousLine
previousLine = line



On Fri, Feb 27, 2009 at 11:43 AM,  bearophileh...@lycos.com wrote:
 Brett Hedges:
 How would I keep track of the absolute position of the lines?

 You may have to do all things manually (tell, seek and looking for
 newlines manually, iterating chars), that's why I have said it's not
 handy. The other solutions are simpler.

 Bye,
 bearophile
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Re: Using xreadlines

2009-02-27 Thread Roy H. Han
On Fri, Feb 27, 2009 at 12:20 PM, Scott David Daniels
scott.dani...@acm.org wrote:
 (1) Please do not top post in comp.lang.python, it violates conventions.

 Brett Hedges (should have written):
 bearophile wrote: ...

 You can also keep track of the absolute position of the lines in the
 file, etc, or step

 back looking for newlines, etc, but it's not handy

 How would I keep track of the absolute position of the lines?

 I have tried to use the files.seek() command with the files.tell()
 command and it does not seem to work. The files.tell() command seems
  to give me a number but when I use the files.next() command with
 xreadlines it does not change the line number the next time I use
 files.tell().

 The answer to your question depends on what version of Python you are
 running.  Give python version and platform to any question when you
 don't _know_ they are irrelevant.

 If you want an answer without any other input, try this:

 The simplest way to solve this for the moment is (re)defining
 xreadlines:

    def xreadlines(source):
        for line in iter(src.readline, ''):
            yield line

 --Scott David Daniels
 scott.dani...@acm.org
 --
 http://mail.python.org/mailman/listinfo/python-list


Sorry for top-posting.
http://en.wikipedia.org/wiki/Posting_style
--
http://mail.python.org/mailman/listinfo/python-list


Re: How do I decode unicode characters in the subject using email.message_from_string()?

2009-02-25 Thread Roy H. Han
Thanks for writing back, RDM and John Machin.  Tomorrow I'll try the
code you suggested, RDM.  It looks quite helpful and I'll report the
results.

In the meantime, John asked for more data.  The sender's email client
is Microsoft Outlook 11.  The recipient email client is Lotus Notes.



Actual Subject
=?us-ascii?Q?Inteum_C/SR_User_Tip:__Quick_Access_to_Recently_Opened_Inteu?=\r\n\t=?us-ascii?Q?m_C/SR_Records?=

Expected Subject
Inteum C/SR User Tip: Quick Access to Recently Opened Inteum C/SR Records

X-Mailer
Microsoft Office Outlook 11

X-MimeOLE
Produced By Microsoft MimeOLE V6.00.2900.5579



RHH



On Wed, Feb 25, 2009 at 8:39 AM,  rdmur...@bitdance.com wrote:
 John Machin sjmac...@lexicon.net wrote:
 On Feb 25, 11:07=A0am, Roy H. Han starsareblueandfara...@gmail.com
 wrote:
  Dear python-list,
 
  I'm having some trouble decoding an email header using the standard
  imaplib.IMAP4 class and email.message_from_string method.
 
  In particular, email.message_from_string() does not seem to properly
  decode unicode characters in the subject.
 
  How do I decode unicode characters in the subject?

 You don't. You can't. You decode str objects into unicode objects. You
 encode unicode objects into str objects. If your input is not a str
 object, you have a problem.

 I can't speak for the OP, but I had a similar (and possibly
 identical-in-intent) question.  Suppose you have a Subject line that
 looks like this:

    Subject: 'u' Obselete type =?ISO-8859-1?Q?--_it_is_identical_?=   
 =?ISO-8859-1?Q?to_=27d=27=2E_=287=29?=

 How do you get the email module to decode that into unicode?  The same
 question applies to the other header lines, and the answer is it isn't
 easy, and I had to read and reread the docs and experiment for a while
 to figure it out.  I understand there's going to be a sprint on the
 email module at pycon, maybe some of this will get improved then.

 Here's the final version of my test program.  The third to last line is
 one I thought ought to work given that Header has a __unicode__ method.
 The final line is the one that did work (note the kludge to turn None
 into 'ascii'...IMO 'ascii' is what deocde_header _should_ be returning,
 and this code shows why!)

 ---
 from email import message_from_string
 from email.header import Header, decode_header

 x = message_from_string(\
 To: test
 Subject: 'u' Obselete type =?ISO-8859-1?Q?--_it_is_identical_?=   
 =?ISO-8859-1?Q?to_=27d=27=2E_=287=29?=

 this is a test.
 )

 print x
 print 
 for key, header in x.items():
    print key, 'type', type(header)
    print key+:, unicode(Header(header)).decode('utf-8')
    print key+:, decode_header(header)
    print key+:, ''.join([s.decode(t or 'ascii') for (s, t) in 
 decode_header(header)]).encode('utf-8')
 ---


    From nobody Wed Feb 25 08:35:29 2009
    To: test
    Subject: 'u' Obselete type =?ISO-8859-1?Q?--_it_is_identical_?=
            =?ISO-8859-1?Q?to_=27d=27=2E_=287=29?=

    this is a test.

    
    To type type 'str'
    To: test
    To: [('test', None)]
    To: test
    Subject type type 'str'
    Subject: 'u' Obselete type =?ISO-8859-1?Q?--_it_is_identical_?=   
 =?ISO-8859-1?Q?to_=27d=27=2E_=287=29?=
    Subject: [('u' Obselete type, None), (-- it is identical to 'd'. (7), 
 'iso-8859-1')]
    Subject: 'u' Obselete type-- it is identical to 'd'. (7)


 --RDM

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

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


Re: How do I decode unicode characters in the subject using email.message_from_string()?

2009-02-25 Thread Roy H. Han
Cool, it works!

Thanks, RDM, for stating the right approach.
Thanks, Steve, for teaching by example.

I wonder why the email.message_from_string() method doesn't call
email.header.decode_header() automatically.


On Wed, Feb 25, 2009 at 9:50 AM,  rdmur...@bitdance.com wrote:
 Steve Holden st...@holdenweb.com wrote:
  from email.header import decode_header
  print
 decode_header(=?us-ascii?Q?Inteum_C/SR_User_Tip:__Quick_Access_to_Recently_Opened_Inteu?=\r\n\t=?us-ascii?Q?m_C/SR_Records?=)
 [('Inteum C/SR User Tip:  Quick Access to Recently Opened Inteum C/SR
 Records', 'us-ascii')]
 

 It is interesting that decode_header does what I would consider to be
 the right thing (from a pragmatic standpoint) with that particular bit
 of Microsoft not-quite-standards-compliant brain-damage; but, removing
 the tab is not in fact standards compliant if I'm reading the RFC
 correctly.

 --RDM

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

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


How do I decode unicode characters in the subject using email.message_from_string()?

2009-02-24 Thread Roy H. Han
Dear python-list,

I'm having some trouble decoding an email header using the standard
imaplib.IMAP4 class and email.message_from_string method.

In particular, email.message_from_string() does not seem to properly
decode unicode characters in the subject.

How do I decode unicode characters in the subject?

I read on the documentation that the email module supports RFC 2047.
But is there a way to make imaplib.IMAP4 and email.message_from_string
use this protocol?  I'm using Python 2.5.2 on Fedora.  Perhaps this
problem has been fixed already in Python 2.6.

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


Re: Where to host a (Python) project?

2009-01-31 Thread Roy H. Han
I really like WebFaction for web-based Python projects.  It's a paid
web-hosting service, though.  What I like is how they always have the
most up-to-date Python packages and frameworks using one-click
installers.

On Sat, Jan 31, 2009 at 4:30 PM, andrew cooke and...@acooke.org wrote:
 On Jan 31, 4:50 pm, Giampaolo Rodola' gne...@gmail.com wrote:
 Google Code.

 --- Giampaolohttp://code.google.com/p/pyftpdlib

 thanks - that's a nice example.  i'm a bit concerned about the whole
 google corporation thing, but reading through the ideological check-
 sheet at savannah convinced me i wasn't worthy and your project looks
 good (i admit i haven't seen that many google projects, but they all
 seemed abandoned/bare/hostile).  so i'll follow the majority here and
 give google code a go.

 cheers,
 andrew
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Re: RELEASED Python 3.0 final

2008-12-04 Thread Roy H. Han
Hi,

This is great, however, the link to the What's New page appears to be
broken.
http://docs.python.org/dev/3.0/whatsnew/3.1.html

RHH

On Thu, Dec 4, 2008 at 8:37 AM, Istvan Albert [EMAIL PROTECTED]wrote:

 Congratulations on a fantastic work!
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Re: Is there a faster way to do this?

2008-08-05 Thread Roy H. Han
Why not just use sets?

a = set()
a.add(1)
a.add(2)

On Tue, Aug 5, 2008 at 10:14 PM, RPM1 [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] wrote:

 I have a csv file containing product information that is 700+ MB in
 size. I'm trying to go through and pull out unique product ID's only
 as there are a lot of multiples. My problem is that I am appending the
 ProductID to an array and then searching through that array each time
 to see if I've seen the product ID before. So each search takes longer
 and longer. I let the script run for 2 hours before killing it and had
 only run through less than 1/10 if the file.


 I think you need to learn about Python's dictionary data type.
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Re: % sign in python?

2008-07-17 Thread Roy H. Han
The percent sign is a placeholder.

For example, if
level = 1
msg = 'look'

Then
'[[Log level %d: %s]]' % ( level, msg )
becomes
'[[Log level 1: look]]'

%d means insert an integer
%s means insert a string

You can also use dictionaries.
d = {'string1': 'hey', 'string2': 'you'}
Then
'%(string1)s %(string2)s' % d
becomes 'hey you'


On Thu, Jul 17, 2008 at 10:33 AM, korean_dave [EMAIL PROTECTED] wrote:
 What does this operator do? Specifically in this context

 test.log( [[Log level %d: %s]] % ( level, msg ), description )

 (Tried googling and searching, but the % gets interpreted as an
 operation and distorts the search results)
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Re: property getter with more than 1 argument?

2008-07-17 Thread Roy H. Han
I don't understand what you're trying to do here.


On Thu, Jul 17, 2008 at 10:57 AM, mk [EMAIL PROTECTED] wrote:

 It seems like getter is defined in such way that it passes only 'self':


 class FunDict(dict):
def __init__(self):
self.fundict = dict()

def fget(self, fun):
return fundict[fun.func_name]

def fset(self, newfun):
self.fundict[newfun.func_name] = newfun

newfun = property (fget, fset)


 a=FunDict()

 a.newfun=f1

 a.newfun('f1')

 Traceback (most recent call last):
  File pyshell#67, line 1, in module
a.newfun('f1')
 TypeError: fget() takes exactly 2 arguments (1 given)



 Is it possible to pass more than one argument to fget function?

 I know: I can define a function with property name ('newfun' in the example)
 and call it with more arguments. But then I do not get the benefits of
 setter and property in general!

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

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


Re: Pythonwin

2008-05-09 Thread Roy H. Han
Hi Clive,

For ArcGIS, I use plain old VIM, IPython and IDLE.

If you really want PythonWin, then you can download Mark Hammond's Python
for Windows extensions: http://sourceforge.net/projects/pywin32/

Note also that with the pywin32 extensions, you can also use Python 2.5 to
access ArcGIS using

from win32com.client import Dispatch
arcgis = Dispatch('esriGeoprocessing.GpDispatch')

If you just need to access shapefiles, there is shapelib:
http://shapelib.maptools.org/
To make shapelib bindings for Python 2.5
1. Download *shapelib_1_2_10.zip *from http://dl.maptools.org/dl/shapelib/
2. Download *pyshapelib-0.3.zip* from
ftp://intevation.de/users/bh/pyshapelib
3. Extract *pyshapelib-0.3.zip*
4. Extract *shapelib_1_2_10.zip* to the folder containing pyshapelib.
Rename the extracted folder as *shapelib*
5. From the pyshapelib directory, run python setup.py build.  The script
looks in its parent folder for the shapelib folder.
5. From the pyshapelib directory, python setup.py install

Hope that helps,
Roy
**
On Fri, May 9, 2008 at 6:46 AM, Niklas Norrthon [EMAIL PROTECTED]
wrote:

 On 9 Maj, 12:30, Clive_S [EMAIL PROTECTED] wrote:
  Hi
 
  I am trying to use Python with ArcGIS.
 
  I have installed Python 2.4. I have an icon for IDLE and command line.
  I do not see Python PythonWin.
 
  How do you install or launch pythonwin??

 There is a distribution of PythonWin bundled with the
 ArcGIS Desktop installation media, but it is not
 installed by the ArcGIS installer.

 You have three options:
 1. Install it manually from the ArcGIS installation
 media.
 2. Find it on the web (google for it), download and
 install.
 3. (My recommendation) Don't bother. IDLE is pretty
 good. Emacs even better (unless you hate emacs).

 --
 Niklas Norrthon
 ESRI S-GROUP
 --
 http://mail.python.org/mailman/listinfo/python-list

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

Re: Question.

2008-04-04 Thread Roy H. Han
Your boyfriend is pretty funny.  I tried to get my girlfriend to learn
Python a long time ago but she doesn't see value in it.

On Fri, Apr 4, 2008 at 12:31 AM, AJay Grimmett [EMAIL PROTECTED] wrote:

 My name is Amanda. My boyfriend sent me an encrypted message by using
 python. I guess he thought it would be fun for me to figure it out for
 myself. This one involes a whole lotta numbers. I can't read or understand
 what I am supposed to do to read this message. I mean, I've read the
 information, but I seriously do not understand. He sent the .py file, and
 the messages that were encrypted...i just don't know how to use it to get to
 the message where I can read it. Is there anyway you or someone could do it
 step by step..or just do it for me?! lol. I just need to know what this
 says. Apparently it's an important message and I must read it. =] Thank you
 for your time. I hope to hear from you soon!
 -amanda

 --
 You rock. That's why Blockbuster's offering you one month of Blockbuster
 Total 
 Accesshttp://us.rd.yahoo.com/evt=47523/*http://tc.deals.yahoo.com/tc/blockbuster/text5.com,
 No Cost.
 --
 http://mail.python.org/mailman/listinfo/python-list

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

Re: Python-by-example - new online guide to Python Standard Library

2008-04-01 Thread Roy H. Han
Learning by example is the best.  I remember working through a book when I
was little called Qbasic by Example.

On Tue, Apr 1, 2008 at 9:15 PM, AK [EMAIL PROTECTED] wrote:

 Hello,

 I find that I learn easier when I go from specific examples to a more
 general explanation of function's utility and I made a reference guide
 that will eventually document all functions, classes and methods in
 Python's Standard Library. For now, I covered about 20 most important
 modules. I will be adding more modules and eventually I'll cover
 everything. Here's my progress so far, let me know if this is useful;
 I'll be glad to hear comments/suggestions/etc:

 http://www.lightbird.net/py-by-example/

 --
  -ak
   Tobu | http://www.lightbird.net/tobu/ | Freeform DB / Tagger / PIM
 --
 http://mail.python.org/mailman/listinfo/python-list

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

Re: Where's GUI for Python?

2008-03-02 Thread Roy H. Han
Hi Konrad,

I remember taking a long time in deciding which GUI framework to use last
year and I picked wxGlade/wxPython because it seemed mature, easy to use and
easy to understand.

In the beginning I wasted a lot of time coding the GUI manually but wxGlade
lets me use the mouse to arrange the components so that I can focus on
writing the event handling code.  I mostly don't touch the code that wxGlade
auto-generates and I work my code around it.
http://wxglade.sourceforge.net/demo/

Sorry I responded to your personal email by mistake.  I pressed Reply All in
gmail.

I don't know who wrote wxGlade or wxPython but both have been real
timesavers to me.

Roy

On Sun, Mar 2, 2008 at 3:50 AM, Konrad Viltersten [EMAIL PROTECTED]
wrote:

  Konrad, I use wxPython with wxGlade.
  I love wxGlade!
  wxGlade http://wxglade.sourceforge.net/
  You need to look at this documentation to
  code event handling. wxWidgets:
  http://www.wxwidgets.org/manuals/stable/wx_classesbycat.html
 
  You can also try coding the GUI manually,
  but it is much easier to use wxGlade.
  wxPython
  http://wiki.wxpython.org/AnotherTutorial

 May i ask what's the advantage in using
 wxGlade instead of the buil-in Tkinter?

 Also - why did you replied to my private
 email instead of to news? Is the choice of
 GUI an infected matter among the Python
 community, by any chance?

 --
 Regards
 Konrad Viltersten

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

Re: Where's GUI for Python?

2008-03-01 Thread Roy H. Han
Konrad, I use wxPython with wxGlade.

I love wxGlade!
wxGlade http://wxglade.sourceforge.net/

You need to look at this documentation to code event handling.
wxWidgets http://www.wxwidgets.org/manuals/stable/wx_classesbycat.html

You can also try coding the GUI manually, but it is much easier to use
wxGlade.
wxPython http://wiki.wxpython.org/AnotherTutorial

Roy


On Sat, Mar 1, 2008 at 5:05 PM, Tim Chase [EMAIL PROTECTED]
wrote:

  I'm certain there is an API for creating
  GUI's but as far i can find it in the
  http://docs.python.org/tut/tut.html
  the only gui is in Guido.
 
  What do i miss?


 The batteries-included GUI:

   import tkininter

 Add-on solutions include wxPython, PythonCard and many others.  GIYF:

   http://google.com/search?q=python+gui

 -tkc

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