Skip to content

Commit

Permalink
Merge pull request #1074 from zooba/issue-1043
Browse files Browse the repository at this point in the history
Issue 1043
  • Loading branch information
zooba committed Jan 30, 2016
2 parents df333e7 + acb4ac5 commit 1c2c892
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions Python/Product/PythonTools/visualstudio_py_debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,9 +641,12 @@ def line_locations(self):
line_info = []
file_len = 0
for line in contents:
line_len = len(line)
if not line_info and line.startswith(BOM_UTF8):
line = line[3:] # Strip the BOM, Django seems to ignore this...
file_len += len(line)
line_len -= len(BOM_UTF8) # Strip the BOM, Django seems to ignore this...
if line.endswith(to_bytes('\r\n')):
line_len -= 1 # Django normalizes newlines to \n
file_len += line_len
line_info.append(file_len)
contents.close()
self._line_locations = line_info
Expand Down Expand Up @@ -674,10 +677,26 @@ def should_break(self, start, end):
def get_django_frame_source(frame):
if frame.f_code.co_name == 'render':
self_obj = frame.f_locals.get('self', None)
if self_obj is not None and type(self_obj).__name__ != 'TextNode':
source_obj = getattr(self_obj, 'source', None)
if source_obj is not None:
return source_obj
if self_obj is None:
return None
name = type(self_obj).__name__
if name in ('Template', 'TextNode'):
return None
source_obj = getattr(self_obj, 'source', None)
if source_obj and hasattr(source_obj, '__len__') and len(source_obj) == 2:
return str(source_obj[0]), source_obj[1]

token_obj = getattr(self_obj, 'token', None)
if token_obj is None:
return None
template_obj = getattr(frame.f_locals.get('context', None), 'template', None)
if template_obj is None:
return None
template_name = getattr(template_obj, 'origin', None)
position = getattr(token_obj, 'position', None)
if template_name and position:
return str(template_name), position


return None

Expand Down Expand Up @@ -878,8 +897,8 @@ def handle_call(self, frame, arg):
source_obj = get_django_frame_source(frame)
if source_obj is not None:
origin, (start, end) = source_obj
active_bps = DJANGO_BREAKPOINTS.get(origin.name.lower())

active_bps = DJANGO_BREAKPOINTS.get(origin.lower())
should_break = False
if active_bps is not None:
should_break, bkpt_id = active_bps.should_break(start, end)
Expand Down

0 comments on commit 1c2c892

Please sign in to comment.