Hasan Diwan | 2 Mar 01:17 2003

UnicodeError: ASCII encoding error: ordinal not in range(128)

I have a script to parse RSS feeds into HTML. Some of these RSS feeds
contain characters outside the 7-bit ASCII range, and the page is set to
display in utf8. My question is how to force the script below to output
strings in UTF8 as opposed to ASCII:
#!/sw/bin/python
from xml.dom import minidom
import string
import urllib
import time
import sys
import re
import zlib
#Change these to reflect your reality
class news:
	def load(self, url):
	 p=None
	 try:
	  p=minidom.parse(urllib.urlopen(url))
	 except:
	  print 'unreachable URL '+url,
	 return p
	DEFAULT_NAMESPACES = \
	  (None, # RSS 0.91, 0.92, 0.93, 0.94, 2.0
	   'http://purl.org/rss/1.0/', # RSS 1.0
	   'http://my.netscape.com/rdf/simple/0.9/' # RSS 0.90
	   )

	def getElementsByTagName(self, node, tagName, possibleNamespaces=DEFAULT_NAMESPACES):
	   for namespace in possibleNamespaces:
	      children = node.getElementsByTagName(tagName)
(Continue reading)

Paul Rubin | 6 Mar 18:35 2003

Re: unsigned integers

"Giovanni Bajo" <noway <at> sorry.com> writes:
> 1) How can I force 0xFFFFFFFF to be 4294967295 instead of -1? 

Say 0xFFFFFFFFL (the trailing L makes the literal into a long integer).

> 2) binascii.crc32() returns a signed integer representing the CRC. I call it
> signed because if I print the result it displays a signed number. Now, what
> if I need the unsigned representation of it (as in, the unsigned number
> which is machine-represented with the same 32 bits)? I need to multiply it
> by another integer, but I need an unsigned multiplication, not a signed one.

crc = binascii.crc32(...)
if crc < 0:
   crc += 0x100000000L

or something like that.

Hasan Diwan | 8 Mar 21:26 2003

Re: Perl Vs Python

	I've read lots of Python vs. Perl posts. I know both languages
and was wondering if there was a way to embed one inside the other so as
to decrease the amount of learning I have to do. As Python is cleaner,
I'd prefer to use Perl's DBI system in a python PyXML script. Is this
even possible? Thanks for the help!
--

-- 
Hasan Diwan <hdiwan <at> mac.com> OpenPGP keyID: 0x7EE3855B
http://ibn.com/~hdiwan 
Fingerprint: 42F0 5758 C3EB BA1F ABD2  ED49 3390 CCF0 7EE3 855B

Hasan Diwan | 9 Mar 17:38 2003

Re: DNS lookup

Alessio Pace <puccio_13 <at> yahoo.it> writes:

>Is there a portable way to do a DNS lookup? I am developing in Unix (Linux)
>but I would prefer avoiding the use of Unix specific command line tools. I
>need both translation from machine name to IP and from IP to machine name.
>Thanks.

I recently wrote a script that takes IPs on the command line and returns 
their hostnames. It is enclosed below. It has little error checking.
Feel free to improve on it if you wish:
import sys
import socket;
for x in sys.argv[1:]:
    try:	
     s = socket.gethostbyaddr(x)[0]
    except:
     print x + ' not found'
     continue
    print x+': '+s

--

-- 
Hasan Diwan <hdiwan <at> mac.com> OpenPGP keyID: 0x7EE3855B
http://ibn.com/~hdiwan 
Fingerprint: 42F0 5758 C3EB BA1F ABD2  ED49 3390 CCF0 7EE3 855B

Justin Sheehy | 10 Mar 16:00 2003

Re: interacting with gui-based programs

Mike Meyer <mwm <at> mired.org> writes:

> I wonder what it would take to get emacs python-mode
> to send a function to the python interpreter buffer?

It would take about two or three keystrokes.

Use M-C-x, C-c |, or C-c C-c depending on how much you want to send.

Use C-h m to see the mode documentation.

-Justin

дамјан г. | 11 Mar 22:20 2003

Re: Working example of extension class in C/C++ ?

> I recently started with making my own extension things in C/C++ for
> Python.  Extension functions work OK, but I have more difficulty in
> creating an extension class.
> 
> I would like to write an extension to access shared memory on Linux.

There already is a shared memory support in Pytohn, look at the mmap module.
What would be nice, though, is a shared-mem dictionary that also can store
its values in the sahred memory, thus creating a super-fast and simple
mmaped Python IPC.

--

-- 
Дамјан                                  (jabberid:damjan <at> bagra.net.mk)

      Anything you code can and will be used against you

Gerhard Häring | 11 Mar 23:49 2003
Picon

Re: Convert a C pgm

Benoit BESSE wrote:
> You're right, this is just a par of Application that list multicast
> directory session.
> The module have to parsed Session Description Protocol (RFC 2327).
> This is the main ()

Thi is still not complete. The .h file you posted earlier referenced
other header files in the same project.

I'll second Peter's suggestion of rewriting the whole thing from
scratch using the spec with unit tests.

As I personally have no need for a "Session Description Protocol" for
Multimedia apps (RFC 2327), it's unlikely I'd find the motivation to
create an implementation. Especially as I've a bunch of other more
interesting (to me) open-source projects to work on.

I have no idea what SDP is good for. A quick Google search suggests it
has some relation with SIP (Session Initiation Protocol), which I've
at least heard of before, but still don't know what it's all about ...

Gerhard
--

-- 
mail:   gh <at> ghaering.de
web:    http://ghaering.de/

дамјан г. | 12 Mar 02:43 2003

Re: Curses - Win/dos

>> There's an implimentation called pdcurses that's available for
>> Win32.  I've never used it, and have no idea if it's compatible
>> with the Python curses package.  AFAIK, there isn't a Win32
>> port of ncurses [the curses package used by Linux].
> 
> FWIW:
> 
>   pdcurses: http://pdcurses.sourceforge.net
>    ncurses: http://dickey.his.com/ncurses

While we are at the ncurses topic... does python support the ncursesw
libaries. As of ncurses-5.3 there is a compile-time option to produce
wide-ncurses libraries. These libraries have greatly improved Unicode nad
UTF-8 handling. 

So, can Python's curses module be made to work with ncursesw?

--

-- 
Дамјан                                  (jabberid:damjan <at> bagra.net.mk)

            Secret hacker rule #11: hackers read manuals.

Robin Dunn | 12 Mar 07:30 2003

ANNOUNCE: wxPython 2.4.0.5

Close on the heels of 2.4.04, wxPython 2.4.0.5 is now available for 
download at http://wxpython.org/download.php

wxPython is a popular cross platform GUI toolkit for the Python language 
that supports running Python apps on Win32, Mac OSX, and Linux/Unix 
systems, using native widgets and therefore natiove look and feel on the 
respective plafroms.

 From the webpage given above you can download source code, 
documentation and pre-built wxPython packages for various platforms and 
for various versions of Python (2.1, 2.2 or 2.3, except for OS X which 
only has a build for 2.3)

The 2.4.0.5 release solves several small but annoying bugs, and includes 
updates of the colourchooser and PyCrust pacakges.

For details of the 2.4.0.4 or earlier releases please look here: 
http://wxpython.org/CHANGES.txt

--

-- 
Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!

дамјан г. | 12 Mar 13:36 2003

Re: Working example of extension class in C/C++ ?

>> There already is a shared memory support in Pytohn, look at the mmap
>> module. What would be nice, though, is a shared-mem dictionary that also
>> can store its values in the sahred memory, thus creating a super-fast
>> and simple mmaped Python IPC.
> 
> mmap is a different API than shm.  The OP wants to wrap the SysV shared
> memory API - which does not involve files (except as a kludgey convention
> for constructing 'keys' to identify shm segments).

oh, but isn't SysV shm considered obsolete??
And I don't think there is nothing wrong with mmap.

btw I think there already is shm module for Python. I'm sure I've seen it
somewhere.

--

-- 
Дамјан                                  (jabberid:damjan <at> bagra.net.mk)

     The three Rs of Microsoft support: Retry, Reboot, Reinstall.


Gmane