Best Python code snippet using avocado_python
__init__.py
Source:__init__.py  
1# plugins/Foobar2000/__init__.py2#3# Copyright (C) 2006 MonsterMagnet4#5# This file is a plugin for EventGhost.6#7# EventGhost is free software; you can redistribute it and/or modify8# it under the terms of the GNU General Public License as published by9# the Free Software Foundation; either version 2 of the License, or10# (at your option) any later version.11#12# EventGhost is distributed in the hope that it will be useful,13# but WITHOUT ANY WARRANTY; without even the implied warranty of14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the15# GNU General Public License for more details.16#17# You should have received a copy of the GNU General Public License18# along with EventGhost; if not, write to the Free Software19# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA202122# Every EventGhost plugin should start with the import of 'eg' and the 23# definition of an eg.PluginInfo subclass.242526eg.RegisterPlugin(27    name = "Foobar2000",28    author = "MonsterMagnet",29#    version = "1.3." + "$LastChangedRevision$".split()[1],30    version = "1.3.1423",31    kind = "program",32    guid = "{50257196-DB5B-4291-BD62-FF3DE53DDCA2}",33    description = (34        'Adds actions to control the <a href="http://www.foobar2000.net/">'35        'Foobar2000</a> audio player.<br />'36	'<br />'37	'For v1.0 you need I <a href="http://foosion.foobar2000.net/components/?id=runcmd">foosion\'s Run Command (foo_runcmd) plugin</a>.'38    ),39    createMacrosOnAdd = True,40    url = "http://www.eventghost.net/forum/viewtopic.php?t=695",41    icon = (42        "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAC0UlEQVR42m1TO0hjURA9"43        "1/8nH+OPJdoYRIWgLgZhwUJsLFZUkG0iYiGCgnZpJKRQUDfEVhAsDWIRFSzURtlO0YiC"44        "pFAskxiiFnn5+Es0OzPw3GYHLu8+7sy5Z86ZqwDYaP2uq6v7YaYoKChAPp+XxXuOz89P"45        "KKVkfXx8IJlMZh8fH4N05FKUFBgZGfk1MDCA8vJySSoqKpK9pmkCRLh4f3/H29ub/L+8"46        "vODg4AC7u7v7qr6+Pup2u621tbXIZrOS2NzcjI6ODuzt7SGXy2FwcBCRSASXl5coKSlB"47        "cXExnp6e4PV6Y8pqtWrj4+OmsrIyocogTqcT7e3t2NzcRCqVwvT0NMLhMNbX14VBYWEh"48        "Xl9f+TypqqurE/39/WYG4GJihMXFRVRUVEgx91xVVSXgCwsLuLm5AecywPHxsaYqKysT"49        "nZ2dAsAFExMTcuP/Ymdnh2nDYDCIHtfX15qifhKNjY1m7qu0tBRzc3NoaGhAb2/vVyHr"50        "EAgEYLFYMD8/L/0zI9JFYxcSNTU1ZlbeZrOhp6cHPp8PJCyWlpZE1MnJSfj9fqyuruLo"51        "6AgnJyfiFgH9A2AGJpNJKE5NTSEejyMYDIp4ZDPsdju2t7cxNjaG+/t7YfAFQENkZvqZ"52        "TAazs7MYGhrC8vIyPB6PeL6xsSGM2FYWkmeEBadh0hRRT5CVZladFWfkra0tdHd3IxQK"53        "iQOkEU5PT0F2i43cLrsQi8U0RTcnWlpaeIpFMD5oa2vDysoKDg8PQS6JLjMzM4hGoyI0"54        "989s7+7uNGU0GjWHw2HiSdTfAdMeHh7G6OioJK6trYkeTF0Peg88mUlFlsW6urq+NTU1"55        "CTXdNr7J5XLh9vZWWuI50YMveXh4wMXFRVzR/35ra+vPvr4+cUF/dQxC7iCdTouVPL5c"56        "yPH8/Izz83OcnZ39YQA7LS89nu9UaGQ7GUBnwm3prXGw0BSZq6urEH09fwEfgnAhbyFf"57        "mQAAAABJRU5ErkJggg=="58    ),59)6061# changelog:62# 1.3 by CHeitkamp63#     - fixed path autodetection64#     - optional use of run_cmd plugin, because v1.0 doesn't work without it65#     - reorderd actionlist into a tree66# 1.2 by CHeitkamp67#     - changed code to get path from uninstall information68# 1.1 by bitmonster69#     - changed code to use new AddActionsFromList method70# 1.0 by MonsterMagnet71#     - initial version727374# Now import some other modules that are needed for the special purpose of75# this plugin.76import os77import _winreg78from win32api import ShellExecute798081# This plugin will create its actions dynamically from a list of data.82#83# Here we define a list of tuples, where every tuple contains the following84# information:85#   1. The name of the eg.ActionClass we want to create later.86#   2. A value for the 'name' member.87#   3. A value for the 'description' member.88#   4. A value that is needed by the action to do the actual work. This time89#      it is the parameter that will be used for a command line that calls90#      Foobar2000.919293ACTIONS = (94    (95        "Run", 96        "Run", 97        "Run foobar with its default settings.", 98        ( None, None )99    ),100    (101        "Exit", 102        "Exit", 103        "Quits foobar.", 104        ( "/exit", "/exit" )105    ), 106    ( eg.ActionGroup, "Playback_Control", "Playback Control", "Playback Control Functions\ne.g. Play/Pause",(107        (108            "Play",109            "Play", 110            "Simulate a press on the play button.", 111            ( "/play", "/play" )112        ), 113        (114            "Pause",115            "Pause", 116            "Simulate a press on the pause button.", 117            ( "/pause", "/pause" )118        ), 119        (120            "PlayPause", 121            "Toggle Play/Pause", 122            "Simulate a press on the PlayPause button.", 123            ( "/playpause", "/playpause" )124        ), 125        (126            "Stop",127            "Stop", 128            "Simulate a press on the stop button.", 129            ( "/stop", "/stop" )130        ), 131        (132            "Random", 133            "Random", 134            "Simulate a press on the random button.", 135            ( "/rand", "/rand" )136        ),137        (138            "PreviousTrack",139            "Previous Track", 140            "Simulate a press on the previous track button.", 141            ( "/prev", "/prev" )142        ), 143        (144            "NextTrack", 145            "Next Track", 146            "Simulate a press on the next track button.", 147            ( "/next", "/next" )148        ), 149        ( eg.ActionGroup, "Seek_Functions", "Seek Functions", "Seek Functions",(150            (151                "SeekAhead1s", 152                "Seek ahead by 1 seconds", 153                "Seek ahead by 1 seconds.", 154                ( '/command:"Seek ahead by 1 seconds"', '/runcmd="Seek/Ahead by 1 second"' )155            ),156            (157                "SeekAhead5s", 158                "Seek ahead by 5 seconds", 159                "Seek ahead by 5 seconds.", 160                ( '/command:"Seek ahead by 5 seconds"', '/runcmd="Seek/Ahead by 5 second"' )161            ),162            (163                "SeekAhead10s", 164                "Seek ahead by 10 seconds", 165                "Seek ahead by 10 seconds.", 166                ( '/command:"Seek ahead by 10 seconds"', '/runcmd="Seek/Ahead by 10 second"' )167            ),168            (169                "SeekAhead30s", 170                "Seek ahead by 30 seconds", 171                "Seek ahead by 30 seconds.", 172                ( '/command:"Seek ahead by 30 seconds"', '/runcmd="Seek/Ahead by 30 second"' )173            ),174            (175                "SeekAhead1m", 176                "Seek ahead by 1 minute", 177                "Seek ahead by 1 minute.", 178                ( '/command:"Seek ahead by 1 minute"', '/runcmd="Seek/Ahead by 1 minute"' )179            ),180            (181                "SeekAhead2m", 182                "Seek ahead by 2 minute", 183                "Seek ahead by 2 minute.", 184                ( '/command:"Seek ahead by 2 minute"', '/runcmd="Seek/Ahead by 2 minute"' )185            ),186            (187                "SeekAhead5m", 188                "Seek ahead by 5 minute", 189                "Seek ahead by 5 minute.", 190                ( '/command:"Seek ahead by 5 minute"', '/runcmd="Seek/Ahead by 5 minute"' )191            ),192            (193                "SeekAhead10m", 194                "Seek ahead by 10 minute", 195                "Seek ahead by 10 minute.", 196                ( '/command:"Seek ahead by 10 minute"', '/runcmd="Seek/Ahead by 10 minute"' )197            ),198            (199                "SeekBack1s", 200                "Seek back by 1 seconds", 201                "Seek back by 1 seconds.", 202                ( '/command:"Seek back by 1 seconds"', '/runcmd="Seek/Back by 1 second"' )203            ),204            (205                "SeekBack5s", 206                "Seek back by 5 seconds", 207                "Seek back by 5 seconds.", 208                ( '/command:"Seek back by 5 seconds"', '/runcmd="Seek/Back by 5 second"' )209            ),210            (211                "SeekBack10s", 212                "Seek back by 10 seconds", 213                "Seek back by 10 seconds.", 214                ( '/command:"Seek back by 10 seconds"', '/runcmd="Seek/Back by 10 second"' )215            ),216            (217                "SeekBack30s", 218                "Seek back by 30 seconds", 219                "Seek back by 30 seconds.", 220                ( '/command:"Seek back by 30 seconds"', '/runcmd="Seek/Back by 30 second"' )221            ),222            (223                "SeekBack1m", 224                "Seek back by 1 minute", 225                "Seek back by 1 minute.", 226                ( '/command:"Seek back by 1 minute"', '/runcmd="Seek/Back by 1 minute"' )227            ),228            (229                "SeekBack2m", 230                "Seek back by 2 minute", 231                "Seek back by 2 minute.", 232                ( '/command:"Seek back by 2 minute"', '/runcmd="Seek/Back by 2 minute"' )233            ),234            (235                "SeekBack5m", 236                "Seek back by 5 minute", 237                "Seek back by 5 minute.", 238                ( '/command:"Seek back by 5 minute"', '/runcmd="Seek/Back by 5 minute"' )239            ),240            (241                "SeekBack10m", 242                "Seek back by 10 minute", 243                "Seek back by 10 minute.", 244                ( '/command:"Seek back by 10 minute"', '/runcmd="Seek/Back by 10 minute"' )245            ),246        ) ),247    ) ),248    ( eg.ActionGroup, "Volume_Control", "Volume Control", "Volume Control Functions",(249        (250            "VolumeUp", 251            "Volume Up", 252            "Turn Volume Up.",253        ( '/command:"Volume up"', '/runcmd="Playback/Volume/Up"' )254        ),255        (256            "VolumeDown", 257            "Volume Down", 258            "Turn Volume Down.", 259        ( '/command:"Volume down"', '/runcmd="Playback/Volume/Down"' )260        ),261        (262            "VolumeMute", 263            "Volume Mute", 264            "Turn Volume Mute.", 265        ( '/command:"Volume mute"', '/runcmd="Playback/Volume/Mute"' )266        ),267    ) ),268    ( eg.ActionGroup, "Miscellaneous", "Miscellaneous", "Miscellaneous Functions",(269        (270            "Show", 271            "Show", 272            "Shows foobar.", 273            ( "/show", "/show" )274        ), 275        (276            "Hide", 277            "Hide", 278            "Hides foobar.", 279            ( "/hide", "/hide" )280        ), 281    ) ), 282)283284285class ActionPrototype(eg.ActionClass):286287    # Every action needs a workhorse.288    def __call__(self):289        if self.plugin.useRunCmdPlugin:290	    command = self.value[1]291        else:292            command = self.value[0]293        # This one is quite simple. It just calls ShellExecute.294        try:295            head, tail = os.path.split(self.plugin.foobar2000Path)296            return ShellExecute(0, None, tail, command, head, 1)297        except:298            # Some error-checking is always fine.299            raise self.Exceptions.ProgramNotFound300301302# Now we can start to define the plugin by sub-classing eg.PluginClass303class Foobar2000(eg.PluginClass):304    305    def __init__(self):306        self.AddActionsFromList(ACTIONS, ActionPrototype)307308309    def __start__(self, foobar2000Path=None, useRunCmdPlugin=None):310        if foobar2000Path is None:311            foobar2000Path = self.GetFoobar2000Path()312        if not os.path.exists(foobar2000Path):313            raise self.Exceptions.ProgramNotFound314        self.foobar2000Path = foobar2000Path315        if useRunCmdPlugin is None:316            useRunCmdPlugin = ( self.GetFoobar2000Version() >= '1.0' )317        self.useRunCmdPlugin = useRunCmdPlugin318        319        320    def Configure(self, foobar2000Path=None, useRunCmdPlugin=None):321        if foobar2000Path is None:322            foobar2000Path = self.GetFoobar2000Path()323            if foobar2000Path is None:324                foobar2000Path = os.path.join(325                    eg.folderPath.ProgramFiles, 326                    "foobar2000", 327                    "foobar2000.exe"328                )329        if useRunCmdPlugin is None:330            useRunCmdPlugin = ( self.GetFoobar2000Version() >= '1.0' )331        panel = eg.ConfigPanel()332        filepathCtrl = eg.FileBrowseButton(333            panel, 334            size=(320,-1),335            initialValue=foobar2000Path, 336            startDirectory=eg.folderPath.ProgramFiles,337            labelText="",338            fileMask = "Foobar2000 executable|foobar2000.exe|All-Files (*.*)|*.*",339            buttonText=eg.text.General.browse,340        )341        panel.AddLabel("Path to foobar2000 executable:")342        panel.AddCtrl(filepathCtrl)343344        useRunCmdPluginCtrl = wx.CheckBox(panel, -1, "Use foo_runcmd plugin (neccessary for foobar2000 v1.0)")345	useRunCmdPluginCtrl.SetValue(useRunCmdPlugin)346        panel.AddCtrl(useRunCmdPluginCtrl)347348        while panel.Affirmed():349            panel.SetResult(filepathCtrl.GetValue(), useRunCmdPluginCtrl.GetValue())350        351352    def GetFoobar2000Path(self):353        """354        Get the path of Foobar2000's installation directory through querying 355        the Windows registry.356        """357        try:358            fb = _winreg.OpenKey(359                _winreg.HKEY_LOCAL_MACHINE,360                "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\foobar2000"361            )362            try:363                foobar2000Path, dummy =_winreg.QueryValueEx(fb, "InstallLocation")364            except WindowsError:365                foobar2000Path, dummy =_winreg.QueryValueEx(fb, "UninstallString")366                foobar2000Path = os.path.dirname(foobar2000Path)367            _winreg.CloseKey(fb)368            foobar2000Path = os.path.join(foobar2000Path, "foobar2000.exe")369        except WindowsError:370            foobar2000Path = None371        return foobar2000Path372373374    def GetFoobar2000Version(self):375        """376        Get the version of Foobar2000 through querying the Windows registry.377        """378        try:379            fb = _winreg.OpenKey(380                _winreg.HKEY_LOCAL_MACHINE,381                "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\foobar2000"382            )383            foobar2000Version, dummy =_winreg.QueryValueEx(fb, "DisplayVersion")384            _winreg.CloseKey(fb)385        except WindowsError:386            foobar2000Version= None387        return foobar2000Version
...utils.py
Source:utils.py  
1#2# SPDX-License-Identifier: Apache-2.03from hfc.protos.orderer import ab_pb24from hfc.protos.common import common_pb25from hfc.protos.peer import chaincode_pb2, transaction_pb26def create_seek_info(start=None, stop=None, behavior="BLOCK_UNTIL_READY"):7    # build start8    if start is not None:9        seek_specified_start = ab_pb2.SeekSpecified()10        seek_specified_start.number = start11        seek_start = ab_pb2.SeekPosition()12        seek_start.specified.CopyFrom(seek_specified_start)13    else:14        seek_start = ab_pb2.SeekPosition()15        seek_start.newest.CopyFrom(ab_pb2.SeekNewest())16    # build stop17    if stop is not None:18        seek_specified_stop = ab_pb2.SeekSpecified()19        seek_specified_stop.number = stop20        seek_stop = ab_pb2.SeekPosition()21        seek_stop.specified.CopyFrom(seek_specified_stop)22    else:23        seek_stop = ab_pb2.SeekPosition()24        seek_stop.newest.CopyFrom(ab_pb2.SeekNewest())25    # seek info with all parts26    seek_info = ab_pb2.SeekInfo()27    seek_info.start.CopyFrom(seek_start)28    seek_info.stop.CopyFrom(seek_stop)29    seek_info.behavior = ab_pb2.SeekInfo.SeekBehavior.Value(behavior)30    return seek_info31def create_seek_payload(seek_header, seek_info):32    seek_payload = common_pb2.Payload()33    seek_payload.header.CopyFrom(seek_header)34    seek_payload.data = seek_info.SerializeToString()35    seek_payload_bytes = seek_payload.SerializeToString()36    return seek_payload_bytes37def create_cc_spec(chaincode_input, chaincode_id, type):38    chaincode_spec = chaincode_pb2.ChaincodeSpec()39    chaincode_spec.type = chaincode_pb2.ChaincodeSpec.Type.Value(type)40    chaincode_spec.chaincode_id.CopyFrom(chaincode_id)41    chaincode_spec.input.CopyFrom(chaincode_input)42    return chaincode_spec43def create_tx_payload(endorsements, tran_req):44    cc_action_payload = transaction_pb2.ChaincodeActionPayload()45    response = tran_req.responses[0]46    cc_action_payload.action.proposal_response_payload = \47        response.payload48    cc_action_payload.action.endorsements.extend(endorsements)49    cc_action_payload.chaincode_proposal_payload = tran_req.proposal.payload50    tran = transaction_pb2.Transaction()51    cc_tran_action = tran.actions.add()52    cc_tran_action.header = tran_req.header.signature_header53    cc_tran_action.payload = cc_action_payload.SerializeToString()54    tran_payload = common_pb2.Payload()55    tran_payload.header.channel_header = tran_req.header.channel_header56    tran_payload.header.signature_header = tran_req.header.signature_header57    tran_payload.data = tran.SerializeToString()58    tran_payload_bytes = tran_payload.SerializeToString()59    return tran_payload_bytes60def create_envelope(seek_payload_sig, seek_payload_bytes):61    envelope = common_pb2.Envelope()62    envelope.signature = seek_payload_sig63    envelope.payload = seek_payload_bytes...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!!
