def launch_browser(): url = S.get_project_value('url') or S.get_package_value('url') if not url: sublime.status_message('Xdebug: No URL defined in (project) settings file.') return ide_key = S.get_project_value('ide_key') or S.get_package_value('ide_key') or S.DEFAULT_IDE_KEY if S.SESSION and (S.SESSION.listening or not S.SESSION.connected): webbrowser.open(url + '?XDEBUG_SESSION_START=' + ide_key) else: webbrowser.open(url + '?XDEBUG_SESSION_STOP=' + ide_key)
def launch_browser(): url = S.get_project_value('url') or S.get_package_value('url') if not url: sublime.status_message( 'Xdebug: No URL defined in (project) settings file.') return ide_key = S.get_project_value('ide_key') or S.get_package_value( 'ide_key') or S.DEFAULT_IDE_KEY if S.SESSION and (S.SESSION.listening or not S.SESSION.connected): webbrowser.open(url + '?XDEBUG_SESSION_START=' + ide_key) else: webbrowser.open(url + '?XDEBUG_SESSION_STOP=' + ide_key)
def get_context_values(): """ Get variables in current context. """ if S.SESSION: context = H.new_dictionary() try: # Super global variables if S.get_project_value('super_globals') or S.get_package_value('super_globals'): S.SESSION.send(dbgp.CONTEXT_GET, c=1) response = S.SESSION.read() context.update(get_response_properties(response)) # Local variables S.SESSION.send(dbgp.CONTEXT_GET) response = S.SESSION.read() context.update(get_response_properties(response)) except (socket.error, ProtocolConnectionException): e = sys.exc_info()[1] connection_error("%s" % e) # Store context variables in session S.CONTEXT_DATA = context return generate_context_output(context)
def get_context_values(): """ Get variables in current context. """ if S.SESSION: context = H.new_dictionary() try: # Super global variables if S.get_project_value('super_globals') or S.get_package_value( 'super_globals'): S.SESSION.send(dbgp.CONTEXT_GET, c=1) response = S.SESSION.read() context.update(get_response_properties(response)) # Local variables S.SESSION.send(dbgp.CONTEXT_GET) response = S.SESSION.read() context.update(get_response_properties(response)) except (socket.error, ProtocolConnectionException): e = sys.exc_info()[1] connection_error("%s" % e) # Store context variables in session S.CONTEXT_DATA = context return generate_context_output(context)
def __init__(self): # Set port number to listen for response self.port = S.get_project_value('port') or S.get_package_value('port') or S.DEFAULT_PORT self.clear()
def get_response_properties(response, default_key=None): """ Return a dictionary with available properties from response. Keyword arguments: response -- Response from debugger engine. default_key -- Index key to use when property has no name. """ properties = H.new_dictionary() # Walk through elements in response for child in response: # Read property elements if child.tag == dbgp.ELEMENT_PROPERTY or child.tag == dbgp.ELEMENT_PATH_PROPERTY: # Get property attribute values property_name_short = child.get(dbgp.PROPERTY_NAME) property_name = child.get(dbgp.PROPERTY_FULLNAME, property_name_short) property_type = child.get(dbgp.PROPERTY_TYPE) property_children = child.get(dbgp.PROPERTY_CHILDREN) property_numchildren = child.get(dbgp.PROPERTY_NUMCHILDREN) property_classname = child.get(dbgp.PROPERTY_CLASSNAME) property_value = None if child.text: try: # Try to base64 decode value property_value = H.base64_decode(child.text) except: # Return raw value property_value = child.text if property_name is not None and len(property_name) > 0: property_key = property_name # Ignore following properties if property_name == "::": continue # Avoid nasty static functions/variables from turning in an infinitive loop if property_name.count("::") > 1: continue # Filter password values hide_password = S.get_project_value('hide_password') or S.get_package_value('hide_password', True) if hide_password and property_name.lower().find('password') != -1 and property_value is not None: property_value = '******' else: property_key = default_key # Store property if property_key: properties[property_key] = { 'name': property_name, 'type': property_type, 'value': property_value, 'numchildren': property_numchildren, 'children' : None } # Get values for children if property_children: properties[property_key]['children'] = get_response_properties(child, default_key) # Set classname, if available, as type for object if property_classname and property_type == 'object': properties[property_key]['type'] = property_classname # Handle error elements elif child.tag == dbgp.ELEMENT_ERROR or child.tag == dbgp.ELEMENT_PATH_ERROR: message = 'error' for step_child in child: if step_child.tag == dbgp.ELEMENT_MESSAGE or step_child.tag == dbgp.ELEMENT_PATH_MESSAGE and step_child.text: message = step_child.text break if default_key: properties[default_key] = { 'name': None, 'type': message, 'value': None, 'numchildren': None, 'children': None } return properties
def debug(message=None): debug = S.get_project_value('debug') or S.get_package_value('debug') or S.DEBUG if not debug or message is None: return # Write message to output file logging.debug(message)
def get_real_path(uri, server=False): """ Get real path Keyword arguments: uri -- Uri of file that needs to be mapped and located server -- Map local path to server path TODO: Fix mapping for root (/) and drive letters (P:/) """ if uri is None: return uri # URLdecode uri uri = H.url_decode(uri) # Split scheme from uri to get absolute path try: # scheme:///path/file => scheme, /path/file # scheme:///C:/path/file => scheme, C:/path/file transport, filename = uri.split(':///', 1) except: filename = uri # Normalize path for comparison and remove duplicate/trailing slashes uri = os.path.normpath(filename) # Pattern for checking if uri is a windows path drive_pattern = re.compile(r'^[a-zA-Z]:[\\/]') # Append leading slash if filesystem is not Windows if not drive_pattern.match(uri) and not os.path.isabs(uri): uri = os.path.normpath('/' + uri) path_mapping = S.get_project_value('path_mapping') or S.get_package_value('path_mapping') if not path_mapping is None: # Go through path mappings for server_path, local_path in path_mapping.items(): server_path = os.path.normpath(server_path) local_path = os.path.normpath(local_path) # Replace path if mapping available if server: # Map local path to server path if local_path in uri: uri = uri.replace(local_path, server_path) break else: # Map server path to local path if server_path in uri: uri = uri.replace(server_path, local_path) break else: sublime.status_message("Xdebug: No path mapping defined, returning given path.") # Replace slashes if not drive_pattern.match(uri): uri = uri.replace("\\", "/") # Append scheme if server: return H.url_encode("file://" + uri) return uri
def __init__(self): # Set port number to listen for response self.port = S.get_project_value('port') or S.get_package_value( 'port') or S.DEFAULT_PORT self.clear()
def get_response_properties(response, default_key=None): """ Return a dictionary with available properties from response. Keyword arguments: response -- Response from debugger engine. default_key -- Index key to use when property has no name. """ properties = H.new_dictionary() # Walk through elements in response for child in response: # Read property elements if child.tag == dbgp.ELEMENT_PROPERTY or child.tag == dbgp.ELEMENT_PATH_PROPERTY: # Get property attribute values property_name_short = child.get(dbgp.PROPERTY_NAME) property_name = child.get(dbgp.PROPERTY_FULLNAME, property_name_short) property_type = child.get(dbgp.PROPERTY_TYPE) property_children = child.get(dbgp.PROPERTY_CHILDREN) property_numchildren = child.get(dbgp.PROPERTY_NUMCHILDREN) property_classname = child.get(dbgp.PROPERTY_CLASSNAME) property_value = None if child.text: try: # Try to base64 decode value property_value = H.base64_decode(child.text) except: # Return raw value property_value = child.text if property_name is not None and len(property_name) > 0: property_key = property_name # Ignore following properties if property_name == "::": continue # Avoid nasty static functions/variables from turning in an infinitive loop if property_name.count("::") > 1: continue # Filter password values hide_password = S.get_project_value( 'hide_password') or S.get_package_value( 'hide_password', True) if hide_password and property_name.lower().find( 'password') != -1 and property_value is not None: property_value = '******' else: property_key = default_key # Store property if property_key: properties[property_key] = { 'name': property_name, 'type': property_type, 'value': property_value, 'numchildren': property_numchildren, 'children': None } # Get values for children if property_children: properties[property_key][ 'children'] = get_response_properties( child, default_key) # Set classname, if available, as type for object if property_classname and property_type == 'object': properties[property_key]['type'] = property_classname # Handle error elements elif child.tag == dbgp.ELEMENT_ERROR or child.tag == dbgp.ELEMENT_PATH_ERROR: message = 'error' for step_child in child: if step_child.tag == dbgp.ELEMENT_MESSAGE or step_child.tag == dbgp.ELEMENT_PATH_MESSAGE and step_child.text: message = step_child.text break if default_key: properties[default_key] = { 'name': None, 'type': message, 'value': None, 'numchildren': None, 'children': None } return properties
def get_real_path(uri, server=False): """ Get real path Keyword arguments: uri -- Uri of file that needs to be mapped and located server -- Map local path to server path TODO: Fix mapping for root (/) and drive letters (P:/) """ if uri is None: return uri # URLdecode uri uri = H.url_decode(uri) # Split scheme from uri to get absolute path try: # scheme:///path/file => scheme, /path/file # scheme:///C:/path/file => scheme, C:/path/file transport, filename = uri.split(':///', 1) except: filename = uri # Normalize path for comparison and remove duplicate/trailing slashes uri = os.path.normpath(filename) # Pattern for checking if uri is a windows path drive_pattern = re.compile(r'^[a-zA-Z]:[\\/]') # Append leading slash if filesystem is not Windows if not drive_pattern.match(uri) and not os.path.isabs(uri): uri = os.path.normpath('/' + uri) path_mapping = S.get_project_value('path_mapping') or S.get_package_value( 'path_mapping') if not path_mapping is None: # Go through path mappings for server_path, local_path in path_mapping.items(): server_path = os.path.normpath(server_path) local_path = os.path.normpath(local_path) # Replace path if mapping available if server: # Map local path to server path if local_path in uri: uri = uri.replace(local_path, server_path) break else: # Map server path to local path if server_path in uri: uri = uri.replace(server_path, local_path) break else: sublime.status_message( "Xdebug: No path mapping defined, returning given path.") # Replace slashes if not drive_pattern.match(uri): uri = uri.replace("\\", "/") # Append scheme if server: return H.url_encode("file://" + uri) return uri