def _decode_from_file_system(self, arg):
     encoding = sys.getfilesystemencoding()
     if sys.platform.startswith('java'):
         # http://bugs.jython.org/issue1592
         from java.lang import String
         arg = String(arg)
     return unic(arg, encoding) if encoding else unic(arg)
Exemple #2
0
 def _decode_from_file_system(self, arg):
     encoding = sys.getfilesystemencoding()
     if sys.platform.startswith('java'):
         # http://bugs.jython.org/issue1592
         from java.lang import String
         arg = String(arg)
     return unic(arg, encoding) if encoding else unic(arg)
Exemple #3
0
def decode_from_file_system(string):
    """Decodes path from file system to Unicode."""
    encoding = sys.getfilesystemencoding()
    if sys.platform.startswith('java'):
        # http://bugs.jython.org/issue1592
        from java.lang import String
        string = String(string)
    return unic(string, encoding) if encoding else unic(string)
Exemple #4
0
def _get_python_message(exc_type, exc_value):
    # If exception is a "string exception" without a message exc_value is None
    if exc_value is None:
        return unic(exc_type)
    name = _get_name(exc_type)
    try:
        msg = unicode(exc_value)
    except UnicodeError:  # Happens if message is Unicode and version < 2.6
        msg = ' '.join(unic(a) for a in exc_value.args)
    return _format_message(name, msg)
Exemple #5
0
def _get_python_message(exc_type, exc_value):
    # If exception is a "string exception" without a message exc_value is None
    if exc_value is None:
        return unic(exc_type)
    name = _get_name(exc_type)
    try:
        msg = unicode(exc_value)
    except UnicodeError:  # Happens if message is Unicode and version < 2.6
        msg = ' '.join(unic(a) for a in exc_value.args)
    return _format_message(name, msg)
 def _escape(self, content):
     content = unic(content)
     for char in _ILLEGAL_CHARS_IN_XML:
         # Avoid bug http://ironpython.codeplex.com/workitem/29402
         if char in content:
             content = content.replace(char, '')
     return content
Exemple #7
0
def fail_unless_raises_with_msg(exc_class, expected_msg, callable_obj, *args,
                                **kwargs):
    """Similar to fail_unless_raises but also checks the exception message."""
    try:
        callable_obj(*args, **kwargs)
    except exc_class, err:
        assert_equal(expected_msg, unic(err), 'Correct exception but wrong message')
Exemple #8
0
def getdoc(item):
    doc = inspect.getdoc(item) or u''
    if isinstance(doc, unicode):
        return doc
    try:
        return doc.decode('UTF-8')
    except UnicodeDecodeError:
        return unic(doc)
Exemple #9
0
def fail_unless_raises_with_msg(exc_class, expected_msg, callable_obj, *args,
                                **kwargs):
    """Similar to fail_unless_raises but also checks the exception message."""
    try:
        callable_obj(*args, **kwargs)
    except exc_class, err:
        assert_equal(expected_msg, unic(err),
                     'Correct exception but wrong message')
 def _format_message(self, name, message):
     message = unic(message or '')
     message = self._clean_up_message(message, name)
     name = name.split('.')[-1]  # Use only last part of the name
     if message == '':
         return name
     if name in _generic_exceptions:
         return message
     return '%s: %s' % (name, message)
Exemple #11
0
def seq2str(sequence, quote="'", sep=', ', lastsep=' and '):
    """Returns sequence in format 'item 1', 'item 2' and 'item 3'"""
    quote_elem = lambda string: quote + unic(string) + quote
    if len(sequence) == 0:
        return ''
    if len(sequence) == 1:
        return quote_elem(sequence[0])
    elems = [quote_elem(s) for s in sequence[:-2]]
    elems.append(quote_elem(sequence[-2]) + lastsep + quote_elem(sequence[-1]))
    return sep.join(elems)
Exemple #12
0
def _format_message(name, message, java=False):
    message = unic(message or '')
    if java:
        message = _clean_up_java_message(message, name)
    name = name.split('.')[-1]  # Use only last part of the name
    if message == '':
        return name
    if name in _generic_exceptions:
        return message
    return '%s: %s' % (name, message)
Exemple #13
0
def _format_message(name, message, java=False):
    message = unic(message or '')
    if java:
        message = _clean_up_java_message(message, name)
    name = name.split('.')[-1]  # Use only last part of the name
    if message == '':
        return name
    if name in _generic_exceptions:
        return message
    return '%s: %s' % (name, message)
Exemple #14
0
def seq2str(sequence, quote="'", sep=', ', lastsep=' and '):
    """Returns sequence in format 'item 1', 'item 2' and 'item 3'"""
    quote_elem = lambda string: quote + unic(string) + quote
    if len(sequence) == 0:
        return ''
    if len(sequence) == 1:
        return quote_elem(sequence[0])
    elems = [quote_elem(s) for s in sequence[:-2]]
    elems.append(quote_elem(sequence[-2]) + lastsep + quote_elem(sequence[-1]))
    return sep.join(elems)
 def _get_details(self):
     # OOME.printStackTrace seems to throw NullPointerException
     if self._is_out_of_memory_error(self._exc_type):
         return ''
     output = StringWriter()
     self._exc_value.printStackTrace(PrintWriter(output))
     lines = [ line for line in output.toString().splitlines()
               if line and not self._is_ignored_stack_trace_line(line) ]
     details = '\n'.join(lines)
     msg = unic(self._exc_value.getMessage() or '')
     if msg:
         details = details.replace(msg, '', 1)
     return details
Exemple #16
0
def _get_java_details(exc_value):
    # OOME.printStackTrace seems to throw NullPointerException
    if isinstance(exc_value, OutOfMemoryError):
        return ''
    output = StringWriter()
    exc_value.printStackTrace(PrintWriter(output))
    lines = [ line for line in output.toString().splitlines()
              if line and not _is_ignored_stacktrace_line(line) ]
    details = '\n'.join(lines)
    msg = unic(exc_value.getMessage() or '')
    if msg:
        details = details.replace(msg, '', 1)
    return details
Exemple #17
0
def _get_java_details(exc_value):
    # OOME.printStackTrace seems to throw NullPointerException
    if isinstance(exc_value, OutOfMemoryError):
        return ''
    output = StringWriter()
    exc_value.printStackTrace(PrintWriter(output))
    lines = [
        line for line in output.toString().splitlines()
        if line and not _is_ignored_stacktrace_line(line)
    ]
    details = '\n'.join(lines)
    msg = unic(exc_value.getMessage() or '')
    if msg:
        details = details.replace(msg, '', 1)
    return details
Exemple #18
0
def html_escape(text, formatting=False):
    if not isinstance(text, basestring):
        text = unic(text)
    for name, value in [('&', '&amp;'), ('<', '&lt;'), ('>', '&gt;')]:
        text = text.replace(name, value)

    ret = []
    table = _Table()
    hr = None

    for line in text.splitlines():
        if formatting and table.is_table_row(line):
            if hr:
                ret.append(hr)
                hr = None
            table.add_row(line)
        elif table.is_started():
            if _hr_re.match(line):
                hr = '<hr />\n'
                line = ''
            else:
                line = _format_line(line, True)
            ret.append(table.end() + line)
        elif formatting and _hr_re.match(line):
            hr = '<hr />\n'
        else:
            line = _format_line(line, formatting)
            if hr:
                line = hr + line
                hr = None
            ret.append(line)

    if table.is_started():
        ret.append(table.end())
    if hr:
        ret.append(hr)

    return '<br />\n'.join(ret)
Exemple #19
0
def _get_name(exc_type):
    try:
        return exc_type.__name__
    except AttributeError:
        return unic(exc_type)
 def format(self, text):
     text = self._html_escape(unic(text))
     for line in text.splitlines():
         self.add_line(line)
     return self.get_result()
Exemple #21
0
 def _encode(self, message):
     message = unic(message)
     for char in _ILLEGAL_CHARS_IN_XML:
         message = message.replace(char, '')
     return message
Exemple #22
0
 def _escape_content(self, content):
     return html_escape(unic(content))
Exemple #23
0
def decode_output(string):
    """Decodes string from console encoding to Unicode."""
    if _output_encoding:
        return unic(string, _output_encoding)
    return string
Exemple #24
0
def format_assign_message(variable, value, cut_long=True):
    value = unic(value) if variable.startswith('$') else seq2str2(value)
    if cut_long and len(value) > _MAX_ASSIGN_LENGTH:
        value = value[:_MAX_ASSIGN_LENGTH] + '...'
    return '%s = %s' % (variable, value)
Exemple #25
0
def _get_name(exc_type):
    try:
        return exc_type.__name__
    except AttributeError:
        return unic(exc_type)
Exemple #26
0
def seq2str2(sequence):
    """Returns sequence in format [ item 1 | item 2 | ... ] """
    if not sequence:
        return '[ ]'
    return '[ %s ]' % ' | '.join(unic(item) for item in sequence)
Exemple #27
0
def decode_output(string):
    """Decodes string from console encoding to Unicode."""
    if _output_encoding:
        return unic(string, _output_encoding)
    return string
 def _encode(self, message):
     message = unic(message)
     for char in _ILLEGAL_CHARS_IN_XML:
         message = message.replace(char, '')
     return message
Exemple #29
0
def seq2str2(sequence):
    """Returns sequence in format [ item 1 | item 2 | ... ] """
    if not sequence:
        return '[ ]'
    return '[ %s ]' % ' | '.join(unic(item) for item in sequence)
 def content(self, content=None, escape=True):
     """Given content doesn't need to be a string"""
     if content is not None:
         if escape:
             content = html_escape(unic(content))
         self._write(content)
Exemple #31
0
 def _escape_content(self, content):
     return html_escape(unic(content))