473,795 Members | 3,175 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

string.encode on HP-UX

Using Python-2.3.4 on HP-UX11i, the following code:

import locale
loc = locale.setlocal e(locale.LC_ALL )
print 'locale =', loc
loc = locale.nl_langi nfo(locale.CODE SET)
print 'locale =', loc
print 'hello'.encode( loc, 'replace')

produces:

locale = C C C C C C
locale = roman8
Traceback (most recent call last):
File "test_locale.py ", line 13, in ?
print 'hello'.encode( loc, 'replace')
LookupError: unknown encoding: roman8
[The same code on SUSE 9.1 doesn't raise an exception].

Should I be able to pass the value returned by nl_langinfo() to the
string.encode call?

Similar code is used by wxGlade and this exception prevents it from
running.

Does anybody know how to fix this on HP-UX?

--
Richard Townsend
Jul 18 '05 #1
12 2702
Richard Townsend <ri******@edshk .demon.co.uk> writes:
Using Python-2.3.4 on HP-UX11i, the following code:

import locale
loc = locale.setlocal e(locale.LC_ALL )
print 'locale =', loc
loc = locale.nl_langi nfo(locale.CODE SET)
print 'locale =', loc
print 'hello'.encode( loc, 'replace')

produces:

locale = C C C C C C
locale = roman8
Traceback (most recent call last):
File "test_locale.py ", line 13, in ?
print 'hello'.encode( loc, 'replace')
LookupError: unknown encoding: roman8
[The same code on SUSE 9.1 doesn't raise an exception].

Should I be able to pass the value returned by nl_langinfo() to the
string.encode call?


What is roman8? If it's some hp-ux specific thingy, I guess the
solution is to teach Python what to do with it. If it's just HP's
name for iso-8859-1 or something then this is easy (mucking with
encodings.alias es).

If it's some custom encoding, finding out what unicode codepoint each
octet maps to and writing a codec a la macroman can't be impossibly
hard.

I guess a patch would be welcome either way.

Cheers,
mwh

--
Windows 2000: Smaller cow. Just as much crap.
-- Jim's pedigree of operating systems, asr
Jul 18 '05 #2
On Wed, 21 Jul 2004, Richard Townsend wrote:
Using Python-2.3.4 on HP-UX11i, the following code:

import locale
loc = locale.setlocal e(locale.LC_ALL )
print 'locale =', loc
loc = locale.nl_langi nfo(locale.CODE SET)
print 'locale =', loc
print 'hello'.encode( loc, 'replace')

produces:

locale = C C C C C C
locale = roman8
Traceback (most recent call last):
File "test_locale.py ", line 13, in ?
print 'hello'.encode( loc, 'replace')
LookupError: unknown encoding: roman8

[The same code on SUSE 9.1 doesn't raise an exception].


My guess is roman8 is HP-UX's version of latin_1. Setting an alias fixes
this:
import encodings
encodings.alias es.aliases['roman8']='latin_1'
'hello'.encode( 'roman8')

'hello'

You can add those first two lines to a sitecustomize.p y file, located
somewhere in your Python path (generally ~/site-packages/ or
/usr/local/lib/python2.X/ should work).

Jul 18 '05 #3
Christopher T King <sq******@WPI.E DU> writes:
My guess is roman8 is HP-UX's version of latin_1. Setting an alias fixes
this:


No, HP Roman-8 is *not* the same as Latin 1 (ISO 8859-1). You can
find a table at, e.g., <http://www.kostis.net/charsets/hproman8.htm>.

--
Michael Piotrowski, M.A. <mx*@dynalabs.d e>
Public key at <http://www.dynalabs.de/mxp/pubkey.txt>
Jul 18 '05 #4
On Wed, 21 Jul 2004, Michael Piotrowski wrote:
Christopher T King <sq******@WPI.E DU> writes:
My guess is roman8 is HP-UX's version of latin_1. Setting an alias fixes
this:


No, HP Roman-8 is *not* the same as Latin 1 (ISO 8859-1). You can
find a table at, e.g., <http://www.kostis.net/charsets/hproman8.htm>.


Well, the first 128 characters are the same. I'd say that's close enough,
right?
;)

Jul 18 '05 #5
Christopher T King <sq******@WPI.E DU> writes:
On Wed, 21 Jul 2004, Michael Piotrowski wrote:
Christopher T King <sq******@WPI.E DU> writes:
My guess is roman8 is HP-UX's version of latin_1. Setting an alias fixes
this:


No, HP Roman-8 is *not* the same as Latin 1 (ISO 8859-1). You can
find a table at, e.g., <http://www.kostis.net/charsets/hproman8.htm>.


Well, the first 128 characters are the same. I'd say that's close enough,
right?
;)


For Americans, perhaps ;-)

--
Michael Piotrowski, M.A. <mx*@dynalabs.d e>
Public key at <http://www.dynalabs.de/mxp/pubkey.txt>
Jul 18 '05 #6
Hi Christopher,

Thanks for your suggestion, however it produces two problems for me.

1. If I execute the code in the interpreter, it still fails like this:
import encodings
encodings.alias es.aliases['roman8']='latin_1'
'hello'.encode( 'roman8')


Traceback (most recent call last):
File "<pyshell#3 >", line 1, in -toplevel-
'hello'.encode( 'roman8')
LookupError: unknown encoding: roman8
2. If I put the code in site-packages/sitecustomize.p y, it fails like
this:

capulet:home/richardt > python -v
# installing zipimport hook
import zipimport # builtin
# installed zipimport hook
# /opt/python/lib/python2.3/site.pyc matches /opt/python/lib/python2.3/s
ite.py
import site # precompiled from /opt/python/lib/python2.3/site.pyc
# /opt/python/lib/python2.3/os.pyc matches /opt/python/lib/python2.3/os.
py
import os # precompiled from /opt/python/lib/python2.3/os.pyc
import posix # builtin
# /opt/python/lib/python2.3/posixpath.pyc matches /opt/python/lib/python
2.3/posixpath.py
import posixpath # precompiled from /opt/python/lib/python2.3/posixpath.
pyc
# /opt/python/lib/python2.3/stat.pyc matches /opt/python/lib/python2.3/s
tat.py
import stat # precompiled from /opt/python/lib/python2.3/stat.pyc
# /opt/python/lib/python2.3/UserDict.pyc matches /opt/python/lib/python2
..3/UserDict.py
import UserDict # precompiled from /opt/python/lib/python2.3/UserDict.py
c
# /opt/python/lib/python2.3/copy_reg.pyc matches /opt/python/lib/python2
..3/copy_reg.py
import copy_reg # precompiled from /opt/python/lib/python2.3/copy_reg.py
c
# /opt/python/lib/python2.3/types.pyc matches /opt/python/lib/python2.3/
types.py
import types # precompiled from /opt/python/lib/python2.3/types.pyc
# /opt/python/lib/python2.3/site-packages/sitecustomize.p yc matches
/opt/python/lib/python2.3/site-packages/sitecustomize.p y
import sitecustomize # precompiled from /opt/python/lib/python2.3/site-
packages/sitecustomize.p yc
import encodings # directory /opt/python/lib/python2.3/encodings
# /opt/python/lib/python2.3/encodings/__init__.pyc matches /opt/python/l
ib/python2.3/encodings/__init__.py
import encodings # precompiled from /opt/python/lib/python2.3/encodings/
__init__.pyc
# /opt/python/lib/python2.3/codecs.pyc matches /opt/python/lib/python2.3
/codecs.py
import codecs # precompiled from /opt/python/lib/python2.3/codecs.pyc
import _codecs # builtin
'import site' failed; traceback:
Traceback (most recent call last):
File "/opt/python/lib/python2.3/site.py", line 355, in ?
import sitecustomize
File "/opt/python/lib/python2.3/site-packages/sitecustomize.p y", line
7, in ?
encodings.alias es.aliases['roman8']='latin_1'
AttributeError: 'module' object has no attribute 'aliases'
# /opt/python/lib/python2.3/warnings.pyc matches /opt/python/lib/python2
..3/warnings.py
import warnings # precompiled from /opt/python/lib/python2.3/warnings.py
c
# /opt/python/lib/python2.3/linecache.pyc matches /opt/python/lib/python
2.3/linecache.py
import linecache # precompiled from /opt/python/lib/python2.3/linecache.
pyc
# /opt/python/lib/python2.3/encodings/aliases.pyc matches /opt/python/li
b/python2.3/encodings/aliases.py
import encodings.alias es # precompiled from /opt/python/lib/python2.3/en
codings/aliases.pyc
Python 2.3.4 (#3, May 28 2004, 13:24:19) [C] on hp-ux11
Type "help", "copyright" , "credits" or "license" for more information.

--
Richard Townsend
Jul 18 '05 #7
Further, if I put the following in sitecustomize.p y:

import encodings
print dir(encodings)

I get:

['CodecRegistryE rror', '__builtins__', '__doc__', '__file__',
'__name__', '__path__', '_cache', '_import_tail',
'_norm_encoding _map', '_unknown', 'codecs', 'exceptions',
'normalize_enco ding', 'search_functio n', 'types']

Notice there is no 'aliases' attribute.

But if I then run this interactively:
import encodings
dir(encodings)

['CodecRegistryE rror', '__builtins__', '__doc__', '__file__',
'__name__', '__path__', '_cache', '_import_tail',
'_norm_encoding _map', '_unknown', 'aliases', 'codecs', 'exceptions',
'normalize_enco ding', 'search_functio n', 'types']

then the 'aliases' attribute is there.
--
Richard Townsend
Jul 18 '05 #8
On Thu, 22 Jul 2004, Richard Townsend wrote:
Further, if I put the following in sitecustomize.p y:

import encodings
print dir(encodings)

I get:

['CodecRegistryE rror', '__builtins__', '__doc__', '__file__',
'__name__', '__path__', '_cache', '_import_tail',
'_norm_encoding _map', '_unknown', 'codecs', 'exceptions',
'normalize_enco ding', 'search_functio n', 'types']

Notice there is no 'aliases' attribute.


Oops, I had only tested it at the prompt :P I had assumed sitecustomize.p y
was run after everything was set up.

This code uses a more defined interface for altering the codecs registry,
uses 'ascii' instead of 'latin_1' (to prevent some confusion), and
I've actually tested it in sitecustomize.p y:

import codecs

def roman8(n):
if n=='roman8':
return codecs.lookup(' ascii')

codecs.register (roman8)

This achieves the same effect as the aliases trick (which I'm surprised
didn't work for you at the prompt), but is less tricksy and should
therefore work better.

Jul 18 '05 #9

"Christophe r T King" <sq******@WPI.E DU> wrote in message
news:Pi******** *************** *************** @ccc2.wpi.edu.. .
This achieves the same effect as the aliases trick (which I'm surprised
didn't work for you at the prompt), but is less tricksy and should
therefore work better.


I've put what should be a proper codec as a patch on SF. Really needs
testing on HP-UX though....
Jul 18 '05 #10

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

Similar topics

3
2671
by: Peter | last post by:
Hi, I try to make up a javascript string which contains numeric numbers in any positions. For example, I want to make a string: secretcode, where secretcode.charAt(0)==(-21), secretcode.charAt(5)==(-14). Is there any way to accomplish this task? Thanks in advance, Peter
2
2689
by: charlie_M | last post by:
I have the following code: <script type=text/javascript> function hide_tooltip(){ var hp = document.getElementById("tooltipper"); hp.style.left=0; hp.style.top=0; hp.style.width=1; hp.style.height=1; hp.style.padding=0;
1
3040
by: olsongt | last post by:
I was going to submit to sourceforge, but my unicode skills are weak. I was trying to strip characters from a string that contained values outside of ASCII. I though I could just encode as 'ascii' in 'replace' mode but it threw an error. Strangely enough, if I decode via the ascii codec and then encode via the ascii codec, I get what I want. That being said, this may be operating correctly. >>> print 'aaa\xae' aaa® >>>...
2
10320
by: aurora | last post by:
I have some unicode string with some characters encode using python notation like '\n' for LF. I need to convert that to the actual LF character. There is a 'unicode_escape' codec that seems to suit my purpose. >>> encoded = u'A\\nA' >>> decoded = encoded.decode('unicode_escape') >>> print len(decoded) 3 Note that both encoded and decoded are unicode string. I'm trying to use
4
2826
by: Dirk Hagemann | last post by:
Hi! When I receive data from Microsoft Active Directory it is an "ad_object" and has the type unicode. When I try to convert it to a string I get this error: UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in position 26: ordinal not in range(128) This is caused by characters like the german ä, ö or ü.
5
2501
by: wanghz | last post by:
Hello, everyone. I have a problem when I'm processing unicode strings. Is it possible to get the 8bit-string representation of any unicode string? Suppose I get a unicode string: a = u'\xc8\xce\xcf\xcd\xc6\xeb'; then, by a.encode('latin-1'); I can get the 8bit-string representation of it, that is, the physical
4
8254
by: J Peyret | last post by:
Well, as usual I am confused by unicode encoding errors. I have a string with problematic characters in it which I'd like to put into a postgresql table. That results in a postgresql error so I am trying to fix things with <string>.encode he Company�s ticker Trying for an encode:
5
2374
by: sniipe | last post by:
Hi, I have a problem with unicode string in Pylons templates(Mako). I will print first char from my string encoded in UTF-8 and urllib.quote(), for example string '£ukasz': ${urllib.unquote(c.user.firstName).encode('latin-1')} and I received this information:
19
5347
by: est | last post by:
From python manual str( ) Return a string containing a nicely printable representation of an object. For strings, this returns the string itself. The difference with repr(object) is that str(object) does not always attempt to return a string that is acceptable to eval(); its goal is to return a printable string. If no argument is given, returns the empty string, ''.
5
3626
by: erictheone | last post by:
so here is my code. My getlines for the strings keyword and phrase at lines 44 and 79 respectively don't work. Please help!!! #include <cstdlib> #include <string> #include <iostream> #include <fstream> using namespace std; string removeAllWhite( string eric) {
0
10213
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10163
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9040
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4113
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 we have to send another system
2
3722
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.