Revision 26f15862 lib/utils.py

b/lib/utils.py
576 576
          try:
577 577
            val = int(val)
578 578
          except ValueError, err:
579
            raise errors.OpPrereqError("Invalid %s size: %s" % (item, str(err)))
579
            raise errors.OpPrereqError("Invalid %s size: %s" % (item, err))
580 580
          beparams[item] = val
581 581
      if item in (constants.BE_AUTO_BALANCE):
582 582
        val = beparams[item]
......
1743 1743
  return rows[-lines:]
1744 1744

  
1745 1745

  
1746
def SafeEncode(text):
1747
  """Return a 'safe' version of a source string.
1748

  
1749
  This function mangles the input string and returns a version that
1750
  should be safe to disply/encode as ASCII. To this end, we first
1751
  convert it to ASCII using the 'backslashreplace' encoding which
1752
  should get rid of any non-ASCII chars, and then we again encode it
1753
  via 'string_escape' which converts '\n' into '\\n' so that log
1754
  messages remain one-line.
1755

  
1756
  @type text: str or unicode
1757
  @param text: input data
1758
  @rtype: str
1759
  @return: a safe version of text
1760

  
1761
  """
1762
  text = text.encode('ascii', 'backslashreplace')
1763
  text = text.encode('string_escape')
1764
  return text
1765

  
1766

  
1746 1767
def LockedMethod(fn):
1747 1768
  """Synchronized object access decorator.
1748 1769

  

Also available in: Unified diff