Standardizing XML

2007-04-15 Thread ZeeGeek
Is there a module for python to standardize XML?  Since MSN Live Space
doesn't use standard XML in the posts, I want to standardize them so
that I can use them elsewhere.

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


Re: Standardizing XML

2007-04-15 Thread ZeeGeek
On Apr 15, 7:08 am, Jan Danielsson <[EMAIL PROTECTED]> wrote:
> ZeeGeek wrote:
> > Is there a module for python to standardize XML?  Since MSN Live Space
> > doesn't use standard XML in the posts, I want to standardize them so
> > that I can use them elsewhere.
>
>Hmm... XML _is_ standardized. If it doesn't follow the specs, then
> it's not XML. If you want to make XML out of something which isn't XML,
> you'll probably have to be a little more specific about how this other
> format works.

Thanks for correcting me.  I worded it inproperly.  For example, in
the code returned by Live Space, they use  instead of  so
that Blogger will complain that this tag is not valid because it
doesn't have a closing tag.  Another example is that the contents of a
lot of the tag attributes like "color" and "size" are not surrounded
by quotes.

>
> --
> Kind regards,
> Jan Danielsson

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


Re: Standardizing XML

2007-04-15 Thread ZeeGeek
On Apr 15, 1:13 pm, Jonathan Ballet <[EMAIL PROTECTED]> wrote:
> Le 15 Apr 2007 11:02:20 -0700,
> "ZeeGeek" <[EMAIL PROTECTED]> a écrit :
>
> > Thanks for correcting me.  I worded it inproperly.  For example, in
> > the code returned by Live Space, they use  instead of  so
> > that Blogger will complain that this tag is not valid because it
> > doesn't have a closing tag.  Another example is that the contents of a
> > lot of the tag attributes like "color" and "size" are not surrounded
> > by quotes.
>
> Maybe you can try BeautifulSoup module which aims to handle things like
> that :http://www.crummy.com/software/BeautifulSoup/

Wow, this tool is fantastic.  Thank you very much.

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


Re: Standardizing XML

2007-04-15 Thread ZeeGeek
On Apr 15, 1:13 pm, ZeD <[EMAIL PROTECTED]> wrote:
> ZeeGeek wrote:
> > in the code returned by Live Space, they use  instead of  so
> > that Blogger will complain that this tag is not valid because it
> > doesn't have a closing tag.  Another example is that the contents of a
> > lot of the tag attributes like "color" and "size" are not surrounded
> > by quotes.
>
> Are you sure it's xml? It sounds to me like "old" HTML

Yeah, I realized this after I read the first reply to my post. That
was a big mistake to word it XML.

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


socket and thread

2009-01-08 Thread ZeeGeek
I'm writing a small program which uses different threads to monitor an
IMAP mailbox and an RSS feed. If network is not available when the
program starts, both threads will sleep for a while and try again. It
seems that the first thread succeeds when the network becomes
available will cause the other thread to always give a gaierror "No
address associated with hostname". The weird thing is that this only
happens when the program starts with network unavailable. If network
is available when the program starts, both threads work well, even if
the network drops in the middle, the threads can recover properly when
the network comes back alive. Is Python socket thread-unsafe or is it
because of some other problems?

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


Re: default gettext localedir on windows

2008-05-20 Thread ZeeGeek
On May 17, 8:39 pm, Thorsten Kampe <[EMAIL PROTECTED]> wrote:
> * ZeeGeek (Sun, 4 May 2008 10:56:52 -0700 (PDT))
>
> > On May 5, 1:16 am, Thorsten Kampe <[EMAIL PROTECTED]> wrote:
> > > * ZeeGeek (Sun, 4 May 2008 08:59:05 -0700 (PDT))
>
> > > > Hi, what's the default localedir for gettext module on windows? In
> > > > Linux, it's /usr/share/locale. Where should I put the *.mo file in
> > > > order to make the translation work?
>
> > > %PYTHONHOME%\share\locale
>
> > I tried moving the *.mo file into %PYTHONHOME%\share\locale\zh_CN
> > \LC_MESSAGES, but still no luck. The following is the code snippet I
> > use:
>
> > import gettext
> > gettext.install('testprogram', unicode = True)
>
> The syntax is correct. Is the test program localised under Linux or
> Cygwin? If not then the error is somewhere in your application.

Yes, it's localized under linux.

> How did you try to set the language on Windows? It works for me on Vista
> with "set LANG=de" or "set LANGUAGE=de" while I think under XP it had to
> be "set LANG=de_DE" (LANGUAGE or de alone did not work if I remember
> correctly).

I'm using Simplified Chinese Windows, so I didn't set anything
specifically before firing up the program. I found that if I use
gettext.GNUTranslations to read in the .mo file, then it's localized.
But gettext.install doesn't work.
--
http://mail.python.org/mailman/listinfo/python-list


Re: default gettext localedir on windows

2008-05-20 Thread ZeeGeek
On May 21, 2:31 am, Thorsten Kampe <[EMAIL PROTECTED]> wrote:
> * ZeeGeek (Tue, 20 May 2008 09:31:27 -0700 (PDT))
>
>
>
> > On May 17, 8:39 pm, Thorsten Kampe <[EMAIL PROTECTED]> wrote:
> > > * ZeeGeek (Sun, 4 May 2008 10:56:52 -0700 (PDT))
> > > > On May 5, 1:16 am, Thorsten Kampe <[EMAIL PROTECTED]> wrote:
> > > > > * ZeeGeek (Sun, 4 May 2008 08:59:05 -0700 (PDT))
> > > > > > Hi, what's the default localedir for gettext module on windows? In
> > > > > > Linux, it's /usr/share/locale. Where should I put the *.mo file in
> > > > > > order to make the translation work?
>
> > > > > %PYTHONHOME%\share\locale
>
> > > > I tried moving the *.mo file into %PYTHONHOME%\share\locale\zh_CN
> > > > \LC_MESSAGES, but still no luck. The following is the code snippet I
> > > > use:
>
> > > > import gettext
> > > > gettext.install('testprogram', unicode = True)
>
> > > The syntax is correct. Is the test program localised under Linux or
> > > Cygwin? If not then the error is somewhere in your application.
>
> > Yes, it's localized under linux.
>
> > > How did you try to set the language on Windows? It works for me on Vista
> > > with "set LANG=de" or "set LANGUAGE=de" while I think under XP it had to
> > > be "set LANG=de_DE" (LANGUAGE or de alone did not work if I remember
> > > correctly).
>
> > I'm using Simplified Chinese Windows, so I didn't set anything
> > specifically before firing up the program. I found that if I use
> > gettext.GNUTranslations to read in the .mo file, then it's localized.
> > But gettext.install doesn't work.
>
> Well, then why don't you set the environment variable for testing!?

Yes, it works for the program strings by setting LANG to zh_CN. But
glade strings are not localized. I did call gtk.glade.bindtextdomain
and gtk.glade.textdomain, and it works in Linux.
--
http://mail.python.org/mailman/listinfo/python-list


email header decoding fails

2008-04-09 Thread ZeeGeek
It seems that the decode_header function in email.Header fails when
the string is in the following form,

'=?gb2312?Q?=D0=C7=C8=FC?=(revised)'

That's when a non-encoded string follows the encoded string without
any whitespace. In this case, decode_header function treats the whole
string as non-encoded. Is there a work around for this problem?

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


Re: email header decoding fails

2008-04-10 Thread ZeeGeek
On Apr 10, 4:31 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Wed, 09 Apr 2008 23:12:00 -0300, ZeeGeek <[EMAIL PROTECTED]> escribió:
>
> > It seems that the decode_header function in email.Header fails when
> > the string is in the following form,
>
> > '=?gb2312?Q?=D0=C7=C8=FC?=(revised)'
>
> > That's when a non-encoded string follows the encoded string without
> > any whitespace. In this case, decode_header function treats the whole
> > string as non-encoded. Is there a work around for this problem?
>
> That header does not comply with RFC2047 (MIME Part Three: Message Header
> Extensions for Non-ASCII Text)
>
> Section 5 (1)
>  An 'encoded-word' may replace a 'text' token (as defined by RFC 822)
>  in any Subject or Comments header field, any extension message
>  header field, or any MIME body part field for which the field body
>  is defined as '*text'. [...]
>  Ordinary ASCII text and 'encoded-word's may appear together in the
>  same header field.  However, an 'encoded-word' that appears in a
>  header field defined as '*text' MUST be separated from any adjacent
>  'encoded-word' or 'text' by 'linear-white-space'.
>
> Section 5 (3)
>  As a replacement for a 'word' entity within a 'phrase', for example,
>  one that precedes an address in a From, To, or Cc header.  [...]
>  An 'encoded-word' that appears within a
>  'phrase' MUST be separated from any adjacent 'word', 'text' or
>  'special' by 'linear-white-space'.

Thank you very much, Gabriel.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: email header decoding fails

2008-04-10 Thread ZeeGeek
On Apr 10, 5:18 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Thu, 10 Apr 2008 05:45:41 -0300, ZeeGeek <[EMAIL PROTECTED]> escribió:
>
> > On Apr 10, 4:31 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
> > wrote:
> >> En Wed, 09 Apr 2008 23:12:00 -0300, ZeeGeek <[EMAIL PROTECTED]>
> >> escribió:
>
> >> > It seems that the decode_header function in email.Header fails when
> >> > the string is in the following form,
>
> >> > '=?gb2312?Q?=D0=C7=C8=FC?=(revised)'
> >>  An 'encoded-word' that appears within a
> >>  'phrase' MUST be separated from any adjacent 'word', 'text' or
> >>  'special' by 'linear-white-space'.
>
> > Thank you very much, Gabriel.
>
> The above just says "why" decode_header refuses to decode it, and why it's
> not a bug. But if you actually have to deal with those malformed headers,
> some heuristics may help. By example, if you *know* your mails typically
> specify gb2312 encoding, or iso-8859-1, you may look for things that look
> like the example above and "fix" it.

Right now what I'm doing is to use re.sub(r'(=\?([^\?]*\?){3}=)', r'
\1 ', orig_string) to detect and place an extra white space before and
after every occurrence of an encoded string. Then the whole string is
compliant with the standard and decode_header can decode it properly.
-- 
http://mail.python.org/mailman/listinfo/python-list


default gettext localedir on windows

2008-05-04 Thread ZeeGeek
Hi, what's the default localedir for gettext module on windows? In
Linux, it's /usr/share/locale. Where should I put the *.mo file in
order to make the translation work?

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


Re: default gettext localedir on windows

2008-05-04 Thread ZeeGeek
On May 5, 1:16 am, Thorsten Kampe <[EMAIL PROTECTED]> wrote:
> * ZeeGeek (Sun, 4 May 2008 08:59:05 -0700 (PDT))
>
> > Hi, what's the default localedir for gettext module on windows? In
> > Linux, it's /usr/share/locale. Where should I put the *.mo file in
> > order to make the translation work?
>
> %PYTHONHOME%\share\locale

I tried moving the *.mo file into %PYTHONHOME%\share\locale\zh_CN
\LC_MESSAGES, but still no luck. The following is the code snippet I
use:

import gettext
gettext.install('testprogram', unicode = True)
--
http://mail.python.org/mailman/listinfo/python-list