diff Generic/base.py @ 26:16f91684686b default tip

Upgrade to python 3. Keep python 2/3 compatibility
author Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
date Tue, 18 Jun 2019 17:50:23 +0200
parents 189f8274aecd
children
line wrap: on
line diff
--- a/Generic/base.py	Mon May 20 13:18:33 2019 +0200
+++ b/Generic/base.py	Tue Jun 18 17:50:23 2019 +0200
@@ -263,7 +263,9 @@
 
 # Modules
 # python 2/3 compatibility
-#from __future__ import absolute_import, division, print_function, unicode_literals
+from __future__ import absolute_import, division, print_function, unicode_literals
+from builtins import str as text
+from six import text_type
 
 import re
 import datetime
@@ -277,7 +279,7 @@
 # Translatable global Vars
 
 authors = ["Miguel Ángel Bárcena Rodríguez"]
-copyright = "Copyright \xc2\xa9 2019 Autoras de Pyarq Presupuestos"
+copyright = "Copyright © 2019 Autoras de Pyarq Presupuestos"
 website = "http://pyarq.obraencurso.es/pyarq-Presupuestos"
 website_label = "pyarq Presupuestos Web"
 comments = _("""
@@ -418,7 +420,9 @@
         Sets the code, must be a valid code
         """
         if not utils.is_valid_code(code)[0]:
-            raise ValueError(utils.mapping(_("Invalid code: $1"),(str(code),)))
+            _uni = utils.mapping(_("Invalid code: $1"),(code,))
+            _str = _uni.encode("utf-8")
+            raise ValueError(_str)
         self.__code = code
 
     def getSynonyms(self):
@@ -433,12 +437,16 @@
             - the items must be valid codes
         """
         if not isinstance(synonyms, list):
-            raise TypeError( utils.mapping(_("Synonyms ($1) must be a list, " \
-                  "code: $2"), (str(synonyms), str(self.__code))) )
+            _tuni = _("Synonyms ($1) must be a list, code: $2")
+            _uni = utils.mapping(_tuni, (synonyms, self.__code))
+            _str = _uni.encode("utf-8")
+            raise TypeError(_str)
         for code in synonyms:
             if not utils.is_valid_code(code)[0]:
-                raise ValueError( utils.mapping(_("Invalid Code in synomyms "\
-                      "list ($1) code: $2"), (str(code), str(self.__code))) )
+                _tuni = _("Invalid Code in synomyms list ($1) code: $2")
+                _uni = utils.mapping(_tuni, (code, self.__code))
+                _str = _uni.encode("utf-8")
+                raise ValueError(_str)
         self.__synonyms = synonyms
 
     def getRecordType(self):
@@ -467,9 +475,11 @@
         Set the unit of measure
         The unit must be a string.
         """
-        if not isinstance(unit, str):
-            raise TypeError( utils.mapping(_("Unit ($1) must be a string: $2"),
-                  (str(unit), str(self.__code))) )
+        if not isinstance(unit, text_type):
+            _tuni = _("Unit ($1) must be a text string: $2")
+            _uni = utils.mapping(_tuni, (unit, self.__code))
+            _str = _uni.encode("utf-8")
+            raise TypeError(_str)
         self.__unit = unit
 
     def getSummary(self):
@@ -481,9 +491,11 @@
         Set the summary of a record
         The summary must be a string.
         """
-        if not isinstance(summary, str):
-            raise TypeError( utils.mapping(_("Summary ($1) must be a string: "\
-                  "$1"), (str(summary), str(self.__code))) )
+        if not isinstance(summary, text_type):
+            _tuni = _("Summary ($1) must be a text string: $1")
+            _uni = utils.mapping(_tuni, (summary, self.__code))
+            _str = _uni.encode("utf-8")
+            raise TypeError(_str)
         self.__summary = summary
 
     def getPrices(self):
@@ -499,8 +511,10 @@
             - the first item: price must be a float
         """
         if not isinstance(prices, list):
-            raise TypeError( utils.mapping(_("Prices ($1) must be a list: $2"),
-                  (str(prices), str(self.__code))) )
+            _tuni = _("Prices ($1) must be a list: $2")
+            _uni = utils.mapping(_tuni, (text(prices), self.__code))
+            _str = _uni.encode("utf-8")
+            raise TypeError(_str)
         for index in range(len(prices)):
             _price_date = prices[index]
             _price_date = self._validate_price_date(_price_date, decimals)
@@ -520,13 +534,17 @@
 
     def _validate_price_date(self, price_date, decimals):
         if not isinstance(price_date, list) and len(price_date) == 2:
-            raise ValueError( utils.mapping(_("Price ($1) must be a list"\
-                  " with two items: $2"), (str(price_date), str(self.__code))) )
+            _tuni = _("Price ($1) must be a list with two items: $2")
+            _uni = utils.mapping(_tuni, (text(price_date), self.__code))
+            _str = _uni.encode("utf-8")
+            raise ValueError(_str)
         _price = price_date[0]
         _date = price_date[1]
         if not isinstance(_price, float):
-            raise TypeError( utils.mapping(_("Price must be a float "\
-                      "number: $1"), (str(_price),)) )
+            _tuni = ("Price must be a float number: $1")
+            _uni = utils.mapping(_tuni, (text(_price),))
+            _str = _uni.encode("utf-8")
+            raise TypeError(_str)
         _D = abs(decimals.getD(self.recordType))
         _price = round(_price, _D)
         price_date[0] = _price
@@ -535,19 +553,23 @@
 
     def getPrice(self, index_price):
         if len(self.__prices) <= index_price:
-            raise IndexError( _("The record do not have this Price. Code: %s"
-                                % self.__code) )
+            _tuni = _("The record do not have this Price. Code: $1")
+            _uni = utils.mapping(_tuni, (self.__code,))
+            _str = _uni.encode("utf-8")
+            raise IndexError(_str)
         return self.__prices[index_price][0]
 
     def getDate(self, index_price):
         if len(self.__prices) <= index_price:
-            raise IndexError( _("The record do not have this Price") )
+            _tuni = _("The record do not have this Price")
+            _str = _tuni.encode("utf-8")
+            raise IndexError(_str)
         return self.__prices[index_price][1] 
 
     def getParents(self):
         return self.__parents
 
-    def setParents(self,parents):
+    def setParents(self, parents):
         """setParents(parents)
         
         Sets the list of parents codes of the record.
@@ -556,12 +578,16 @@
             - the items must be valid codes
         """
         if not isinstance(parents, list):
-            raise TypeError( utils.mapping(_("Parents ($1) must be a list: $2"),
-                  (str(parents), str(self.__code))) )
+            _tuni = _("Parents ($1) must be a list: $2")
+            _uni = utils.mapping(_tuni, (text(parents), self.__code))
+            _str = _uni.encode("utf-8")
+            raise TypeError(_str)
         for parent in parents:
             if not utils.is_valid_code(parent)[0]:
-                raise ValueError(utils.mapping(_("Invalid parent code ($1) " \
-                      "in the record: $2"), (str(padre), str(self.__code))) )
+                _tuni = _("Invalid parent code ($1) in the record: $2")
+                _uni = utils.mapping(_tuni, (padre, self.__code))
+                _str = _uni.encode("utf-8")
+                raise ValueError(_str)
         self.__parents = parents
 
     def appendParent(self, parent):
@@ -572,8 +598,10 @@
 
         """
         if not utils.is_valid_code(parent)[0]:
-            raise ValueError( utils.mapping(_("Invalid parent code ($1) " \
-                  "in the record: $2"), (str(parent), str(self.__code))) )
+            _tuni = _("Invalid parent code ($1) in the record: $2")
+            _uni = utils.mapping(_tuni, (parent, self.__code))
+            _str = _uni.encode("utf-8")
+            raise ValueError(_str)
         self.__parents.append(parent)
 
     def getchildren(self):
@@ -588,13 +616,16 @@
             - the items must be instances of Decomposition class
         """
         if not isinstance(children, list):
-            raise TypeError( utils.mapping(_("children ($1) must be a list, "\
-                  "record: $2"), (str(children), str(self.__code))) )
+            _tuni = _("children ($1) must be a list, record: $2")
+            _uni = utils.mapping(_tuni, (text(children), self.__code))
+            _str = _uni.encode("utf-8")
+            raise TypeError(_str)
         for _child in children:
             if not isinstance(_child, Decomposition):
-                raise ValueError( utils.mapping(_("child ($1) must be a "\
-                      "Decomposition object, record: $2"),
-                      (str(_child), str(self.__code))) )
+                _tuni = _("child ($1) must be a Decomposition object, record: $2")
+                _uni = utils.mapping(_tuni, (text(_child), self.__code))
+                _str = _uni.encode("utf-8")
+                raise ValueError(_str)
             _record_code = self.code
             for _measure_list in [_child.budgetMeasures, _child.certification,
                                   _child.real_cost, _child.cost_goals,
@@ -645,9 +676,11 @@
         Sets the text of the record
         It must be a string
         """
-        if not isinstance(text, str):
-            raise TypeError( utils.mapping(_("Text ($1) must be a string, "\
-                  "record: $2"), (str(text), str(self.__code))) )
+        if not isinstance(text, text_type):
+            _tuni = _("Text ($1) must be a text string, record: $2")
+            _uni = utils.mapping(_tuni, (text, self.__code))
+            _str = _uni.encode("utf-8")
+            raise TypeError(_str)
         self.__text = text
 
     def getSheet(self):
@@ -659,7 +692,9 @@
         Sets the sheet of condition object
         """
         if not isinstance(sheet, Sheet):
-            raise ValueError( _("sheet must be a Sheet instance") )
+            _tuni = _("sheet must be a Sheet instance")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         self.__sheet = sheet
 
     def getFiles(self):
@@ -671,8 +706,10 @@
         Sets the files list
         """
         if not isinstance(files, list):
-            raise ValueError( utils.mapping(_("files must be a list: $1"),
-                                              str(files)) )
+            _tuni = _("files must be a list: $1")
+            _uni = utils.mapping(_tuni, text(files))
+            _str = _uni.encode("utf-8")
+            raise ValueError(_str)
         _files = []
         for file in files:
             if isinstance(file, File):
@@ -682,12 +719,16 @@
                 _type = file[1]
                 _description = file[2]
                 if not os.path.exists(file[0]):
-                    raise ValueError( _("Incorrect path") )
+                    _tuni = _("Incorrect path")
+                    _str = _tuni.encode("utf-8")
+                    raise ValueError(_str)
                 _file = File(file_path, type_, description)
                 _files.append(_file)
             else:
-                raise ValueError( utils.mapping(_(
-                      "file must be a list or a File object: $1"),str(file)) )
+                _tuni = _("file must be a list or a File object: $1")
+                _uni = utils.mapping(_tuni, file)
+                _str = _uni.encode("utf-8")
+                raise ValueError(_str)
         self.__files = _files
 
     def addFile(self, file_path, type_, description):
@@ -696,7 +737,9 @@
         Add a file to a record instance
         """
         if not os.path.exists(file_path):
-            raise ValueError( _("Incorrect path") )
+            _tuni = _("Incorrect path")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         _name = os.path.basename(file_path)
         _isin = False
         for _ofile in self.__files:
@@ -715,13 +758,17 @@
         Sets the labels list of a record
         """
         if not isinstance(labels, list):
-            raise ValueError( _("labels must be a list") )
+            _tuni = _("labels must be a list")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         _labels = []
         for _label in labels:
-            if isinstance(_label, str):
+            if isinstance(_label, text_type):
                 _labels.append(_label)
             else:
-                raise ValueError( _("label must be a string") )
+                _tuni = _("label must be a text string")
+                _str = _tuni.encode("utf-8")
+                raise ValueError(_str)
         self.__labels = _labels
 
     def addLabel(self, label):
@@ -729,8 +776,10 @@
         
         Add a label to a record instance
         """
-        if not isinstance(label, str):
-            raise ValueError( _("Label must be a string") )
+        if not isinstance(label, text_type):
+            _tuni = _("Label must be a text string")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         if not label in self.__labels:
             self.__labels.append(label)
 
@@ -978,7 +1027,9 @@
 
     def setPosition(self, position):
         if not isinstance(position, int):
-            raise ValueError( _("Position must be a integer") )
+            _tuni = _("Position must be a integer")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         self.__position = position
 
     def getCode(self):
@@ -992,11 +1043,14 @@
 
     def setBudgetMeasures(self, budgetMeasures):
         if not isinstance(budgetMeasures, list):
-            raise ValueError( _("BudgetMeasures atribute must be a list") )
+            _tuni = _("BudgetMeasures atribute must be a list")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         for _measure in budgetMeasures:
             if not isinstance(_measure, Measure):
-                raise ValueError( _("BudgetMeasures item must be a Measure "/
-                                    "object") )
+                _tuni = _("BudgetMeasures item must be a Measure object")
+                _str = _tuni.encode("utf-8")
+                raise ValueError(_str)
         self.__budgetMeasures = budgetMeasures
 
     def getCertification(self):
@@ -1004,7 +1058,9 @@
 
     def setCertification(self, certification):
         if not (certification is None or isinstance(certification, list)):
-            raise ValueError(_("Certification atribute must be a list or None"))
+            _tuni = _("Certification atribute must be a list or None")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         self.__certification = certification
 
     def getRealCost(self):
@@ -1012,7 +1068,9 @@
 
     def setRealCost(self, real_cost):
         if not (real_cost is None or  isinstance(real_cost, list)):
-            raise ValueError( _("Real cost atribute must be a list or None") )
+            _tuni =_("Real cost atribute must be a list or None")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         self.__real_cost = real_cost
 
     def getCostGoals(self):
@@ -1020,7 +1078,9 @@
 
     def setCostGoals(self, cost_goals):
         if not (cost_goals is None or  isinstance(cost_goals, list)):
-            raise ValueError( _("Cost goals atribute must be a list or None") )
+            _tuni = _("Cost goals atribute must be a list or None")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         self.__cost_goals = cost_goals
 
     def getCostPlanned(self):
@@ -1028,7 +1088,9 @@
 
     def setCostPlanned(self, cost_planned):
         if not (cost_planned is None or  isinstance(cost_planned, list)):
-            raise ValueError(_("Cost Planned atribute must be a list or None"))
+            _tuni = _("Cost Planned atribute must be a list or None")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         self.__cost_planned = cost_planned
 
     position = property(getPosition, setPosition, None,
@@ -1121,8 +1183,10 @@
 
     def setMeasure(self, measure, decimals):
         if not isinstance(measure, float):
-            raise ValueError( utils.mapping(_("Measure must be a float "\
-                  "number. Type: $1"), (type(measure),)) )
+            _tuni = _("Measure must be a float number. Type: $1")
+            _uni = utils.mapping(_tuni, (type(measure),))
+            _str = _uni.encode("utf-8")
+            raise ValueError(_str)
         # TODO: test after
         _DS = abs(decimals.DS)
         measure = round(measure, _DS)
@@ -1133,10 +1197,14 @@
 
     def setLines(self, lines):
         if not isinstance(lines, list):
-            raise ValueError( _("Lines must be a list") )
+            _tuni = _("Lines must be a list")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         for _line in lines:
             if not isinstance(_line, MeasureLine):
-                raise ValueError( _("Line must be a MeasureLine objetc") )
+                _tuni = _("Line must be a MeasureLine objetc")
+                _str = _tuni.encode("utf-8")
+                raise ValueError(_str)
         self.__lines = lines
 
     def getLabel(self):
@@ -1147,8 +1215,10 @@
 
     def setFactor(self, factor, decimals, recordType):
         if not isinstance(factor, float):
-            raise ValueError( utils.mapping(_("Factor must be a float number "\
-                  "|$1|"), (str(factor),)) )
+            _tuni = _("Factor must be a float number |$1|")
+            _uni = utils.mapping(_tuni, (text(factor),))
+            _str = _uni.encode("utf-8")
+            raise ValueError(_str)
         # TODO: test after
         _DF = abs(decimals.getDF(recordType))
         factor = round(factor, _DF)
@@ -1159,7 +1229,9 @@
 
     def setYield(self, yield_, decimals, recordType):
         if not isinstance(yield_, float):
-            raise ValueError( _("Yield must be a float number") )
+            _tuni = _("Yield must be a float number")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         # TODO: test after
         _DR = abs(decimals.getDR(recordType))
         yield_ = round(yield_, _DR)
@@ -1170,7 +1242,9 @@
 
     def setFixed(self, fixed, decimals):
         if not isinstance(fixed, bool):
-            raise ValueError( _("Fixed must be boolean object") )
+            _tuni = _("Fixed must be boolean object")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         self.__fixed = fixed
         self.updateYield(decimals)
 
@@ -1240,8 +1314,10 @@
         elif type_ == "A":
             self.lines.extend(_lines)
         else:
-            raise ValueError( utils.mapping(_("Type must be M or A. Type: $1"),
-                                            (str(type_),)) )
+            _tuni = _("Type must be M or A. Type: $1")
+            _uni = utils.mapping(_tuni, (type_,))
+            _str = _uni.encode("utf-8")
+            raise ValueError(_str)
         self.calculateMeasure(decimals, recordType)
 
     def calculateMeasure(self, decimals, recordType):
@@ -1384,17 +1460,20 @@
 
     def setParcialSubtotal(self, parcial_subtotal, decimals):
         if not isinstance(parcial_subtotal, float):
-            raise ValueError( utils.mapping(_(" Parcial Subtotal must be a "\
-                      "float number. Parcial: $1"), (str(parcial_subtotal),)) )
+            _tuni = _("Parcial Subtotal must be a float number. Parcial: $1")
+            _uni = utils.mapping(_tuni, (text(parcial_subtotal),))
+            _str = _uni.encode("utf-8")
+            raise ValueError(_str)
         _DS = abs(decimals.DS)
         parcial_subtotal = round(parcial_subtotal, _DS)
         self.__parcial_subtotal = parcial_subtotal
 
     def setAcumulatedSubtotal(self, acumulated_subtotal, decimals):
         if not isinstance(acumulated_subtotal, float):
-            raise ValueError( utils.mapping(_(" Acumulated Subtotal must be "\
-                      "a float number. Parcial: $1"),
-                     (str(acumulated_subtotal),)) )
+            _tuni = _("Acumulated Subtotal must be a float number. Parcial: $1")
+            _uni = utils.mapping(_tuni, (text(acumulated_subtotal),))
+            _str = _uni.encode("utf-8")
+            raise ValueError(_str)
         _DS = abs(decimals.DS)
         acumulated_subtotal = round(acumulated_subtotal, _DS)
         self.__acumulated_subtotal = acumulated_subtotal
@@ -1428,21 +1507,27 @@
 
     def setLineType(self, type_):
         if not type_ in [0, 1, 2, 3]:
-            raise ValueError( utils.mapping(_("Invalid measure line type ($1)"),
-                  (str(type_),)) )
+            _tuni = _("Invalid measure line type ($1)")
+            _uni = utils.mapping(_tuni, (type_,))
+            _str = _uni.encode("utf-8")
+            raise ValueError(_str)
         self.__lineType = type_
 
     def setComment(self, comment):
-        if not isinstance(comment, str):
-            raise ValueError( utils.mapping(_("Measure Comment must be a "\
-                  "string ($1)"), (str(comment),)) )
+        if not isinstance(comment, text_type):
+            _tuni = ("Measure Comment must be a text string ($1)")
+            _uni = utils.mapping(_tuni, (comment,))
+            _str = _uni.encode("utf-8")
+            raise ValueError(_str)
         self.__comment = comment
 
     def setUnits(self, units, decimals):
         if units != "":
             if not isinstance(units, float):
-                raise ValueError( utils.mapping(_("Invalid Measure Units ($1)"),
-                      (str(units),)) )
+                _tuni = _("Invalid Measure Units ($1)")
+                _uni = utils.mapping(_tuni, (text(units),))
+                _str = _uni.encode("utf-8")
+                raise ValueError(_str)
             _DN = abs(decimals.DN)
             units = round(units, _DN)
         self.__units = units
@@ -1454,8 +1539,10 @@
     def setLength(self, length, decimals):
         if length != "":
             if not isinstance(length, float):
-                raise ValueError( utils.mapping(_("Invalid Measure length ($1)"),
-                      (str(units),)) )
+                _tuni = _("Invalid Measure length ($1)")
+                _uni = utils.mapping(_tuni, (text(length),))
+                _str = _uni.encode("utf-8")
+                raise ValueError(_str)
             _DD = abs(decimals.DD)
             length = round(length, _DD)
         self.__length = length
@@ -1467,8 +1554,10 @@
     def setWidth(self, width, decimals):
         if width != "":
             if not isinstance(width, float):
-                raise ValueError( utils.mapping(_("Invalid Measure Width ($1)"),
-                      (str(units),)) )
+                _tuni = _("Invalid Measure Width ($1)")
+                _uni =  utils.mapping(_tuni, (text(units),))
+                _str = _uni.encode("utf-8")
+                raise ValueError(_str)
             _DD = abs(decimals.DD)
             width = round(width, _DD)
         self.__width = width
@@ -1480,8 +1569,10 @@
     def setHeight(self, height, decimals):
         if height != "":
             if not isinstance(height, float):
-                raise ValueError( utils.mapping(_("Invalid Measure Height ($1)"),
-                      (str(height),)) )
+                _tuni = _("Invalid Measure Height ($1)")
+                _uni = utils.mapping(_tuni, (text(height),))
+                _str = _uni.encode("utf-8")
+                raise ValueError(_str)
             _DD = abs(decimals.DD)
             height = round(height, _DD)
         self.__height = height
@@ -1491,12 +1582,16 @@
             pass
 
     def setFormula(self, formula, decimals):
-        if not isinstance(formula, str):
-            raise ValueError( utils.mapping(_("Formula must be a "\
-                  "string ($1)"), (str(formula),)) )
+        if not isinstance(formula, text_type):
+            _tuni = _("Formula must be a text string ($1)")
+            _uni = utils.mapping(_tuni, (formula,))
+            _str = _uni.encode("utf-8")
+            raise ValueError(_str)
         if re.match(".*[^0123456789\.()\+\-\*/\^abcdp ].*", formula):
-            raise ValueError( utils.mapping(_("There is invalid characters"\
-                  "in formula ($1)"), (str(formula),)) )
+            _tuni = _("There is invalid characters in formula ($1)")
+            _uni =  utils.mapping(_tuni, (formula,))
+            _str = _uni.encode("utf-8")
+            raise ValueError(_str)
         self.__formula = formula
         try:
             self.calculateParcial(decimals)
@@ -1561,19 +1656,27 @@
         try:
             a = float(a)
         except:
-            raise ValueError( _("'a' value must be a float number") )
+            _tuni = _("'a' value must be a float number")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         try:
             b = float(b)
         except:
-            raise ValueError( _("'b' value must be a float number") )
+            _tuni = _("'b' value must be a float number")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         try:
             c = float(c)
         except:
-            raise ValueError( _("'c' value must be a float number") )
+            _tuni = _("'c' value must be a float number")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         try:
             d = float(d)
         except:
-            raise ValueError( _("'d' value must be a float number") )
+            _tuni = _("'d' value must be a float number")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         # spaces are erased
         formula.replace(" ","")
         # operators and varibles are replaced
@@ -1584,16 +1687,16 @@
         formula = formula.replace("^", " ** ")
         formula = formula.replace("(", " ( ")
         formula = formula.replace(")", " ) ")
-        formula = formula.replace("a", str(a))
-        formula = formula.replace("b", str(b))
-        formula = formula.replace("c", str(c))
-        formula = formula.replace("d", str(d))
+        formula = formula.replace("a", text(a))
+        formula = formula.replace("b", text(b))
+        formula = formula.replace("c", text(c))
+        formula = formula.replace("d", text(d))
         formula = formula.replace("p", "3.1415926")
         _list_formula = formula.split(" ")
         _formula2 = ""
         for oper in _list_formula:
             try:
-                _float_oper= str(float(oper))
+                _float_oper= text(float(oper))
                 _formula2 = _formula2 + _float_oper
             except ValueError:
                 _formula2 = _formula2 + oper
@@ -1601,7 +1704,9 @@
         try:
             return eval(_formula2, _g)
         except:
-            raise ValueError( _("Invalid formula") )
+            _tuni = _("Invalid formula")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
 
 
 class Decimals(object):
@@ -1855,7 +1960,9 @@
 
     def setSheet_dict(self, sheet_dict):
         if not isinstance(sheet_dict, dict):
-            raise ValueError( _("sheet_dict must be a dictionay") )
+            _tuni = _("sheet_dict must be a dictionay")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         self.__sheet_dict = sheet_dict
 
     def getFields(self):
@@ -1875,19 +1982,29 @@
             return None
 
     def addField(self, field, section_dict):
-        if not isinstance(field, str):
-            raise ValueError( _("sheet field must be a string") )
+        if not isinstance(field, text_type):
+            _tuni = _("sheet field must be a text string")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         if not isinstance(section_dict, dict):
-            raise ValueError( _("section_dict must be a dictionary") )
+            _tuni = _("section_dict must be a dictionary")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         self.__sheet_dict[field] = section_dict
 
     def addSection(self, field, section, paragraph):
-        if not isinstance(field, str):
-            raise ValueError( _("sheet field must be a string") )
-        if not isinstance(section, str):
-            raise ValueError( _("sheet section must be a string") )
-        if not isinstance(paragraph, str):
-            raise ValueError( _("sheet paragraph must be a string") )
+        if not isinstance(field, text_type):
+            _tuni = _("sheet field must be a text string")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
+        if not isinstance(section, text_type):
+            _tuni = _("sheet section must be a text string")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
+        if not isinstance(paragraph, text_type):
+            _tuni = _("sheet paragraph must be a text string")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         if not field in self.__sheet_dict:
             self.addField(field, { })
         _field = self.__sheet_dict[field]
@@ -2172,10 +2289,12 @@
         owner: data owner 
         Set the data owner.
         """
-        if isinstance(owner, basestring):
+        if isinstance(owner, text_type):
             self.__file_owner = owner
         else:
-            raise  TypeError( _("Owner must be a string") )
+            _tuni = _("Owner must be a text string")
+            _str = _tuni.encode("utf-8")
+            raise  TypeError(_str)
 
     def setDate(self, date):
         """setOwner(self, date)
@@ -2191,7 +2310,10 @@
                 datetime.date(*date)
             self.__date = date
         else:
-            raise  TypeError(utils.mapping(_("Invalid Date: $1"),(str(date),)))
+            _tuni = _("Invalid Date: $1")
+            _uni = utils.mapping(_tuni,(text(date),))
+            _str = _uni.encode("utf-8")
+            raise  TypeError(_str)
 
     def setComment(self, comment):
         """setOwner(self, comment)
@@ -2199,10 +2321,12 @@
         comment: text to comment the budged
         Set the comment.
         """
-        if isinstance(comment, basestring):
+        if isinstance(comment, text_type):
             self.__comment = comment
         else:
-            raise  TypeError( _("Comment must be a string") )
+            _tuni = _("Comment must be a text string")
+            _str = _tuni.encode("utf-8")
+            raise  TypeError(_str)
 
     def setBudgeType(self, budget_type):
         """setOwner(self, budget_type)
@@ -2218,7 +2342,9 @@
         if budget_type in [1, 2, 3, 4]:
             self.__budgetType = budget_type
         else:
-            raise  ValueError( _("Budget type must be 1, 2, 3 or 4.") )
+            _tuni = _("Budget type must be 1, 2, 3 or 4.")
+            _str = _tuni.encode("utf-8")
+            raise  ValueError(_str)
 
     def setCertificateOrder(self, certificate_order, certificate_date):
         """setOwner(self, budget_type)
@@ -2230,7 +2356,9 @@
         if isinstance(certificate_order, int):
             self.__budgetCerficateOrder = certificate_order
         else:
-            raise  ValueError( _("Certificate order must be a integer.") )
+            _tuni =  _("Certificate order must be a integer.")
+            _str = _tuni.encode("utf-8")
+            raise  ValueError(_str)
 
     def setCertificateDater(self, certificate_date):
         """setCertidicateDate(self, certificate_date)
@@ -2245,7 +2373,8 @@
             datetime.date(*certificate_date)
             self.__budgetCerficateDate = certificate_date
         else:
-            _str = _("Budget certificate Date must be a valid Date.")
+            _tuni = _("Budget certificate Date must be a valid Date.")
+            _str = _tuni.encode("utf-8")
             raise  ValueError(_str)
 
     def setTitleList(self, title_list):
@@ -2254,13 +2383,15 @@
         title_list: [ "Header", ["Title1", "Title2", ... ] ]
         Set the header and titles for the price groups and decimals.
         """
-        title_list[0] = str(title_list[0])
+        title_list[0] = text(title_list[0])
         if isinstance(title_list, list) and isinstance(title_list[1], list):
             for i in range(len(title_list[1])):
-                title_list[1][i] = str(title_list[1][i])
+                title_list[1][i] = text(title_list[1][i])
             self.__title_list = title_list
         else:
-            raise TypeError( _("Invalid title list format") )
+            _tuni = _("Invalid title list format")
+            _str = _tuni.encode("utf-8")
+            raise TypeError(_str)
 
     def getTitleList(self):
         """ getTitleList(self)
@@ -2289,7 +2420,9 @@
         elif N < len(self.__decimals):
             _default_decimals = self.__decimals[N]
         else:
-            raise IndexError( _("Invalid Index Title") )
+            _tuni = _("Invalid Index Title")
+            _str = _tuni.encode("utf-8")
+            raise IndexError(_str)
         for _decimal in dictionary:
             if dictionary[_decimal] == "":
                 dictionary[_decimal] = eval("_default_decimals." + _decimal)
@@ -2364,7 +2497,9 @@
         elif key in self.__percentages:
             return self.__percentages[key]
         else:
-            raise KeyError( _("Invalid Percentage key") )
+            _tuni = _("Invalid Percentage key")
+            _str = _tuni.encode("utf-8")
+            raise KeyError(_str)
 
     def getAllParents(self,code):
         """getAllParents(self,code)
@@ -2435,15 +2570,13 @@
         return _measure
 
     def getStrYield(self, measure, recordType):
-        #_DR = measure.getDR(self.getDecimals())
         _DR = abs(self.getDecimals().getDR(recordType))
-        _yield = ("%." + str(_DR) + "f" ) % measure.yield_
+        _yield = ("%." + text(_DR) + "f" ) % measure.yield_
         return _yield
 
     def getStrFactor(self, measure, recorType):
         _DF = abs(self.getDecimals().getDF(recordType))
-        #_DF = measure.getDF(self.getDecimals())
-        _factor = ("%." + str(_DF) + "f" ) % measure.factor
+        _factor = ("%." + text(_DF) + "f" ) % measure.factor
         return _factor
 
     def setTree(self, code, child_code, position, factor, yield_, total,
@@ -2481,30 +2614,37 @@
         if code is None: # No-estructured measures
             code = self.getRoot()
             if code == None: # No root
-                print( "No-estructured measures. Adding root record " +  
-                str(self.setRecord("root", [], 0, "", "", [0.0,], [(1,1,1970)],
-                                     0, "") ).encode("utf8"))
+                _record = self.setRecord("root", [], 0, "", "", [0.0,],
+                                         [(1,1,1970)], 0, "")
+                _tuni = _("No-estructured measures. Adding root record")
+                print(_tuni)
                 code = self.getRoot()
 
         if not utils.is_valid_code(code)[0]:
-            raise ValueError( utils.mapping(_("Invalid parent code: $1"),
-                                            (str(code),)) )
+            _tuni = _("Invalid parent code: $1")
+            _uni = utils.mapping(_tuni, (code,))
+            _str = _uni.encode("utf-8")
+            raise ValueError(_str)
         if not utils.is_valid_code(child_code)[0]:
-            raise ValueError( utils.mapping(_("Invalid child code: $1 $2"),
-                                           (str(code),str(child_code))) )
+            _tuni = _("Invalid child code: $1 $2")
+            _uni = utils.mapping(_tuni, (code,child_code))
+            _str = _uni.encode("utf-8")
+            raise ValueError(_str)
         if not isinstance(position, int):
-            raise ValueError( utils.mapping(_("Invalid position in measure "\
-                  "$1, in code $2"), (str(parent_code), str(position))) )
+            _tuni = _("Invalid position in measure $1, in code $2 $3")
+            _uni = utils.mapping(_tuni, (text(position), code, child_code))
+            _str = _uni.encode("utf-8")
+            raise ValueError(_str)
         # Test circular references
         _all_parent_list = self.getAllParents(code) + [ code ]
         _all_child_list = self.getAllchildren(child_code) + [ child_code ]
         for _parent_code in _all_parent_list:
             if _parent_code in _all_child_list:
                 # TODO: change return to except
-                _str = _("Circular Decomposition, parent code: "\
+                _tuni = _("Circular Decomposition, parent code: "\
                          "$1, child code: $2, repeated code: $3")
-                print(utils.mapping(_str, (str(code), str(child_code),
-                                           str(_parent_code))).encode("utf8") )
+                _uni = utils.mapping(_tuni, (code, child_code, _parent_code))
+                print(_uni)
                 return
 
         # Creating reference to parent code in child record
@@ -2528,19 +2668,21 @@
                 positions = _record.getChildPositions(child_code)
                 if len(positions) == 1:
                     position = positions[0]
-                    _str = _("No-estructured measure or empty position. " \
+                    _tuni = _("No-estructured measure or empty position. " \
                              "Parent Code: $1, Child code: $2, Position: $3")
-                    print(utils.mapping(_str,(str(code), str(child_code),
-                                        str(position))).encode("utf8") )
+                    _uni = utils.mapping(_tuni,(code, child_code,
+                                         text(position)))
+                    print(_uni)
                 else:
                     position = _child_number
-                    _str = _("No-estructured measure or empty position. "\
+                    _tuni = _("No-estructured measure or empty position. "\
                              "Repeated child in unspecified position. "\
                              "It is impossible to determine the position. "\
                              "New child is added in the decomposition. "\
                              "Parent code: $1, Child code: $2, Position: $3")
-                    print(utils.mapping(_str,(str(code), str(child_code),
-                                        str(position))).encode("utf8") )
+                    _uni = utils.mapping(_tuni,(code, child_code,
+                                         text(position)))
+                    print(_uni)
             if position == _child_number:
                 # The record do not have the child
                 if not isinstance(factor, float): factor = 1.0
@@ -2572,31 +2714,33 @@
                 if isinstance(list_lines, list) and len(list_lines) > 0:
                     _measure.buildMeasure(list_lines, type_, self.getDecimals(),
                                           _record.recordType)
-                if isinstance(label, str) and label != "" :
+                if isinstance(label, text_type) and label != "" :
                     _measure.label = label
             else:
                 # TODO: change return for except
-                _str = _("Error: Invalid child position in "
+                _tuni = _("Error: Invalid child position in "
                          "decomposition. Parent code: $1 Child code: $2 "\
                          "Position: $3")
-                print(utils.mapping(_str, (str(code), str(child_code),
-                                    str(position))).encode("utf8") )
+                _uni = utils.mapping(_tuni, (code, child_code,
+                                     text(position)))
+                print(_uni)
                 return
         else:
             if child_code == "" :
-                _str = _("Error: Empty child code. Parent code: "\
+                _tuni = _("Error: Empty child code. Parent code: "\
                          "$1 Position: $2")
-                print(utils.mapping(_str, (str(code),
-                                           str(position))).encode("utf8") )
+                _uni = utils.mapping(_tuni, (code, text(position)))
+                print(_uni)
                 return
             if position == -1:
                 position = 0
             elif position != 0:
-                _str = _("Error: Invalid child position in "\
+                _tuni = _("Error: Invalid child position in "\
                          "decomposition. Parent code: $1 Child code: $2 "\
                          "Position: $3")
-                print(utils.mapping(_str, (str(code), str(child_code),
-                                    str(position))).encode("utf8") )
+                _uni = utils.mapping(_tuni, (code, child_code, 
+                                             text(position)))
+                print(_uni)
                 return
             if not isinstance(factor, float):
                 factor = 1.0
@@ -2629,19 +2773,27 @@
         try:
             a = float(a)
         except:
-            raise ValueError( _("'a' value must be a float number") )
+            _tuni = _("'a' value must be a float number")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         try:
             b = float(b)
         except:
-            raise ValueError( _("'b' value must be a float number") )
+            _tuni = _("'b' value must be a float number")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         try:
             c = float(c)
         except:
-            raise ValueError( _("'c' value must be a float number") )
+            _tuni = _("'c' value must be a float number")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         try:
             d = float(d)
         except:
-            raise ValueError( _("'d' value must be a float number") )
+            _tuni = _("'d' value must be a float number")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         # spaces are erased
         sre.sub("[ ]","",formula)
         # operators and varibles are replaced
@@ -2652,16 +2804,16 @@
         formula = formula.replace("^", " ** ")
         formula = formula.replace("(", " ( ")
         formula = formula.replace(")", " ) ")
-        formula = formula.replace("a", str(a))
-        formula = formula.replace("b", str(b))
-        formula = formula.replace("c", str(c))
-        formula = formula.replace("d", str(d))
+        formula = formula.replace("a", text(a))
+        formula = formula.replace("b", text(b))
+        formula = formula.replace("c", text(c))
+        formula = formula.replace("d", text(d))
         formula = formula.replace("p", "3.1415926")
         _list_formula = formula.split(" ")
         _formula2 = ""
         for oper in _list_formula:
             try:
-                _float_oper= str(float(oper))
+                _float_oper= text(float(oper))
                 _formula2 = _formula2 + _float_oper
             except ValueError:
                 _formula2 = _formula2 + oper
@@ -2669,7 +2821,9 @@
         try:
             return eval(_formula2, _g)
         except:
-            raise ValueError( _("Invalid formula") )
+            _tuni = _("Invalid formula")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
 
     def getText(self,code):
         """getText(self,code)
@@ -2680,7 +2834,9 @@
         if code in self.__records:
             return self.__records[code].text
         else:
-            raise IndexError( _("Invalid code") )
+            _tuni = _("Invalid code")
+            _str = _tuni.encode("utf-8")
+            raise IndexError(_str)
 
     def setText(self,code,text):
         """setText(self,code,text)
@@ -2690,8 +2846,10 @@
         Sests the description text of a record
         """
         if not utils.is_valid_code(code)[0]:
-            _str = _("Invalid record: $1")
-            raise ValueError( utils.mapping(_str, (str(code),)) )
+            _tuni = _("Invalid record: $1")
+            _uni = utils.mapping(_tuni, (code,))
+            _str = _uni.encode("utf-8")
+            raise ValueError(_str)
         if not code in self.__records:
             _record = self.setRecord(code, [], "", "", "", [], [],
                                      "", "")
@@ -2754,7 +2912,8 @@
             if self.__root is None:
                 self.__root = code
             else:
-                print(_("Only can be one root record").encode("utf8") )
+                _tuni = _("Only can be one root record")
+                print(_tuni)
                 return
                 # TODO: If the root is created in settree.
                 #       No-estructured measures
@@ -2845,7 +3004,7 @@
         else:
             _price = record.getPrice(index_price)
         _D = abs(self.getDecimals().getD(record.recordType))
-        _price = ("%." + str(_D) + "f" ) % _price
+        _price = ("%." + text(_D) + "f" ) % _price
         return _price
 
     def getCode(self, path):
@@ -2864,16 +3023,24 @@
                         try:
                             _child = _children_list[i]
                         except:
-                            raise ValueError( _("This record does not exits") )
+                            _tuni = _("This record does not exits")
+                            _str = _tuni.encode("utf-8")
+                            raise ValueError(_str)
                         _code = _child.code
                     else:
-                        raise ValueError( _("Path item must be a integer") )
+                        _tuni = _("Path item must be a integer")
+                        _str = _tuni.encode("utf-8")
+                        raise ValueError(_str)
                 return _code
             else:
-                raise ValueError( _("This record does not exits") )
+                _tuni = _("This record does not exits")
+                _str = _tuni.encode("utf-8")
+                raise ValueError(_str)
         else:
-            raise ValueError( utils.mapping(_("Path must be a not empty "\
-                  "tuple: $1"), (str(path),)) )
+            _tuni = _("Path must be a not empty tuple: $1")
+            _uni = utils.mapping(_tuni, (text(path),))
+            _str = _uni.encode("utf-8")
+            raise ValueError(_str)
 
     def getAmount(self, path):
         """def getAmount(self,path)
@@ -2891,7 +3058,6 @@
             _parent_code = self.getCode(path[:-1])
             _parent_record = self.getRecord(_parent_code)
             _child_number = path[-1]
-            
             _decomposition = _parent_record.children[_child_number]
             _factor = _decomposition.budgetMeasures[0].factor
             _yield = _decomposition.budgetMeasures[0].yield_
@@ -2934,14 +3100,18 @@
             _parent_record = self.getRecord(_parent_code)
             _amount = self.getAmount(path)
             _DI = abs(self.getDecimals().getDI(_parent_record.recordType))
-            _amount = ("%." + str(_DI) + "f") % _amount
+            _amount = ("%." + text(_DI) + "f") % _amount
             return _amount
 
     def setSheetSection(self,sheet_code,sheet_title):
-        if not isinstance(sheet_code, str):
-            raise ValueError( _("The sheet code must be a string") )
-        if not isinstance(sheet_title, str):
-            raise ValueError( _("The sheet title must be a string") )
+        if not isinstance(sheet_code, text_type):
+            _tuni = _("The sheet code must be a text string")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
+        if not isinstance(sheet_title, text_type):
+            _tuni = _("The sheet title must be a text string")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         self.__sheet_sections[sheet_code] = sheet_title
 
     def hasSheetSection(self, section):
@@ -2952,15 +3122,21 @@
 
     def setSheetSections(self,dictionary): 
         if not isinstance(dictionary, dict):
-            raise ValueError( _("The sheet sections must be a dictionary") )
+            _tuni = _("The sheet sections must be a dictionary")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         for sheet_code in dictionary.keys():
             self.setSheetSection(sheet_code, dictionary[sheet_code])
 
     def setSheetField(self, field_code, field_title):
-        if not isinstance(field_code, str):
-            raise ValueError( _("The field code must be a string") )
-        if not isinstance(field_title, str):
-            raise ValueError( _("The field title must be a string") )
+        if not isinstance(field_code, text_type):
+            _tuni = _("The field code must be a text string")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
+        if not isinstance(field_title, text_type):
+            _tuni = _("The field title must be a text string")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         self.__sheet_fields[field_code] = field_title
 
     def hasSheetField(self, field):
@@ -2971,15 +3147,21 @@
 
     def setSheetFields(self, field_dict):
         if not isinstance(field_dict, dict):
-            raise ValueError( _("The sheet field must be a dictionary") )
+            _tuni = _("The sheet field must be a dictionary")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         for field_code in field_dict.keys():
             self.setSheetField( field_code, field_dict[field_code])
 
     def setSheetParagraph(self, paragraph_code, paragraph_text):
-        if not isinstance(paragraph_code, str):
-            raise ValueError( _("The paragraph code must be a string") )
-        if not isinstance(paragraph_text, str):
-            raise ValueError( _("The paragraph text must be a string") )
+        if not isinstance(paragraph_code, text_type):
+            _tuni = _("The paragraph code must be a text string")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
+        if not isinstance(paragraph_text, text_type):
+            _tuni = _("The paragraph text must be a text string")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         self.__sheet_paragraphs[paragraph_code] = paragraph_text
 
     def hasSheetParagraph(self, paragraph):
@@ -2990,31 +3172,39 @@
 
     def setSheetParagraphs(self, paragraph_dict):
         if not isinstance(paragraph_dict, dict):
-            raise ValueError( _("The paragraph dict must be a dictionary") )
+            _tuni = _("The paragraph dict must be a dictionary")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         for paragraph_code in paragraph_dict.keys():
             self.setSheetParagraph(paragraph_code,
                                    paragraph_dict[paragraph_code])
 
     def setSheetRecord(self, record_code, field, section_dict):
-        if not isinstance(record_code, str):
-            raise ValueError( _("The record_code code must be a string") )
-        if not isinstance(field, str):
-            raise ValueError( _("The field must be a string") )
+        if not isinstance(record_code, text_type):
+            _tuni = _("The record_code code must be a text string")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
+        if not isinstance(field, text_type):
+            _tuni = _("The field must be a text string")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         if not isinstance(section_dict, dict):
-            raise ValueError( _("The section dict must be a dictionary") )
+            _tuni = _("The section dict must be a dictionary")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         #-#
         # TODO: Add a empty record?
         if not self.hasRecord(record_code):
-            _str = _("Error: The budget do not have this record "\
+            _tuni = _("Error: The budget do not have this record "\
                    "code and can not be added the sheet text in the field $1. "\
                    "Record Code: $2")
-            print(utils.mapping(_str, ( str(field),
-                                str(record_code))).encode("utf8") )
+            _uni = utils.mapping(_tuni, ( text(field), record_code))
+            print(_uni)
             return
         #-#
         if not self.hasSheetField(field):
             self.setSheetField(field, "")
-        for section, paragraph in section_dict.iteritems():
+        for (section, paragraph) in section_dict.items():
             if not self.hasSheetParagraph(paragraph):
                 self.setSheetParagraph(paragraph,"")
             if not self.hasSheetSection(section):
@@ -3023,46 +3213,62 @@
             _sheet.addSection(field, section, paragraph)
 
     def addFile(self, record_code, filepath, type_, description):
-        if not isinstance(record_code, str):
-            raise ValueError( _("The record_code code must be a string") )
-        #-# str and unicode
-        if not isinstance(filepath, str) and not isinstance(filepath, unicode):
-            raise ValueError( _("The filename must be a string") )
-        #-#
+        if not isinstance(record_code, text_type):
+            _tuni = _("The record_code code must be a text string")
+            _str = _uni.encode("utf-8")
+            raise ValueError(_str)
+        if not isinstance(filepath, text_type):
+            _tuni = _("The filename must be a text string")
+            _str = _uni.encode("utf-8")
+            raise ValueError(_str)
         # TODO: Add a empty record?
         if not self.hasRecord(record_code):
-            print(utils.mapping(_("Error: The budget do not have the record "\
-                "code $1 and can not be added the file: $2"),
-                (str(record_code), str(filepath))).encode("utf8") )
+            _tuni = _("Error: The budget do not have the record "\
+                      "code $1 and can not be added the file: $2")
+            _uni = utils.mapping(_tuni, (record_code, filepath))
+            print(_uni)
             return
-        #-#
         _record = self.getRecord(record_code)
         _record.addFile(filepath, type_, description)
 
     def setCompany(self, company_code, sumamary, name, offices,
                    cif, web, email):
-        if not isinstance(company_code, str):
-            raise ValueError( _("The company code must be a string") )
-        if not isinstance(sumamary, str):
-            raise ValueError( _("The summary must be a string") )
-        if not isinstance(name, str):
-            raise ValueError( _("The name must be a string") )
+        if not isinstance(company_code, text_type):
+            _tuni = _("The company code must be a text string")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
+        if not isinstance(sumamary, text_type):
+            _tuni = ("The summary must be a text string")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
+        if not isinstance(name, text_type):
+            _tuni = _("The name must be a text string")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         if not isinstance(offices, list):
-            raise ValueError( _("The name must be a list") )
+            _tuni = _("The name must be a list")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         _offices = []
         for _office in offices:
             if not isinstance(_office, list):
-                raise ValueError( _("The office must be a list") )
+                _tuni = _("The office must be a list")
+                _str = _tuni.encode("utf-8")
+                raise ValueError(_str)
             if not len(_office) == 10:
-                raise ValueError( _("The office must be a 10 items list") )
+                _tuni = _("The office must be a 10 items list")
+                _str = _tuni.encode("utf-8")
+                raise ValueError(_str)
             for _item in _office[:7] + _office[9:10]:
-                if not isinstance(_item, str):
-                    raise ValueError( _("This office item must be a "\
-                                        "string") )
+                if not isinstance(_item, text_type):
+                    _tuni = _("This office item must be a text string")
+                    _str = _tuni.encode("utf-8")
+                    raise ValueError(_str)
             for _item in _office[7:8]:
                 if not isinstance(_item, list):
-                    raise ValueError( _("This office item must be a "\
-                                        "list") )
+                    _tuni = _("This office item must be a list")
+                    _str = _tuni.encode("utf-8")
+                    raise ValueError(_str)
             _offices.append(Office(_office[0],
                                   _office[1],
                                   _office[2],
@@ -3073,12 +3279,18 @@
                                   _office[7],
                                   _office[8],
                                   _office[9]))
-        if not isinstance(cif, str):
-            raise ValueError( _("The name must be a string") )
-        if not isinstance(web, str):
-            raise ValueError( _("The web must be a string") )
-        if not isinstance(email, str):
-            raise ValueError( _("The email must be a string") )
+        if not isinstance(cif, text_type):
+            _tuni = _("The name must be a text string")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
+        if not isinstance(web, text_type):
+            _tuni = _("The web must be a text string")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
+        if not isinstance(email, text_type):
+            _tuni = _("The email must be a text string")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         
         self.__companys[company_code] = Company(company_code, sumamary, name,
                                                 _offices, cif, web, email)
@@ -3089,13 +3301,18 @@
         return self.__companys.keys()
 
     def addTecInfo(self, ti_code, text, unit):
-        if not isinstance(ti_code, str):
-            raise ValueError( _("The tecnical info code must be a string") )
-        if not isinstance(text, str):
-            raise ValueError( _("The tecnical info description must be a "\
-                                "string") )
-        if not isinstance(unit, str):
-            raise ValueError( _("The tecnical info unit must be a string") )
+        if not isinstance(ti_code, text_type):
+            _tuni = _("The tecnical info code must be a text string")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
+        if not isinstance(text, text_type):
+            _tuni = _("The tecnical info description must be a text string")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
+        if not isinstance(unit, text_type):
+            _tuni = _("The tecnical info unit must be a text string")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         self.__tec_info[ti_code] = [text, unit]
 
     def hasTecInfo(self, ti_code):
@@ -3145,8 +3362,10 @@
         
         Add a label to a record
         """
-        if not isinstance(label,str):
-            raise ValueError( _("The label must be a string") )
+        if not isinstance(label, text_type):
+            _tuni = _("The label must be a text string")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         if self.hasRecord(record_code):
             _record = self.__records[record_code]
             _record.addLabel(label)
@@ -3162,22 +3381,27 @@
         
         Sets Paramtric Record Select Comment
         """
-        if not isinstance(record_code, str):
-            raise ValueError( _("The record_code code must be a string") )
-        if not isinstance(comment, str):
-            raise ValueError( _("The parametric select comment must be a "\
-                                "string") )
+        if not isinstance(record_code, text_type):
+            _tuni = _("The record_code code must be a text string")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
+        if not isinstance(comment, text_type):
+            _tuni = _("The parametric select comment must be a text string")
+            _str = _tuni.encode("utf-8")
+            raise ValueError(_str)
         if not self.hasRecord(record_code):
-            print(utils.mapping(_("Error: The budget do not have the record "\
-                "code $1 and can not be added the Parametric select comment: "\
-                "$2"),
-                (str(record_code), str(comment))).encode("utf8") )
+            _tuni = _("Error: The budget do not have the record "\
+                      "code $1 and can not be added the Parametric "\
+                      "select comment: $2")
+            _uni = utils.mapping(_tuni, (record_code, comment))
+            print(_uni)
             return
         _record = self.getRecord(record_code)
         if not isinstance(_record, ParametricRecord):
-            print(utils.mapping(_("Error: The Record $1 is not a "\
-                "Parametric Record and can not have Parametric comment"),
-                (str(record_code),)).encode("utf8") )
+            _tuni = _("Error: The Record $1 is not a "\
+                      "Parametric Record and can not have Parametric comment")
+            _uni = utils.mapping(_tuni, (record_code,))
+            print(_uni)
         else:
             _record.select_comment = comment
 
@@ -3186,20 +3410,26 @@
         
         Sets parametric record summary
         """
-        if not isinstance(record_code, str):
-            raise ValueError( _("The record_code code must be a string") )
-        if not isinstance(summary, str):
-            raise ValueError( _("The summary record must be a string") )
+        if not isinstance(record_code, text_type):
+            _tuni = _("The record_code code must be a text string")
+            _str = _uni.encode("utf-8")
+            raise ValueError(_str)
+        if not isinstance(summary, text_type):
+            _tuni = _("The summary record must be a text string")
+            _str = _uni.encode("utf-8")
+            raise ValueError(_str)
         if not self.hasRecord(record_code):
-            print(utils.mapping(_("Error: The budget do not have the record "\
-                "code $1 and can not be seted the summary: $2"),
-                (str(record_code), str(summary))).encode("utf8") )
+            _tuni = _("Error: The budget do not have the record "\
+                      "code $1 and can not be seted the summary: $2")
+            _uni = utils.mapping(_tuni, (record_code, summary))
+            print(_uni)
             return
         _record = self.getRecord(record_code)
         if not isinstance(_record, ParametricRecord):
-            print(utils.mapping(_("Error: The Record $1 is not a "\
-                "Parametric Record and can not have Parametric summary"),
-                (str(record_code),)).encode("utf8") )
+            _tuni = _("Error: The Record $1 is not a "\
+                      "Parametric Record and can not have Parametric summary")
+            _uni = utils.mapping(_tuni, (record_code,))
+            print(_uni)
         else:
             self.getRecord(record_code).parametric_summary = summary
 
@@ -3208,20 +3438,26 @@
         
         Sets parametric record text
         """
-        if not isinstance(record_code, str):
-            raise ValueError( _("The record_code code must be a string") )
-        if not isinstance(text, str):
-            raise ValueError( _("The text record must be a string") )
+        if not isinstance(record_code, text_type):
+            _tuni = _("The record_code code must be a text string")
+            _str = _uni.encode("utf-8")
+            raise ValueError(_str)
+        if not isinstance(text, text_type):
+            _tuni = _("The text record must be a text string")
+            _str = _uni.encode("utf-8")
+            raise ValueError(_str)
         if not self.hasRecord(record_code):
-            print(utils.mapping(_("Error: The budget do not have the record "\
-                "code $1 and can not be seted the text: $2"),
-                (str(record_code), str(text))).encode("utf8") )
+            _tuni = _("Error: The budget do not have the record "\
+                      "code $1 and can not be seted the text: $2")
+            _uni = utils.mapping(_tuni, (record_code, text))
+            print(_uni)
             return
         _record = self.getRecord(record_code)
         if not isinstance(_record, ParametricRecord):
-            print(utils.mapping(_("Error: The Record $1 is not a "\
-                "Parametric Record and can not have Parametric text"),
-                (str(record_code),)).encode("utf8") )
+            _tuni = _("Error: The Record $1 is not a "\
+                      "Parametric Record and can not have Parametric text")
+            _uni = utils.mapping(_tuni, (record_code,))
+            print(_uni)
         else:
             self.getRecord(record_code).parametric_text = text
 
@@ -3742,10 +3978,14 @@
 
     def setHierarchy(self, hierarchy):
         if not hierarchy in [-1, 0 , 1 ,2, ""]:
-            raise ValueError( utils.mapping(_("Invalid Hierarchy ($1) "\
-                  "The hierarchy must be -1, 0, 1, 2"), (str(hierarchy),)) )
+            _tuni = _("Invalid Hierarchy ($1) "\
+                      "The hierarchy must be -1, 0, 1, 2")
+            _uni = utils.mapping(_tuni, (text(hierarchy),))
+            _str = _uni.encode("utf-8")
+            raise ValueError(_str)
         elif hierarchy == "":
-            print("Hierarchy temporarily set to an empty string".encode("utf8"))
+            _tuni = _("Hierarchy temporarily set to an empty string")
+            print(_tuni)
         #TODO Check empty Hierarchy in Generic.fiebdc.Read._testBudget
         self.__hierarchy = hierarchy
 
@@ -3753,9 +3993,12 @@
         return self.__type
 
     def setType(self, type_):
-        if not type_ in  ["", 0, 1, 2, 3] :
-            raise ValueError( utils.mapping(_("Invalid type ($1),"\
-                  "the type must be (empty string,0,1,2,3)"),(str(type_)),) )
+        if not type_ in  ["", 0, 1, 2, 3]:
+            _tuni = _("Invalid type ($1),"\
+                      "the type must be (empty string,0,1,2,3)")
+            _uni = utils.mapping(_tuni ,(text(type_),))
+            _str = _uni.encode("utf-8")
+            raise ValueError(_str)
         self.__type = type_
 
     def getSubtype(self):
@@ -3765,10 +4008,13 @@
         if not subtype in ["", "OB", "PU", "EA", "EU", "EC", "EF", "PA", "H",
                            "Q", "%", "MC", "MCr", "MM", "MS", "ME", "MCu",
                            "Mal","ML","M"]:
-            raise ValueError( utils.mapping(_("Invalid subtype ($1), The "\
+            _tuni = _("Invalid subtype ($1), The "\
                   "subtype must one in (empty string, EA, "\
                   "EU, EC, EF, OB, PA, PU, H, Q, %, MC, MCr, "\
-                  "MM, MS, ME, MCu, MAl, ML, M)"), (str(subtype),)) )
+                  "MM, MS, ME, MCu, MAl, ML, M)")
+            _uni = utils.mapping(_tuni, (text(subtype),))
+            _str = _uni.encode("utf-8")
+            raise ValueError(_str)
         self.__subtype = subtype
 
     hierarchy = property(getHierarchy, setHierarchy, None,