Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/python/pyste/src/Pyste/utils.py @ 29

Last change on this file since 29 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 2.6 KB
Line 
1# Copyright Bruno da Silva de Oliveira 2003. Use, modification and
2# distribution is subject to the Boost Software License, Version 1.0.
3# (See accompanying file LICENSE_1_0.txt or copy at
4# http:#www.boost.org/LICENSE_1_0.txt)
5
6from __future__ import generators
7import string
8import sys
9
10#==============================================================================
11# enumerate
12#==============================================================================
13def enumerate(seq):
14    i = 0
15    for x in seq:
16        yield i, x
17        i += 1 
18
19
20#==============================================================================
21# makeid
22#==============================================================================
23_valid_chars = string.ascii_letters + string.digits + '_'
24_valid_chars = dict(zip(_valid_chars, _valid_chars))
25
26def makeid(name):
27    'Returns the name as a valid identifier'
28    if type(name) != str:
29        print type(name), name
30    newname = []
31    for char in name:
32        if char not in _valid_chars:
33            char = '_'
34        newname.append(char)
35    newname = ''.join(newname)
36    # avoid duplications of '_' chars
37    names = [x for x in newname.split('_') if x]
38    return '_'.join(names)
39 
40
41#==============================================================================
42# remove_duplicated_lines
43#==============================================================================
44def remove_duplicated_lines(text):
45    includes = text.splitlines()
46    d = dict([(include, 0) for include in includes])
47    includes = d.keys()
48    includes.sort()
49    return '\n'.join(includes)
50
51
52#==============================================================================
53# left_equals
54#==============================================================================
55def left_equals(s):
56        s = '// %s ' % s
57        return s + ('='*(80-len(s))) + '\n' 
58
59
60#==============================================================================
61# post_mortem   
62#==============================================================================
63def post_mortem():
64
65    def info(type, value, tb):
66       if hasattr(sys, 'ps1') or not sys.stderr.isatty():
67          # we are in interactive mode or we don't have a tty-like
68          # device, so we call the default hook
69          sys.__excepthook__(type, value, tb)
70       else:
71          import traceback, pdb
72          # we are NOT in interactive mode, print the exception...
73          traceback.print_exception(type, value, tb)
74          print
75          # ...then start the debugger in post-mortem mode.
76          pdb.pm()
77
78    sys.excepthook = info
Note: See TracBrowser for help on using the repository browser.