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


Python tools.check_for_partial_string函数代码示例

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


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

示例1: test_partial_string

def test_partial_string(leaders, prefix, quote):
    (l, l_len), (f, f_len) = leaders
    s = prefix + quote
    t = s + "test string" + quote
    t_len = len(t)
    # single string
    test_string = l + t + f
    obs = check_for_partial_string(test_string)
    exp = l_len, l_len + t_len, s
    assert obs == exp
    # single partial
    test_string = l + f + s + "test string"
    obs = check_for_partial_string(test_string)
    exp = l_len + f_len, None, s
    assert obs == exp
    # two strings
    test_string = l + t + f + l + t + f
    obs = check_for_partial_string(test_string)
    exp = (l_len + t_len + f_len + l_len), (l_len + t_len + f_len + l_len + t_len), s
    assert obs == exp
    # one string, one partial
    test_string = l + t + f + l + s + "test string"
    obs = check_for_partial_string(test_string)
    exp = l_len + t_len + f_len + l_len, None, s
    assert obs == exp
开发者ID:mitnk,项目名称:xonsh,代码行数:25,代码来源:test_tools.py

示例2: _path_from_partial_string

def _path_from_partial_string(inp, pos=None):
    if pos is None:
        pos = len(inp)
    partial = inp[:pos]
    startix, endix, quote = check_for_partial_string(partial)
    _post = ""
    if startix is None:
        return None
    elif endix is None:
        string = partial[startix:]
    else:
        if endix != pos:
            _test = partial[endix:pos]
            if not any(i == ' ' for i in _test):
                _post = _test
            else:
                return None
        string = partial[startix:endix]
    end = re.sub(RE_STRING_START, '', quote)
    _string = string
    if not _string.endswith(end):
        _string = _string + end
    try:
        val = ast.literal_eval(_string)
    except SyntaxError:
        return None
    if isinstance(val, bytes):
        env = builtins.__xonsh_env__
        val = val.decode(encoding=env.get('XONSH_ENCODING'),
                         errors=env.get('XONSH_ENCODING_ERRORS'))
    return string + _post, val + _post, quote, end
开发者ID:mwiebe,项目名称:xonsh,代码行数:31,代码来源:completer.py

示例3: compile

 def compile(self, src):
     """Compiles source code and returns the (possibly modified) source and
     a valid code object.
     """
     _cache = should_use_cache(self.execer, 'single')
     if _cache:
         codefname = code_cache_name(src)
         cachefname = get_cache_filename(codefname, code=True)
         usecache, code = code_cache_check(cachefname)
         if usecache:
             self.reset_buffer()
             return src, code
     try:
         code = self.execer.compile(src,
                                    mode='single',
                                    glbs=self.ctx,
                                    locs=None)
         if _cache:
             update_cache(code, cachefname)
         self.reset_buffer()
     except SyntaxError:
         partial_string_info = check_for_partial_string(src)
         in_partial_string = (partial_string_info[0] is not None and
                              partial_string_info[1] is None)
         if (src == '\n' or src.endswith('\n\n')) and not in_partial_string:
             self.reset_buffer()
             print_exception()
             return src, None
         self.need_more_lines = True
         code = None
     except Exception:  # pylint: disable=broad-except
         self.reset_buffer()
         print_exception()
         code = None
     return src, code
开发者ID:vsajip,项目名称:xonsh,代码行数:35,代码来源:base_shell.py

示例4: carriage_return

def carriage_return(b, cli, *, autoindent=True):
    """
    Preliminary parser to determine if 'Enter' key should send command to
    the xonsh parser for execution or should insert a newline for continued
    input.

    Current 'triggers' for inserting a newline are:
    - Not on first line of buffer and line is non-empty
    - Previous character is a colon (covers if, for, etc...)
    - User is in an open paren-block
    - Line ends with backslash
    - Any text exists below cursor position (relevant when editing previous
    multiline blocks)
    """
    doc = b.document
    at_end_of_line = _is_blank(doc.current_line_after_cursor)
    current_line_blank = _is_blank(doc.current_line)

    indent = env.get('INDENT') if autoindent else ''

    partial_string_info = check_for_partial_string(doc.text)
    in_partial_string = (partial_string_info[0] is not None and
                         partial_string_info[1] is None)

    # indent after a colon
    if (doc.current_line_before_cursor.strip().endswith(':') and
            at_end_of_line):
        b.newline(copy_margin=autoindent)
        b.insert_text(indent, fire_event=False)
    # if current line isn't blank, check dedent tokens
    elif (not current_line_blank and
            doc.current_line.split(maxsplit=1)[0] in DEDENT_TOKENS and
            doc.line_count > 1):
        b.newline(copy_margin=autoindent)
        b.delete_before_cursor(count=len(indent))
    elif (not doc.on_first_line and
            not current_line_blank):
        b.newline(copy_margin=autoindent)
    elif (doc.char_before_cursor == '\\' and
            not (not builtins.__xonsh_env__.get('FORCE_POSIX_PATHS')
                 and ON_WINDOWS)):
        b.newline(copy_margin=autoindent)
    elif (doc.find_next_word_beginning() is not None and
            (any(not _is_blank(i)
                 for i
                 in doc.lines_from_current[1:]))):
        b.newline(copy_margin=autoindent)
    elif not current_line_blank and not can_compile(doc.text):
        b.newline(copy_margin=autoindent)
    elif current_line_blank and in_partial_string:
        b.newline(copy_margin=autoindent)
    else:
        b.accept_action.validate_and_handle(cli, b)
开发者ID:astronouth7303,项目名称:xonsh,代码行数:53,代码来源:key_bindings.py

示例5: completedefault

 def completedefault(self, prefix, line, begidx, endidx):
     """Implements tab-completion for text."""
     if self.completer is None:
         return []
     rl_completion_suppress_append()  # this needs to be called each time
     _rebind_case_sensitive_completions()
     _s, _e, _q = check_for_partial_string(line)
     if _s is not None:
         if _e is not None and ' ' in line[_e:]:
             mline = line.rpartition(' ')[2]
         else:
             mline = line[_s:]
     else:
         mline = line.rpartition(' ')[2]
     offs = len(mline) - len(prefix)
     return [i[offs:] for i in self.completer.complete(prefix, line,
                                                       begidx, endidx,
                                                       ctx=self.ctx)[0]]
开发者ID:nicfit,项目名称:xonsh,代码行数:18,代码来源:readline_shell.py

示例6: push

 def push(self, line):
     """Pushes a line onto the buffer and compiles the code in a way that
     enables multiline input.
     """
     code = None
     self.buffer.append(line)
     if self.need_more_lines:
         return None, code
     src = ''.join(self.buffer)
     _cache = should_use_cache(self.execer, 'single')
     if _cache:
         codefname = code_cache_name(src)
         cachefname = get_cache_filename(codefname, code=True)
         usecache, code = code_cache_check(cachefname)
         if usecache:
             self.reset_buffer()
             return src, code
     try:
         code = self.execer.compile(src,
                                    mode='single',
                                    glbs=self.ctx,
                                    locs=None)
         if _cache:
             update_cache(code, cachefname)
         self.reset_buffer()
     except SyntaxError:
         partial_string_info = check_for_partial_string(src)
         in_partial_string = (partial_string_info[0] is not None and
                              partial_string_info[1] is None)
         if ((line == '\n' and not in_partial_string)):
             self.reset_buffer()
             print_exception()
             return src, None
         self.need_more_lines = True
     except Exception:  # pylint: disable=broad-except
         self.reset_buffer()
         print_exception()
         return src, None
     return src, code
开发者ID:Carreau,项目名称:xonsh,代码行数:39,代码来源:base_shell.py

示例7: test_partial_string

def test_partial_string():
    # single string at start
    yield assert_equal, check_for_partial_string('no strings here'), (None, None, None)
    yield assert_equal, check_for_partial_string(''), (None, None, None)
    for s,e in _startend.items():
        _test = s + inners + e
        for l in _leaders:
            for f in _leaders:
                # single string
                _res = check_for_partial_string(l + _test + f)
                yield assert_equal, _res, (len(l), len(l) + len(_test), s)
                # single partial
                _res = check_for_partial_string(l + f + s + inners)
                yield assert_equal, _res, (len(l+f), None, s)
                for s2, e2 in _startend.items():
                    _test2 = s2 + inners + e2
                    for l2 in _leaders:
                        for f2 in _leaders:
                            # two strings
                            _res = check_for_partial_string(l + _test + f + l2 + _test2 + f2)
                            yield assert_equal, _res, (len(l+_test+f+l2), len(l+_test+f+l2+_test2), s2)
                            # one string, one partial
                            _res = check_for_partial_string(l + _test + f + l2 + s2 + inners)
                            yield assert_equal, _res, (len(l+_test+f+l2), None, s2)
开发者ID:gforsyth,项目名称:xonsh,代码行数:24,代码来源:test_tools.py

示例8: test_partial_string_none

def test_partial_string_none(inp):
    assert check_for_partial_string(inp) == (None, None, None)
开发者ID:mitnk,项目名称:xonsh,代码行数:2,代码来源:test_tools.py


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