summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xgui.py4
-rw-r--r--htmlbuffer.py4
-rw-r--r--iconvmodule/iconvcodec.py2
-rw-r--r--iconvmodule/iconvmodule.c264
-rw-r--r--iconvmodule/test_iconv.py23
-rw-r--r--translate.py44
6 files changed, 191 insertions, 150 deletions
diff --git a/gui.py b/gui.py
index 4cf782c39..962e65a87 100755
--- a/gui.py
+++ b/gui.py
@@ -21,7 +21,7 @@ import sys
import parted
import gtk
import htmlbuffer
-from translate import _, N_
+from translate import _, N_, utf8
from language import expandLangs
from splashscreen import splashScreenPop
from log import log
@@ -445,7 +445,7 @@ class InstallControlWindow:
def refreshHelp(self):
buffer = htmlbuffer.HTMLBuffer()
ics = self.currentWindow.getICS()
- buffer.feed(ics.getHTML(self.langSearchPath))
+ buffer.feed(utf8(ics.getHTML(self.langSearchPath)))
textbuffer = buffer.get_buffer()
self.help.set_buffer(textbuffer)
# scroll to the top. Do this with a mark so it's done in the idle loop
diff --git a/htmlbuffer.py b/htmlbuffer.py
index b06f168d6..bf42aabe5 100644
--- a/htmlbuffer.py
+++ b/htmlbuffer.py
@@ -61,6 +61,10 @@ class HTMLBuffer(HTMLParser.HTMLParser):
tag.set_property('font', '%s %d' % (baseFont, baseSize + 4))
tag.set_property('weight', pango.WEIGHT_BOLD)
+ tag = self.buffer.create_tag('h3')
+ tag.set_property('font', '%s %d' % (baseFont, baseSize + 4))
+ tag.set_property('weight', pango.WEIGHT_BOLD)
+
tag = self.buffer.create_tag('b')
tag.set_property('weight', pango.WEIGHT_BOLD)
diff --git a/iconvmodule/iconvcodec.py b/iconvmodule/iconvcodec.py
index a887b587e..3dbcf45ea 100644
--- a/iconvmodule/iconvcodec.py
+++ b/iconvmodule/iconvcodec.py
@@ -1,3 +1,5 @@
+raise RuntimeError, "Don't use me right now!"
+
import sys, iconv, codecs, errno
# First we need to find out what the Unicode code set name is
diff --git a/iconvmodule/iconvmodule.c b/iconvmodule/iconvmodule.c
index 6841bc85b..31b4d20ed 100644
--- a/iconvmodule/iconvmodule.c
+++ b/iconvmodule/iconvmodule.c
@@ -2,8 +2,8 @@
#include <Python.h>
typedef struct {
- PyObject_HEAD
- iconv_t handle;
+ PyObject_HEAD
+ iconv_t handle;
} IconvObject;
static PyObject *error;
@@ -17,174 +17,162 @@ static char iconv_open__doc__[]=
static PyObject*
py_iconv_open(PyObject* unused, PyObject* args)
{
- char *tocode, *fromcode;
- iconv_t result;
- IconvObject *self;
- if (!PyArg_ParseTuple(args, "ss", &tocode, &fromcode))
- return NULL;
- result = iconv_open(tocode, fromcode);
- if (result == (iconv_t)(-1)){
- PyErr_SetFromErrno(PyExc_ValueError);
- return NULL;
- }
- self = PyObject_New(IconvObject, &Iconv_Type);
- if (self == NULL){
- iconv_close(result);
- return NULL;
- }
- self->handle = result;
- return (PyObject*)self;
+ char *tocode, *fromcode;
+ iconv_t result;
+ IconvObject *self;
+
+ if (!PyArg_ParseTuple(args, "ss", &tocode, &fromcode))
+ return NULL;
+
+ result = iconv_open(tocode, fromcode);
+ if (result == (iconv_t)(-1)) {
+ PyErr_SetFromErrno(PyExc_ValueError);
+ return NULL;
+ }
+ self = PyObject_New(IconvObject, &Iconv_Type);
+ if (self == NULL) {
+ iconv_close(result);
+ return NULL;
+ }
+ self->handle = result;
+ return (PyObject*) self;
}
static void
Iconv_dealloc(IconvObject *self)
{
- iconv_close(self->handle);
- PyObject_Del(self);
+ iconv_close(self->handle);
+ PyObject_Del(self);
}
-static char Iconv_iconv__doc__[]=
-"iconv(in[, outlen[, return_unicode[, count_only]]]) -> out\n"
-"Convert in to out. outlen is the size of the output buffer;\n"
-"it defaults to len(in).";
-
static PyObject*
Iconv_iconv(IconvObject *self, PyObject *args, PyObject* kwargs)
{
- PyObject *inbuf_obj;
- const char *inbuf;
- char *outbuf;
- size_t inbuf_size, outbuf_size, iresult;
- int inbuf_size_int, outbuf_size_int = -1;
- int return_unicode = 0, count_only = 0;
- PyObject *result;
- static char *kwarg_names[]={
- "s",
- "outlen",
- "return_unicode",
- "count_only",
- NULL
- };
- if (!PyArg_ParseTupleAndKeywords(args, kwargs,
- "O|iii:iconv", kwarg_names,
- &inbuf_obj, &outbuf_size_int,
- &return_unicode, &count_only))
- return NULL;
-
- if (inbuf_obj == Py_None){
- /* None means to clear the iconv object */
- inbuf = NULL;
- inbuf_size_int = 0;
- }else if (inbuf_obj->ob_type->tp_as_buffer){
- if (PyObject_AsReadBuffer(inbuf_obj, (const void**)&inbuf,
- &inbuf_size_int) == -1)
- return NULL;
- }else{
- PyErr_SetString(PyExc_TypeError,
- "iconv expects string as first argument");
+ PyObject *inbuf_obj;
+ const char *inbuf, *inptr;
+ char *outbuf, *outptr;
+ size_t inleft, outleft, result;
+ PyObject *ret;
+ static char *kwarg_names[] = { "in", NULL };
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:iconv", kwarg_names,
+ &inbuf_obj))
+ return NULL;
+
+ if (inbuf_obj->ob_type->tp_as_buffer) {
+ if (PyObject_AsReadBuffer(inbuf_obj, (const void**) &inbuf,
+ &inleft) == -1)
+ return NULL;
+ inptr = inbuf;
+ } else {
+ PyErr_SetString(PyExc_TypeError,
+ "iconv expects string as first argument");
+ return NULL;
+ }
+
+ /* begin with the same amount of space as the input */
+ outptr = outbuf = malloc(inleft);
+ outleft = inleft;
+
+ /* Perform the conversion. */
+ do {
+ result = iconv(self->handle, (char **) &inptr, &inleft, &outptr, &outleft);
+ if (result == (size_t) -1) {
+ if (errno == E2BIG) {
+ /* we ran out of space in outbuf, it needs to be bigger */
+ char *newbuf;
+ /* a guess at how much more we need */
+ size_t curpos, extra = inleft * 2;
+
+ curpos = outptr - outbuf;
+ newbuf = realloc(outbuf, outptr - outbuf + extra);
+ if (newbuf == NULL) {
+ free(outbuf);
+ /* XXX set exception */
+ return NULL;
+ }
+ outbuf = newbuf;
+ outptr = outbuf + curpos;
+
+ /* now we have more space to convert into */
+ outleft += extra;
+ } else {
+ /* if we managed to convert everything up to the last byte,
+ it was probably a NULL terminated string (you can't convert
+ the NULL) */
+ if (inleft == 0)
+ break;
+ PyErr_SetFromErrno(PyExc_SystemError);
+ free(outbuf);
return NULL;
+ }
}
- /* If no result size estimate was given, estimate that the result
- string is the same size as the input string. */
- if (outbuf_size_int == -1)
- outbuf_size_int = inbuf_size_int;
- inbuf_size = inbuf_size_int;
- if (count_only){
- result = NULL;
- outbuf = NULL;
- outbuf_size = outbuf_size_int;
- }else if(return_unicode){
- /* Allocate the result string. */
- result = PyUnicode_FromUnicode(NULL, outbuf_size_int);
- outbuf = (char*)PyUnicode_AS_UNICODE(result);
- outbuf_size = outbuf_size_int*2;
- }else{
- /* Allocate the result string. */
- result = PyString_FromStringAndSize(NULL, outbuf_size_int);
- if (!result)
- return NULL;
- outbuf = PyString_AS_STRING(result);
- outbuf_size = outbuf_size_int;
- }
- /* Perform the conversion. */
- iresult = iconv(self->handle, &inbuf, &inbuf_size, &outbuf, &outbuf_size);
- if (count_only){
- result = PyInt_FromLong(outbuf_size_int-outbuf_size);
- }else if (return_unicode) {
- /* If the conversion was successful, the result string may be
- larger than necessary; outbuf_size will present the extra
- bytes. */
- PyUnicode_Resize(&result, outbuf_size_int-outbuf_size/2);
- }else{
- _PyString_Resize(&result, outbuf_size_int-outbuf_size);
- }
+ } while (inleft > 0);
- if (iresult == -1){
- PyObject *exc;
- exc = PyObject_CallFunction(error,"siiO",
- strerror(errno),errno,
- inbuf_size_int - inbuf_size,
- result);
- Py_DECREF(result);
- PyErr_SetObject(error,exc);
- return NULL;
- }
- return result;
+ ret = PyString_FromStringAndSize(outbuf, outptr - outbuf);
+ free(outbuf);
+
+ return ret;
}
+static char Iconv_iconv__doc__[] =
+"iconv(in) -> out\n"
+"Convert in to out.";
+
+
static PyMethodDef Iconv_methods[] = {
- {"iconv", (PyCFunction)Iconv_iconv,
- METH_KEYWORDS|METH_VARARGS, Iconv_iconv__doc__},
- {NULL, NULL} /* sentinel */
+ { "iconv", (PyCFunction)Iconv_iconv,
+ METH_KEYWORDS | METH_VARARGS, Iconv_iconv__doc__},
+ { NULL, NULL }
};
static PyObject *
Iconv_getattr(PyObject *self, char *name)
{
- return Py_FindMethod(Iconv_methods, self, name);
+ return Py_FindMethod(Iconv_methods, self, name);
}
statichere PyTypeObject Iconv_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "Iconv", /*tp_name*/
- sizeof(IconvObject), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- /* methods */
- (destructor)Iconv_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- (getattrfunc)Iconv_getattr, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash*/
+ PyObject_HEAD_INIT(NULL)
+ 0, /*ob_size*/
+ "Iconv", /*tp_name*/
+ sizeof(IconvObject), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ /* methods */
+ (destructor)Iconv_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc)Iconv_getattr, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ 0, /*tp_hash*/
};
static PyMethodDef iconv_methods[] = {
- {"open", py_iconv_open,
- METH_VARARGS, iconv_open__doc__},
- {NULL, NULL} /* sentinel */
+ { "open", py_iconv_open,
+ METH_VARARGS, iconv_open__doc__},
+ { NULL, NULL} /* sentinel */
};
-static char __doc__[]=
+static char __doc__[] =
"The iconv module provides an interface to the iconv library.";
DL_EXPORT(void)
initiconv(void)
{
- PyObject *m, *d;
-
- Iconv_Type.ob_type = &PyType_Type;
-
- /* Create the module and add the functions */
- m = Py_InitModule4("iconv", iconv_methods, __doc__,
- NULL, PYTHON_API_VERSION);
-
- /* Add some symbolic constants to the module */
- d = PyModule_GetDict(m);
- error = PyErr_NewException("iconv.error", PyExc_ValueError, NULL);
- PyDict_SetItemString(d, "error", error);
+ PyObject *m, *d;
+
+ Iconv_Type.ob_type = &PyType_Type;
+
+ /* Create the module and add the functions */
+ m = Py_InitModule4("iconv", iconv_methods, __doc__,
+ NULL, PYTHON_API_VERSION);
+
+ /* Add some symbolic constants to the module */
+ d = PyModule_GetDict(m);
+ error = PyErr_NewException("iconv.error", PyExc_ValueError, NULL);
+ PyDict_SetItemString(d, "error", error);
}
diff --git a/iconvmodule/test_iconv.py b/iconvmodule/test_iconv.py
index d8c6f8325..4180e2743 100644
--- a/iconvmodule/test_iconv.py
+++ b/iconvmodule/test_iconv.py
@@ -1,8 +1,25 @@
import iconv
-s=iconv.open("unicodelittle","iso-8859-1")
-r=s.iconv("Hallo",11,return_unicode=1)
+s=iconv.open("unicodelittle", "iso-8859-1")
+r=s.iconv("Hallo")
print repr(r),len(r)
+s=iconv.open("utf-8", "iso-8859-1")
+r=s.iconv("Hallo")
+print repr(r),len(r)
+u = r.encode("utf-8")
+print u
+
+s=iconv.open("utf-8", "euc-jp")
+r=s.iconv("testビデオカードを検出中test")
+print repr(r),len(r)
+u = r.decode("utf-8")
+print repr(u)
+
+s=iconv.open("euc-jp", "utf-8")
+r=s.iconv(u)
+print repr(r), len(r)
+print r
+
s=iconv.open("iso-8859-1","unicodelittle")
-r=s.iconv(u"Hallo",110)
+r=s.iconv(u"Hallo")
print r
diff --git a/translate.py b/translate.py
index 285f47c09..2332a93a8 100644
--- a/translate.py
+++ b/translate.py
@@ -14,7 +14,8 @@
#
import gettext
-import iconvcodec
+import iconv
+import os
class i18n:
def __init__(self):
@@ -22,24 +23,53 @@ class i18n:
self.cat = gettext.translation("anaconda")
except IOError:
self.cat = None
+ self.iconv = iconv.open('utf-8', 'iso-8859-1')
def getlangs(self):
return self.langs
def setlangs(self, langs):
- self.__init__()
self.langs = langs
+ mofile = None
+ for lang in langs:
+ try:
+ mofile = open("/usr/share/locale/%s/LC_MESSAGES/anaconda.mo"
+ % (lang), "rb")
+ except IOError:
+ try:
+ mofile = open("po/%s.mo" % (lang,), "rb")
+ except IOError:
+ pass
+ if mofile:
+ break
+ if not mofile:
+ print "unable to find translation file"
+ self.cat = None
+ self.iconv = iconv.open("utf-8", 'iso-8859-1')
+ return
- def gettext(self, string):
- if not self.cat:
- return string
+ self.cat = gettext.GNUTranslations(mofile)
+ try:
+ self.iconv = iconv.open("utf-8", self.cat.charset())
+ except:
+ self.iconv = iconv.open("utf-8", "iso-8859-1")
+
+ def utf8(self, string):
try:
- return self.cat.ugettext(string)
- except TypeError:
+ return self.iconv.iconv(string)
+ except:
return string
+ def gettext(self, string):
+ if not self.cat:
+ return self.utf8(string)
+ return self.utf8(self.cat.gettext(string))
+
def N_(str):
return str
cat = i18n()
_ = cat.gettext
+utf8 = cat.utf8
+
+