8787datetime .strptime ('2017-01-01' , '%Y-%m-%d' )
8888
8989
90- def _IsRootInitPy (path ):
91- return path .lstrip (os .sep ) == '__init__.py'
92-
93-
9490def _StripCommonPathPrefix (paths ):
9591 """Removes path common prefix from a list of path strings."""
9692 # Find the longest common prefix in terms of characters.
@@ -124,6 +120,11 @@ def _MultipleModulesFoundError(path, candidates):
124120 return fmt , params
125121
126122
123+ def _SanitizePath (path ):
124+ """Removes leading/trailing whitespace, and leading path separator."""
125+ return path .strip ().lstrip (os .sep )
126+
127+
127128class PythonBreakpoint (object ):
128129 """Handles a single Python breakpoint.
129130
@@ -166,9 +167,9 @@ def __init__(self, definition, hub_client, breakpoints_manager,
166167 if self .definition .get ('action' ) == 'LOG' :
167168 self ._collector = capture_collector .LogCollector (self .definition )
168169
169- # TODO(erezh): Ensure we handle whitespace in paths correctly.
170- # including, extension, basename, location_path
171- path = self . definition [ 'location' ][ 'path' ]
170+ path = _SanitizePath ( self . definition [ 'location' ][ 'path' ])
171+
172+ # Only accept .py extension.
172173 if os .path .splitext (path )[1 ] != '.py' :
173174 self ._CompleteBreakpoint ({
174175 'status' : {
@@ -177,7 +178,8 @@ def __init__(self, definition, hub_client, breakpoints_manager,
177178 'description' : {'format' : ERROR_LOCATION_FILE_EXTENSION_0 }}})
178179 return
179180
180- if _IsRootInitPy (path ):
181+ # A flat init file is too generic; path must include package name.
182+ if path == '__init__.py' :
181183 self ._CompleteBreakpoint ({
182184 'status' : {
183185 'isError' : True ,
@@ -429,3 +431,4 @@ def _BreakpointEvent(self, event, frame):
429431 collector .Collect (frame )
430432
431433 self ._CompleteBreakpoint (collector .breakpoint , is_incremental = False )
434+
0 commit comments