call site 0 for code.Source.__getslice__
code/testing/test_excinfo.py - line 86
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
   def test_traceback_entry_getsource_in_construct(self):
       source = py.code.Source("""\
               def xyz():
                   try:
                       raise ValueError
                   except somenoname:
                       pass
               xyz()
           """) 
       try: 
           exec source.compile()
       except NameError: 
           tb = py.code.ExceptionInfo().traceback 
           print tb[-1].getsource()
->         s = str(tb[-1].getsource())
           assert s.startswith("def xyz():\n    try:")
           assert s.endswith("except somenoname:") 
code/traceback2.py - line 58
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
   def getsource(self): 
       """ return failing source code. """ 
       source = self.frame.code.fullsource
       start = self.getfirstlinesource()
       end = self.lineno
       try:
->         _, end = source.getstatementrange(end) 
       except IndexError: 
           end = self.lineno + 1 
       # heuristic to stop displaying source on e.g. 
       #   if something:  # assume this causes a NameError
       #      # _this_ lines and the one 
              #        below we don't want from entry.getsource() 
       for i in range(self.lineno, end): 
           if source[i].rstrip().endswith(':'): 
               end = i + 1
               break 
       return source[start:end]
code/source.py - line 124
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
   def getstatementrange(self, lineno):
       """ return (start, end) tuple which spans the minimal 
               statement region which containing the given lineno.
           """
       # XXX there must be a better than these heuristic ways ...
       # XXX there may even be better heuristics :-)
       if not (0 <= lineno < len(self)):
           raise IndexError("lineno out of range")
   
       # 1. find the start of the statement
       from codeop import compile_command
       for start in range(lineno, -1, -1):
           trylines = self.lines[start:lineno+1]
           # quick hack to indent the source and get it as a string in one go
           trylines.insert(0, 'def xxx():')
           trysource = '\n '.join(trylines)
           #              ^ space here
           try:
               compile_command(trysource)
           except (SyntaxError, OverflowError, ValueError):
               pass
           else:
               break   # got a valid or incomplete statement
   
       # 2. find the end of the statement
       for end in range(lineno+1, len(self)+1):
->         trysource = self[start:end]
           if trysource.isparseable():
               break
   
       return start, end