Best Python code snippet using slash
input.py
Source:input.py
1#!/usr/bin/env python2# -*- coding: utf-8 -*-3"""4From LeaderF-filer5"""6from bookmark.utils import lfCmd7_switch_normal_mode_key = ""8_context = {}9# search_func10# additional_prompt_string11# cli_key_dict12# cli_cmdline13# cli_cursor_pos14# cli_pattern15# cursor_pos16# results17# input_prompt_prompts18# input_prompt_command19def command___input_cancel(manager):20 _restore_context(manager)21 _switch_normal_mode(manager)22def command___input_prompt(manager):23 global _context24 prompts = _context["input_prompt_prompts"]25 command = _context["input_prompt_command"]26 # Chains the input prompt27 # Save the previous input value.28 if "results" not in _context:29 _context["results"] = []30 _context["results"].append(manager._instance._cli.pattern)31 _context["input_prompt_prompts"] = prompts[1:]32 # reset prompt text33 prompt = prompts[0].get("prompt")34 text = prompts[0].get("text", "")35 manager._instance._cli._additional_prompt_string = prompt36 manager._instance._cli.setPattern(text)37 key_dict = manager._instance._cli._key_dict38 if len(prompts) == 1:39 # done40 key_dict["<CR>"] = "_do_" + command41 else:42 key_dict["<CR>"] = "_input_prompt"43 manager._instance._cli._key_dict = key_dict44def input_prompt(manager, command, prompts=[]):45 """46 params:47 command:48 "delete" or "edit" or ("add")49 When <CR> is pressed, manager.command___co_{command}() is executed.50 prompts:51 input prompts52 [53 {"prompt": prompt1, "text": text1},54 ...55 ]56 """57 global _context58 _context["input_prompt_prompts"] = prompts[1:]59 _context["input_prompt_command"] = command60 # set pattern61 prompt = prompts[0].get("prompt", "")62 text = prompts[0].get("text", "")63 manager._instance._cli._additional_prompt_string = prompt64 manager._instance._cli.setPattern(text)65 # update key_dict66 key_dict = {67 lhs: rhs68 for [lhs, rhs] in manager._instance._cli._key_dict.items()69 if rhs.lower()70 in {71 "<esc>",72 "<c-c>",73 "<bs>",74 "<c-h>",75 "<c-u>",76 "<c-w>",77 "<del>",78 "<c-v>",79 "<s-insert>",80 "<home>",81 "<c-b>",82 "<end>",83 "<c-e>",84 "<left>",85 "<right>",86 "<up>",87 "<down>",88 }89 }90 # To be able to do general input91 for [lrs, rhs] in key_dict.items():92 rhs_low = rhs.lower()93 if rhs_low in {"<esc>", "<c-c>"}:94 key_dict[lrs] = "_input_cancel"95 # add command96 if len(prompts) == 1:97 key_dict["<CR>"] = "_do_" + command98 else:99 # chain100 key_dict["<CR>"] = "_input_prompt"101 manager._instance._cli._key_dict = key_dict102 manager.input()103def do_command(need_refresh=True):104 """105 params:106 need_refresh107 example)108 @do_command()109 def command___do_xxx(manager, context, results):110 ...111 """112 def decorator(func):113 # Give a list of input results to a function114 def inner_func(manager):115 # The first argument must be manager116 global _context117 results = _context.get("results", [])118 results.append(manager._instance._cli.pattern)119 try:120 func(manager, _context, results)121 finally:122 _restore_context(123 manager, restore_input_pattern=False, restore_cursor_pos=False124 )125 _switch_normal_mode(manager)126 manager._instance._cli.setPattern("")127 if need_refresh:128 manager.refresh()129 return inner_func130 return decorator131def save_context(manager, **kwargs):132 """ For input_prompt133 """134 global _context135 _context = {}136 _context["search_func"] = manager._search137 _context[138 "additional_prompt_string"139 ] = manager._instance._cli._additional_prompt_string140 _context["cli_key_dict"] = dict(manager._instance._cli._key_dict)141 _context["cli_cmdline"] = list(manager._instance._cli._cmdline)142 _context["cli_cursor_pos"] = manager._instance._cli._cursor_pos143 _context["cli_pattern"] = manager._instance._cli._pattern144 _context["cursor_pos"] = manager._getInstance()._window_object.cursor145 _context.update(**kwargs)146 manager._search = lambda content, is_continue=False, step=0: ""147def _restore_context(manager, restore_input_pattern=True, restore_cursor_pos=True):148 """ For input_prompt149 params:150 restore_input_pattern:151 The following attributes of the `cli` will not be restored152 * _cmdline153 * _cursor_pos154 * _pattern155 restore_cursor_pos:156 cursor position157 """158 global _context159 manager._search = _context["search_func"]160 manager._instance._cli._additional_prompt_string = _context[161 "additional_prompt_string"162 ]163 manager._instance._cli._key_dict = _context["cli_key_dict"]164 if restore_cursor_pos:165 # To restore only in case of cancel166 [row, col] = _context["cursor_pos"]167 lfCmd(168 """call win_execute({}, 'exec "norm! {}G"')""".format(169 manager._instance._popup_winid, row170 )171 )172 manager._getInstance().refreshPopupStatusline()173 if restore_input_pattern:174 # To restore only in case of cancel175 manager._instance._cli._cmdline = _context["cli_cmdline"]176 manager._instance._cli._cursor_pos = _context["cli_cursor_pos"]177 manager._instance._cli._pattern = _context["cli_pattern"]178 _context = {}179def _switch_normal_mode(manager):180 lfCmd(r'call feedkeys("{}", "n")'.format(_get_switch_normal_mode_key(manager)))181def _get_switch_normal_mode_key(manager):182 """ Returns the key to go into normal mode.183 """184 global _switch_normal_mode_key185 if _switch_normal_mode_key:186 return _switch_normal_mode_key187 keys = [188 lrs189 for [lrs, rhs] in manager._instance._cli._key_dict.items()190 if rhs.lower() == "<tab>"191 ]192 if len(keys) == 0:193 _switch_normal_mode_key = r"\<Tab>"194 else:195 # <Tab> => \<Tab>196 _switch_normal_mode_key = keys[0].replace("<", r"\<")...
sasl.py
Source:sasl.py
1#2# Licensed to the Apache Software Foundation (ASF) under one3# or more contributor license agreements. See the NOTICE file4# distributed with this work for additional information5# regarding copyright ownership. The ASF licenses this file6# to you under the Apache License, Version 2.0 (the7# "License"); you may not use this file except in compliance8# with the License. You may obtain a copy of the License at9#10# http://www.apache.org/licenses/LICENSE-2.011#12# Unless required by applicable law or agreed to in writing,13# software distributed under the License is distributed on an14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15# KIND, either express or implied. See the License for the16# specific language governing permissions and limitations17# under the License.18#19import socket20class SASLError(Exception):21 pass22class WrapperClient:23 def __init__(self):24 self._cli = _Client()25 def setAttr(self, name, value):26 status = self._cli.setAttr(str(name), str(value))27 if status and name == 'username':28 status = self._cli.setAttr('externaluser', str(value))29 30 if not status:31 raise SASLError(self._cli.getError())32 def init(self):33 status = self._cli.init()34 if not status:35 raise SASLError(self._cli.getError())36 def start(self, mechanisms):37 status, mech, initial = self._cli.start(str(mechanisms))38 if status:39 return mech, initial40 else:41 raise SASLError(self._cli.getError())42 def step(self, challenge):43 status, response = self._cli.step(challenge)44 if status:45 return response46 else:47 raise SASLError(self._cli.getError())48 def encode(self, bytes):49 status, result = self._cli.encode(bytes)50 if status:51 return result52 else:53 raise SASLError(self._cli.getError())54 def decode(self, bytes):55 status, result = self._cli.decode(bytes)56 if status:57 return result58 else:59 raise SASLError(self._cli.getError())60 def auth_username(self):61 status, result = self._cli.getUserId()62 if status:63 return result64 else:65 raise SASLError(self._cli.getError())66class PlainClient:67 def __init__(self):68 self.attrs = {}69 def setAttr(self, name, value):70 self.attrs[name] = value71 def init(self):72 pass73 def start(self, mechanisms):74 mechs = mechanisms.split()75 if self.attrs.get("username") and self.attrs.get("password") and "PLAIN" in mechs:76 return "PLAIN", "\0%s\0%s" % (self.attrs.get("username"), self.attrs.get("password"))77 elif "ANONYMOUS" in mechs:78 return "ANONYMOUS", "%s@%s" % (self.attrs.get("username"), socket.gethostname())79 elif "EXTERNAL" in mechs:80 return "EXTERNAL", "%s" % (self.attrs.get("username"))81 else:82 raise SASLError("sasl negotiation failed: no mechanism agreed")83 def step(self, challenge):84 pass85 def encode(self, bytes):86 return bytes87 def decode(self, bytes):88 return bytes89 def auth_username(self):90 return self.attrs.get("username")91try:92 from saslwrapper import Client as _Client93 Client = WrapperClient94except ImportError:...
vulture-whitelist.py
Source:vulture-whitelist.py
1_.error_on_external_run # unused attribute (noxfile.py:20)2_.reuse_existing_virtualenvs # unused attribute (noxfile.py:21)3_.stop_on_first_error # unused attribute (noxfile.py:22)4test # unused function (noxfile.py:25)5_max_tweets_validator # unused function (src/nasty/_cli.py:74)6_batch_size_validator # unused function (src/nasty/_cli.py:90)7title # unused variable (src/nasty/_cli.py:129)8aliases # unused variable (src/nasty/_cli.py:130)9description # unused variable (src/nasty/_cli.py:131)10_since_validator # unused function (src/nasty/_cli.py:150)11_until_validator # unused function (src/nasty/_cli.py:161)12_daily_validator # unused function (src/nasty/_cli.py:196)13title # unused variable (src/nasty/_cli.py:236)14aliases # unused variable (src/nasty/_cli.py:237)15description # unused variable (src/nasty/_cli.py:238)16title # unused variable (src/nasty/_cli.py:267)17aliases # unused variable (src/nasty/_cli.py:268)18description # unused variable (src/nasty/_cli.py:269)19title # unused variable (src/nasty/_cli.py:297)20aliases # unused variable (src/nasty/_cli.py:298)21description # unused variable (src/nasty/_cli.py:299)22title # unused variable (src/nasty/_cli.py:340)23aliases # unused variable (src/nasty/_cli.py:341)24description # unused variable (src/nasty/_cli.py:342)25_out_dir_validator # unused function (src/nasty/_cli.py:367)26title # unused variable (src/nasty/_cli.py:397)27aliases # unused variable (src/nasty/_cli.py:398)28description # unused variable (src/nasty/_cli.py:399)29_out_dir_validator # unused function (src/nasty/_cli.py:426)30title # unused variable (src/nasty/_cli.py:452)31version # unused variable (src/nasty/_cli.py:453)32description # unused variable (src/nasty/_cli.py:454)33subprograms # unused variable (src/nasty/_cli.py:455)34_.num_tombstones # unused attribute (src/nasty/_retriever/conversation_retriever.py:36)35_.num_tombstones # unused attribute (src/nasty/_retriever/replies_retriever.py:139)36_.num_tombstones # unused attribute (src/nasty/_retriever/thread_retriever.py:132)37SingleMetavarHelpFormatter # unused class (src/nasty/_util/argparse_.py:23)38_._format_action_invocation # unused method (src/nasty/_util/argparse_.py:24)39pytest_configure # unused function (tests/conftest.py:30)40activate_requests_cache # unused function (tests/conftest.py:56)41disrespect_robotstxt # unused function (tests/conftest.py:67)42min_tombstones # unused variable (tests/retriever/test_replies.py:70)43min_tombstones # unused variable (tests/retriever/test_thread.py:67)44exc_type # unused variable (tests/util/requests_cache.py:174)45exc_val # unused variable (tests/util/requests_cache.py:175)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!