当前位置: 首页>>代码示例>>Python>>正文


Python helper.H类代码示例

本文整理汇总了Python中helper.H的典型用法代码示例。如果您正苦于以下问题:Python H类的具体用法?Python H怎么用?Python H使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了H类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: generate_stack_output

def generate_stack_output(response):
    values = H.unicode_string('')

    # Display exception name and message
    if S.BREAKPOINT_EXCEPTION:
        values += H.unicode_string('[{name}] {message}\n' \
                                  .format(name=S.BREAKPOINT_EXCEPTION['name'], message=S.BREAKPOINT_EXCEPTION['message']))

    # Walk through elements in response
    has_output = False
    try:
        for child in response:
            # Get stack attribute values
            if child.tag == dbgp.ELEMENT_STACK or child.tag == dbgp.ELEMENT_PATH_STACK:
                stack_level = child.get(dbgp.STACK_LEVEL, 0)
                stack_type = child.get(dbgp.STACK_TYPE)
                stack_file = H.url_decode(child.get(dbgp.STACK_FILENAME))
                stack_line = child.get(dbgp.STACK_LINENO, 0)
                stack_where = child.get(dbgp.STACK_WHERE, '{unknown}')
                # Append values
                values += H.unicode_string('[{level}] {filename}.{where}:{lineno}\n' \
                                          .format(level=stack_level, type=stack_type, where=stack_where, lineno=stack_line, filename=stack_file))
                has_output = True
    except:
        pass

    # When no stack use values from exception
    if not has_output and S.BREAKPOINT_EXCEPTION:
        values += H.unicode_string('[{level}] {filename}.{where}:{lineno}\n' \
                                  .format(level=0, where='{unknown}', lineno=S.BREAKPOINT_EXCEPTION['lineno'], filename=S.BREAKPOINT_EXCEPTION['filename']))

    return values
开发者ID:willbeaufoy,项目名称:SublimeTextXdebug,代码行数:32,代码来源:view.py

示例2: get_stack_values

def get_stack_values():
    """
    Get stack information for current context.
    """
    values = H.unicode_string('')
    if S.SESSION:
        try:
            # Get stack information
            S.SESSION.send(dbgp.STACK_GET)
            response = S.SESSION.read()

            for child in response:
                # Get stack attribute values
                if child.tag == dbgp.ELEMENT_STACK or child.tag == dbgp.ELEMENT_PATH_STACK:
                    stack_level = child.get(dbgp.STACK_LEVEL, 0)
                    stack_type = child.get(dbgp.STACK_TYPE)
                    stack_file = H.url_decode(child.get(dbgp.STACK_FILENAME))
                    stack_line = child.get(dbgp.STACK_LINENO, 0)
                    stack_where = child.get(dbgp.STACK_WHERE, '{unknown}')
                    # Append values
                    values += H.unicode_string('[{level}] {filename}.{where}:{lineno}\n' \
                                              .format(level=stack_level, type=stack_type, where=stack_where, lineno=stack_line, filename=stack_file))
        except (socket.error, ProtocolConnectionException):
            e = sys.exc_info()[1]
            connection_error("%s" % e)
    return values
开发者ID:pirog,项目名称:SublimeTextXdebug,代码行数:26,代码来源:session.py

示例3: generate_watch_output

def generate_watch_output():
    """
    Generate output with all watch expressions.
    """
    values = H.unicode_string('')
    if S.WATCH is None:
        return values
    for watch_data in S.WATCH:
        watch_entry = ''
        if watch_data and isinstance(watch_data, dict):
            # Whether watch expression is enabled or disabled
            if 'enabled' in watch_data.keys():
                if watch_data['enabled']:
                    watch_entry += '|+|'
                else:
                    watch_entry += '|-|'
            # Watch expression
            if 'expression' in watch_data.keys():
                watch_entry += ' "%s"' % watch_data['expression']
            # Evaluated value
            if watch_data['value'] is not None:
                watch_entry += ' = ' + generate_context_output(watch_data['value'])
            else:
                watch_entry += "\n"
        values += H.unicode_string(watch_entry)
    return values
开发者ID:willbeaufoy,项目名称:SublimeTextXdebug,代码行数:26,代码来源:view.py

示例4: generate_breakpoint_output

def generate_breakpoint_output():
    """
    Generate output with all configured breakpoints.
    """
    # Get breakpoints for files
    values = H.unicode_string('')
    if S.BREAKPOINT is None:
        return values
    for filename, breakpoint_data in sorted(S.BREAKPOINT.items()):
        breakpoint_entry = ''
        if breakpoint_data:
            breakpoint_entry += "=> %s\n" % filename
            # Sort breakpoint data by line number
            for lineno, bp in sorted(breakpoint_data.items(), key=lambda item: (int(item[0]) if isinstance(item[0], int) or H.is_digit(item[0]) else float('inf'), item[0])):
                # Do not show temporary breakpoint
                if S.BREAKPOINT_RUN is not None and S.BREAKPOINT_RUN['filename'] == filename and S.BREAKPOINT_RUN['lineno'] == lineno:
                    continue
                # Whether breakpoint is enabled or disabled
                breakpoint_entry += '\t'
                if bp['enabled']:
                    breakpoint_entry += '|+|'
                else:
                    breakpoint_entry += '|-|'
                # Line number
                breakpoint_entry += ' %s' % lineno
                # Conditional expression
                if bp['expression'] is not None:
                    breakpoint_entry += ' -- "%s"' % bp['expression']
                breakpoint_entry += "\n"
        values += H.unicode_string(breakpoint_entry)
    return values
开发者ID:willbeaufoy,项目名称:SublimeTextXdebug,代码行数:31,代码来源:view.py

示例5: generate_context_output

def generate_context_output(context, indent=0):
    """
    Generate readable context from dictionary with context data.

    Keyword arguments:
    context -- Dictionary with context data.
    indent -- Indent level.
    """
    # Generate output text for values
    values = H.unicode_string('')
    if not isinstance(context, dict):
        return values
    for variable in context.values():
        has_children = False
        property_text = ''
        # Set indentation
        for i in range(indent): property_text += '\t'
        # Property with value
        if variable['value'] is not None:
            if variable['name']:
                property_text += '{name} = '
            property_text += '({type}) {value}\n'
        # Property with children
        elif isinstance(variable['children'], dict) and variable['numchildren'] is not None:
            has_children = True
            if variable['name']:
                property_text += '{name} = '
            property_text += '{type}[{numchildren}]\n'
        # Unknown property
        else:
            if variable['name']:
                property_text += '{name} = '
            property_text += '<{type}>\n'

        # Remove newlines in value to prevent incorrect indentation
        value = ''
        if variable['value'] and len(variable['value']) > 0:
            value = variable['value'].replace("\r\n", "\n").replace("\n", " ")

        # Format string and append to output
        values += H.unicode_string(property_text \
                        .format(value=value, type=variable['type'], name=variable['name'], numchildren=variable['numchildren']))

        # Append property children to output
        if has_children:
            # Get children for property (no need to convert, already unicode)
            values += generate_context_output(variable['children'], indent+1)
            # Use ellipsis to indicate that results have been truncated
            limited = False
            if isinstance(variable['numchildren'], int) or H.is_digit(variable['numchildren']):
                if int(variable['numchildren']) != len(variable['children']):
                    limited = True
            elif len(variable['children']) > 0 and not variable['numchildren']:
                limited = True
            if limited:
                for i in range(indent+1): values += H.unicode_string('\t')
                values += H.unicode_string('...\n')
    return values
开发者ID:willbeaufoy,项目名称:SublimeTextXdebug,代码行数:58,代码来源:view.py

示例6: set_layout

def set_layout(layout):
    """
    Toggle between debug and default window layouts.
    """
    # Get active window and set reference to active view
    window = sublime.active_window()
    previous_active = window.active_view()

    # Do not set layout when disabled
    if get_value(S.KEY_DISABLE_LAYOUT):
        S.RESTORE_LAYOUT = window.get_layout()
        set_window_value('restore_layout', S.RESTORE_LAYOUT)
        S.RESTORE_INDEX = H.new_dictionary()
        set_window_value('restore_index', S.RESTORE_INDEX)
        return

    # Show debug layout
    if layout == 'debug':
        debug_layout = get_value(S.KEY_DEBUG_LAYOUT, S.LAYOUT_DEBUG)
        if window.get_layout() != debug_layout:
            # Save current layout
            S.RESTORE_LAYOUT = window.get_layout()
            set_window_value('restore_layout', S.RESTORE_LAYOUT)
            # Remember view indexes
            S.RESTORE_INDEX = H.new_dictionary()
            for view in window.views():
                view_id = "%d" % view.id()
                group, index = window.get_view_index(view)
                S.RESTORE_INDEX[view_id] = { "group": group, "index": index }
            set_window_value('restore_index', S.RESTORE_INDEX)
            # Set debug layout
            window.set_layout(S.LAYOUT_NORMAL)
        window.set_layout(debug_layout)
    # Show previous (single) layout
    else:
        # Get previous layout configuration
        if S.RESTORE_LAYOUT is None:
            S.RESTORE_LAYOUT = get_window_value('restore_layout', S.LAYOUT_NORMAL)
        if S.RESTORE_INDEX is None:
            S.RESTORE_INDEX = get_window_value('restore_index', {})
        # Restore layout
        window.set_layout(S.LAYOUT_NORMAL)
        window.set_layout(S.RESTORE_LAYOUT)
        for view in window.views():
            view_id = "%d" % view.id()
            # Set view indexes
            if view_id in H.dictionary_keys(S.RESTORE_INDEX):
                v = S.RESTORE_INDEX[view_id]
                window.set_view_index(view, v["group"], v["index"])

    # Restore focus to previous active view
    if not previous_active is None:
        window.focus_view(previous_active)
开发者ID:willbeaufoy,项目名称:SublimeTextXdebug,代码行数:53,代码来源:view.py

示例7: generate_stack_output

def generate_stack_output(response):
    values = H.unicode_string('')

    # Display exception name and message
    if S.BREAKPOINT_EXCEPTION:
        values += H.unicode_string('[{name}] {message}\n' \
                                  .format(name=S.BREAKPOINT_EXCEPTION['name'], message=S.BREAKPOINT_EXCEPTION['message']))

    # Walk through elements in response
    has_output = False
    try:
        for child in response:
            # Get stack attribute values
            if child.tag == dbgp.ELEMENT_STACK or child.tag == dbgp.ELEMENT_PATH_STACK:
                stack_level = child.get(dbgp.STACK_LEVEL, 0)
                stack_type = child.get(dbgp.STACK_TYPE)
                stack_file = H.url_decode(child.get(dbgp.STACK_FILENAME))
                stack_line = child.get(dbgp.STACK_LINENO, 0)
                stack_where = child.get(dbgp.STACK_WHERE, '{unknown}')
                # Append values
                filename = os.path.basename(stack_file)
                values += H.unicode_string('[{level}] {lineno} {filename} {where} {filepath}\n' \
                                          .format(level=stack_level, type=stack_type, where=stack_where, lineno=stack_line, filepath=stack_file, filename=filename))
                has_output = True
    except:
        pass

    # When no stack use values from exception
    if not has_output and S.BREAKPOINT_EXCEPTION:
        filename = os.path.basename(stack_file)
        values += H.unicode_string('[{level}] {lineno} {filename} {where} {filepath}\n' \
                                  .format(level=0, where='{unknown}', lineno=S.BREAKPOINT_EXCEPTION['lineno'], filepath=S.BREAKPOINT_EXCEPTION['filename'], filename=filename))

    # Space all out equally
    lines = values.split('\n')
    lines_bits = [x.strip().split(' ') for x in lines]
    bit_widths = []
    for line_bits in lines_bits:
        for i, line_bit in enumerate(line_bits):
            line_bits[i] = line_bit.strip()
            if len(bit_widths) <= i:
                bit_widths.append(0)
            bit_widths[i] = max(bit_widths[i], len(line_bit.strip()))
    new_lines = []
    for i, line_bits in enumerate(lines_bits):
        if(len(line_bits) > 1):
            line_bits[1] = line_bits[1].rjust(bit_widths[1])
        new_lines.append(' '.join([b.ljust(bit_widths[j]) for j, b in enumerate(line_bits)]))
    values = '\n'.join(new_lines)
    return values
开发者ID:sligodave,项目名称:SublimeTextXdebug,代码行数:50,代码来源:view.py

示例8: set_layout

def set_layout(layout):
    """
    Toggle between debug and default window layouts.
    """
    # Get active window and set reference to active view
    window = sublime.active_window()
    previous_active = window.active_view()

    # Show debug layout
    if layout == 'debug':
        if window.get_layout() != S.LAYOUT_DEBUG:
            # Save current layout
            S.RESTORE_LAYOUT = window.get_layout()
            S.set_window_value('restore_layout', S.RESTORE_LAYOUT)
            # Remember view indexes
            S.RESTORE_INDEX = H.new_dictionary()
            for view in window.views():
                view_id = "%d" % view.id()
                group, index = window.get_view_index(view)
                S.RESTORE_INDEX[view_id] = { "group": group, "index": index }
            S.set_window_value('restore_index', S.RESTORE_INDEX)
            # Set debug layout
            window.set_layout(S.LAYOUT_NORMAL)
        window.set_layout(S.LAYOUT_DEBUG)
    # Show previous (single) layout
    else:
        # Get previous layout configuration
        if S.RESTORE_LAYOUT is None:
            S.RESTORE_LAYOUT = S.get_window_value('restore_layout', S.LAYOUT_NORMAL)
        if S.RESTORE_INDEX is None:
            S.RESTORE_INDEX = S.get_window_value('restore_index', {})
        # Restore layout
        window.set_layout(S.LAYOUT_NORMAL)
        window.set_layout(S.RESTORE_LAYOUT)
        for view in window.views():
            view_id = "%d" % view.id()
            # Set view indexes
            if view_id in H.dictionary_keys(S.RESTORE_INDEX):
                v = S.RESTORE_INDEX[view_id]
                window.set_view_index(view, v["group"], v["index"])
            # Close all debugging related windows
            if view.name() == TITLE_WINDOW_BREAKPOINT or view.name() == TITLE_WINDOW_CONTEXT or view.name() == TITLE_WINDOW_STACK or view.name() == TITLE_WINDOW_WATCH:
                window.focus_view(view)
                window.run_command('close')
        window.run_command('hide_panel', {"panel": 'output.xdebug'})

    # Restore focus to previous active view
    if not previous_active is None:
        window.focus_view(previous_active)
开发者ID:pirog,项目名称:SublimeTextXdebug,代码行数:49,代码来源:view.py

示例9: get_context_values

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)
开发者ID:pirog,项目名称:SublimeTextXdebug,代码行数:25,代码来源:session.py

示例10: get_context_values

    def get_context_values(self):
        """
        Get variables in current context.
        """
        if not is_connected():
            return

        context = H.new_dictionary()
        try:
            # Super global variables
            if get_value(S.KEY_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 ProtocolConnectionException:
            e = sys.exc_info()[1]
            self.timeout(lambda: connection_error("%s" % e))

        # Store context variables in session
        S.CONTEXT_DATA = context

        return generate_context_output(context)
开发者ID:brownoxford,项目名称:SublimeTextXdebug,代码行数:27,代码来源:session.py

示例11: rows_to_region

def rows_to_region(rows):
    """
    Convert rows (line numbers) to a region (selection/cursor position).

    Keyword arguments:
    - rows -- Row number(s) to convert to region(s).
    """

    # Get current active view
    view = sublime.active_window().active_view()
    # Unable to convert rows to regions when no view available
    if view is None:
        return

    # List for containing regions to return
    region = []

    # Create list if it is a singleton
    if not isinstance(rows, list):
        rows = [rows]

    for row in rows:
        # Check if row is a digit
        if isinstance(row, int) or H.is_digit(row):
            # Convert from 1 based to a 0 based row (line) number
            row_number = int(row) - 1
            # Calculate offset point for row
            offset_point = view.text_point(row_number, 0)
            # Get region for row by offset point
            region_row = view.line(offset_point)
            # Add to list for result
            region.append(region_row)

    return region
开发者ID:willbeaufoy,项目名称:SublimeTextXdebug,代码行数:34,代码来源:view.py

示例12: load_breakpoint_data

def load_breakpoint_data():
    data_path = os.path.join(sublime.packages_path(), 'User', S.FILE_BREAKPOINT_DATA)
    data = {}
    try:
        data_file = open(data_path, 'rb')
    except:
        e = sys.exc_info()[1]
        info('Failed to open %s.' % data_path)
        debug(e)

    try:
        data = json.loads(H.data_read(data_file.read()))
    except:
        e = sys.exc_info()[1]
        info('Failed to parse %s.' % data_path)
        debug(e)

    # Do not use deleted files or entries without breakpoints
    if data:
        for filename, breakpoint_data in data.copy().items():
            if not breakpoint_data or not os.path.isfile(filename):
                del data[filename]

    if not isinstance(S.BREAKPOINT, dict):
        S.BREAKPOINT = {}

    # Set breakpoint data
    S.BREAKPOINT.update(data)
开发者ID:federivo,项目名称:SublimeTextXdebug,代码行数:28,代码来源:util.py

示例13: load_watch_data

def load_watch_data():
    data_path = os.path.join(sublime.packages_path(), 'User', S.FILE_WATCH_DATA)
    data = []
    try:
        data_file = open(data_path, 'rb')
    except:
        e = sys.exc_info()[1]
        info('Failed to open %s.' % data_path)
        debug(e)

    try:
        data = json.loads(H.data_read(data_file.read()))
    except:
        e = sys.exc_info()[1]
        info('Failed to parse %s.' % data_path)
        debug(e)

    # Check if expression is not already defined
    duplicates = []
    for index, entry in enumerate(data):
        matches = [x for x in S.WATCH if x['expression'] == entry['expression']]
        if matches:
            duplicates.append(entry)
        else:
            # Unset any previous value
            data[index]['value'] = None
    for duplicate in duplicates:
        data.remove(duplicate)

    if not isinstance(S.WATCH, list):
        S.WATCH = []

    # Set watch data
    S.WATCH.extend(data)
开发者ID:federivo,项目名称:SublimeTextXdebug,代码行数:34,代码来源:util.py

示例14: show_context_output

def show_context_output(view):
    """
    Show selected variable in an output panel when clicked in context window.

    Keyword arguments:
    view -- View reference which holds the context window.
    """
    # Check if there is a debug session and context data
    if S.SESSION and S.SESSION.connected and S.CONTEXT_DATA:
        try:
            # Get selected point in view
            point = view.sel()[0]
            # Check if selected point uses variable scope
            if point.size() == 0 and sublime.score_selector(view.scope_name(point.a), 'variable'):
                # Find variable in line which contains the point
                line = view.substr(view.line(point))
                pattern = re.compile('^\\s*(\\$.*?)\\s+\\=')
                match = pattern.match(line)
                if match:
                    # Get variable details from context data
                    variable_name = match.group(1)
                    variable = get_context_variable(S.CONTEXT_DATA, variable_name)
                    if variable:
                        # Convert details to text output
                        variables = H.new_dictionary()
                        variables[variable_name] = variable
                        data = generate_context_output(variables)
                        # Show context variables and children in output panel
                        window = sublime.active_window()
                        panel = window.get_output_panel('xdebug')
                        panel.run_command("xdebug_view_update", {'data' : data} )
                        panel.run_command('set_setting', {"setting": 'word_wrap', "value": True})
                        window.run_command('show_panel', {"panel": 'output.xdebug'})
        except:
            pass
开发者ID:willbeaufoy,项目名称:SublimeTextXdebug,代码行数:35,代码来源:view.py

示例15: load_watch_data

def load_watch_data():
    data_path = os.path.join(sublime.packages_path(), 'User', S.FILE_WATCH_DATA)
    data = []
    try:
        data_file = open(data_path, 'rb')
    except:
        e = sys.exc_info()[1]
        info('Failed to open %s.' % data_path)
        debug(e)

    try:
        data = json.loads(H.data_read(data_file.read()))
    except:
        e = sys.exc_info()[1]
        info('Failed to parse %s.' % data_path)
        debug(e)

    # Check if expression is not already defined
    for entry in data:
        matches = [x for x in S.WATCH if x['expression'] == entry['expression']]
        if matches:
            data.remove(entry)

    if not isinstance(S.WATCH, list):
        S.WATCH = []

    # Set watch data
    S.WATCH.extend(data)
开发者ID:rooseveltrp,项目名称:SublimeTextXdebug,代码行数:28,代码来源:util.py


注:本文中的helper.H类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。