Coverts a simple fault trace to well-known text format

    :param trace:
        Fault trace as instance of :class: openquake.hazardlib.geo.line.Line

    :returns:
        Well-known text (WKT) Linstring representation of the trace
971429
def simple_trace_to_wkt_linestring(trace):
    '''
    
    '''
    trace_str = ""
    for point in trace:
        trace_str += ' %s %s,' % (point.longitude, point.latitude)
    trace_str = trace_str.lstrip(' ')
    return 'LINESTRING (' + trace_str.rstrip(',') + ')'
807668
def render_as_text(self, limit=None):
        """"""
        lines = traceback.format_exception(self.exc_type, self.exc_value,
                                           self.frames[0], limit=limit)
        return ''.join(lines).rstrip()
558900
def format_exception(exc, indent=0, pad='  '):
    
    from_msg = None
    if exc.__cause__ is not None:
        indent += yield from format_exception(exc.__cause__, indent)
        from_msg = traceback._cause_message.strip()
    elif exc.__context__ is not None and not exc.__suppress_context__:
        indent += yield from format_exception(exc.__context__, indent)
        from_msg = traceback._context_message.strip()
    padding = pad * indent
    if from_msg:
        yield '\n%s%s\n' % (padding, from_msg)
    yield '%s<b><u>Traceback (most recent call last)</u></b>' % padding
    tblist = traceback.extract_tb(exc.__traceback__)
    tbdepth = len(tblist)
    for x in tblist:
        depth = '%d.' % tbdepth
        yield '%s<dim>%-3s</dim> <cyan>File</cyan> "<blue>%s</blue>", ' \
            'line <u>%d</u>, in <b>%s</b>' % (padding, depth, x.filename,
                                              x.lineno, x.name)
        yield '%s      %s' % (padding, x.line)
        tbdepth -= 1
    yield '%s<b><red>%s</red>: %s</b>' % (padding, type(exc).__name__, exc)
    return indent + 1
254758
def format_exception(etype, value, tback, limit=None):
    

    rtn = ['Traceback (most recent call last):\n']

    if limit is None or limit >= 0:
        rtn.extend(traceback.format_tb(tback, limit))
    else:
        rtn.extend(traceback.format_list(traceback.extract_tb(tback)[limit:]))

    rtn.extend(traceback.format_exception_only(etype, value))

    return rtn
438835
def log_fault_info_str (exc_info, message = "", level = logging.CRITICAL,
                        traceback = False):
  
  tb = sys.exc_info ()[2]
  stack = _get_stack (tb)
  rc = StringIO ()
  rc.write ("%s: FAULT: %s%s(%s): %s\n"
            % (logging.getLevelName (level),
               ("%s -- " % message) if message else "",
               tb.tb_frame.f_code.co_filename,
               tb.tb_lineno,
               repr (exc_info[1])))
  if traceback:
    for line in _generate_stackdump (stack):
      rc.write ("%s\n" % line)
  return rc.getvalue ()
852033
def errorRecorder(self, lineNumber, offset, text, check):
        
        code = text.split(" ")[0]
        lineOffset = self.report.line_offset

        self.warnings.append((lineOffset + lineNumber,
                              offset + 1, code, text))
1031148
def format_python_stack(self):
        
        ret = ["Traceback:\n"]
        ret.extend(traceback.format_tb(self.original_traceback))
        return "".join(ret)
934835
def debug_text_simple(self, text: str):
        
        self._debug_texts.append(self.to_debug_message(text))
929781
def get_traceback(f):
  
  @functools.wraps(f)
  def wrapper(*args, **kwargs):
    try:
      return f(*args, **kwargs)
    except Exception, ex:
      ret = '#' * 60
      ret += "\nException caught:"
      ret += "\n" + '-' * 60
      ret += "\n" + traceback.format_exc()
      ret += "\n" + '-' * 60
      ret += "\n" + "#" * 60
      print sys.stderr, ret
      sys.stderr.flush()
      raise ex

  return wrapper
1275964
def failure_format_traceback(self, fail):
        
        try:
            f = six.StringIO()
            fail.printTraceback(file=f)
            return f.getvalue()
        except Exception:
            return u"Failed to format failure traceback for '{0}'".format(fail)
196235
def _extract_msg_from_last_exception():
    '''  '''
    last_exc_type, last_error, last_traceback = sys.exc_info()
    if isinstance(last_error, exceptions.DXAPIError):
        # Using the same code path as below would not
        # produce a useful message when the error contains a
        # 'details' hash (which would have a last line of
        # '}')
        return last_error.error_message()
    else:
        return traceback.format_exc().splitlines()[-1].strip()
624548
def tracebacks_from_lines(lines_iter):
    

    tbgrep = TracebackGrep()

    for line in lines_iter:
        tb = tbgrep.process(line)
        if tb:
            yield tb
198107
def pformat(self, traceback=False):
        """"""
        buf = six.StringIO()
        if not self._exc_type_names:
            buf.write('Failure: %s' % (self._exception_str))
        else:
            buf.write('Failure: %s: %s' % (self._exc_type_names[0],
                                           self._exception_str))
        if traceback:
            if self._traceback_str is not None:
                traceback_str = self._traceback_str.rstrip()
            else:
                traceback_str = None
            if traceback_str:
                buf.write(os.linesep)
                buf.write(traceback_str)
            else:
                buf.write(os.linesep)
                buf.write('Traceback not available.')
        return buf.getvalue()
1124740
def output_traceback(ex):
    """"""
    # Dump full traceback to console.
    output = "".join(traceback.format_exc()).strip()
    for line in output.split('\n'):
        logging.error(line)
    trace_obj = traceback.extract_tb(ex.__traceback__)[-1]
    trace = [basename(trace_obj[0]), trace_obj[1]]
    name = type(ex).__name__
    output = str(ex).replace('\n', ' ')
    msg = "%s in %s on line %s: %s" % (name, trace[0], trace[1], output)
    return (msg, output)
491300
def wrap_traceback(traceback):
    
    if email().format == 'html':
        try:
            from pygments import highlight
            from pygments.lexers import PythonTracebackLexer
            from pygments.formatters import HtmlFormatter
            with_pygments = True
        except ImportError:
            with_pygments = False

        if with_pygments:
            formatter = HtmlFormatter(noclasses=True)
            wrapped = highlight(traceback, PythonTracebackLexer(), formatter)
        else:
            wrapped = '<pre>%s</pre>' % traceback
    else:
        wrapped = traceback

    return wrapped
1029971
def get_real_last_traceback(exception):
    
    traceback_blocks = []
    _n, _n, exc_traceback = sys.exc_info()
    tb_list = get_all_tracebacks(exc_traceback)[1:]

    # Remove already captured tracebacks
    # TODO(jmv): This must be a better way of doing this. Need to revisit.
    tb_list = [tb for tb in tb_list if tb not in CAPTURED_TRACEBACKS]
    CAPTURED_TRACEBACKS.extend(tb_list)

    for traceback in tb_list:
        lines, path, line_num = get_source_from_frame(traceback.tb_frame)
        traceback_lines = get_numbered_source(lines, traceback.tb_lineno,
                                              line_num)

        traceback_lines.insert(0, '  - {0}'.format(path))
        traceback_lines.insert(1, '  ------------------')
        traceback_lines.append('  ------------------')
        traceback_blocks.append(traceback_lines)

    traced_lines = ['Error Traceback:']
    traced_lines.extend(itertools.chain.from_iterable(traceback_blocks))
    traced_lines.append('  - Error | {0}: {1}'.format(
        type(exception).__name__, exception))

    return traced_lines
426632
def ErrorMsg():
    
    import traceback

    limit = None
    _type, value, tb = sys.exc_info()
    _list = traceback.format_tb(tb, limit) + \
        traceback.format_exception_only(_type, value)
    return "Traceback (innermost last):\n" + "%-20s %s" % (
        " ".join(_list[:-1]),
        _list[-1])