Pack a command to send to an IRC server
766516
def pack_command(command: str, **kwargs: Any) -> str:
    
    if not command:
        raise ValueError("Must provide a command")
    if not isinstance(command, str):
        raise ValueError("Command must be a string")
    command = command.upper()

    # ========================================================================
    # For each command, provide:
    #  1. a link to the definition in rfc2812
    #  2. the normalized grammar, which may not equate to the rfc grammar
    #     the normalized grammar will use the keys expected in kwargs,
    #     which usually do NOT line up with rfc2812.  They may also make
    #     optional fields which are required in rfc2812, by providing
    #     the most common or reasonable defaults.
    #  3. exhaustive examples, preferring normalized form of
    #     the rfc2812 examples
    # ========================================================================

    # ========================================================================
    # Normalized grammar:
    # : should not be provided; it denotes the beginning of the last
    #   field, which may contain spaces
    # [] indicates an optional field
    # <> denote the key that the field will be filled with
    # because fields are filled from a dict, required fields may follow
    #   optional fields - see USER command, where mode is optional
    #   (and defaults to 0)
    # "" indicates a literal value that is inserted if present
    # ========================================================================

    # PASS
    # https://tools.ietf.org/html/rfc2812#section-3.1.1
    # PASS <password>
    # ----------
    # PASS secretpasswordhere
    if command == "PASS":
        return "PASS " + f("password", kwargs)

    # NICK
    # https://tools.ietf.org/html/rfc2812#section-3.1.2
    # NICK <nick>
    # ----------
    # NICK Wiz
    elif command == "NICK":
        return "NICK " + f("nick", kwargs)

    # USER
    # https://tools.ietf.org/html/rfc2812#section-3.1.3
    # USER <user> [<mode>] :<realname>
    # ----------
    # USER guest 8 :Ronnie Reagan
    # USER guest :Ronnie Reagan
    elif command == "USER":
        return "USER {} {} * :{}".format(
            f("user", kwargs),
            f("mode", kwargs, 0),
            f("realname", kwargs))

    # OPER
    # https://tools.ietf.org/html/rfc2812#section-3.1.4
    # OPER <user> <password>
    # ----------
    # OPER AzureDiamond hunter2
    elif command == "OPER":
        return "OPER {} {}".format(f("user", kwargs), f("password", kwargs))

    # USERMODE (renamed from MODE)
    # https://tools.ietf.org/html/rfc2812#section-3.1.5
    # MODE <nick> [<modes>]
    # ----------
    # MODE WiZ -w
    # MODE Angel +i
    # MODE
    elif command == "USERMODE":
        return "MODE {} {}".format(f("nick", kwargs), f("modes", kwargs, ''))

    # SERVICE
    # https://tools.ietf.org/html/rfc2812#section-3.1.6
    # SERVICE <nick> <distribution> <type> :<info>
    # ----------
    # SERVICE dict *.fr 0 :French
    elif command == "SERVICE":
        return "SERVICE {} * {} {} 0 :{}".format(
            f("nick", kwargs),
            f("distribution", kwargs),
            f("type", kwargs),
            f("info", kwargs))

    # QUIT
    # https://tools.ietf.org/html/rfc2812#section-3.1.7
    # QUIT :[<message>]
    # ----------
    # QUIT :Gone to lunch
    # QUIT
    elif command == "QUIT":
        if "message" in kwargs:
            return "QUIT :" + f("message", kwargs)
        return "QUIT"

    # SQUIT
    # https://tools.ietf.org/html/rfc2812#section-3.1.8
    # SQUIT <server> [<message>]
    # ----------
    # SQUIT tolsun.oulu.fi :Bad Link
    # SQUIT tolsun.oulu.fi
    elif command == "SQUIT":
        base = "SQUIT " + f("server", kwargs)
        if "message" in kwargs:
            return base + " :" + f("message", kwargs)
        return base

    # JOIN
    # https://tools.ietf.org/html/rfc2812#section-3.2.1
    # JOIN <channel> [<key>]
    # ----------
    # JOIN #foo fookey
    # JOIN #foo
    # JOIN 0
    elif command == "JOIN":
        return "JOIN {} {}".format(pack("channel", kwargs),
                                   pack("key", kwargs, ''))

    # PART
    # https://tools.ietf.org/html/rfc2812#section-3.2.2
    # PART <channel> :[<message>]
    # ----------
    # PART #foo :I lost
    # PART #foo
    elif command == "PART":
        base = "PART " + pack("channel", kwargs)
        if "message" in kwargs:
            return base + " :" + f("message", kwargs)
        return base

    # CHANNELMODE (renamed from MODE)
    # https://tools.ietf.org/html/rfc2812#section-3.2.3
    # MODE <channel> <modes> [<params>]
    # ----------
    # MODE #Finnish +imI *!*@*.fi
    # MODE #en-ops +v WiZ
    # MODE #Fins -s
    elif command == "CHANNELMODE":
        return "MODE {} {} {}".format(f("channel", kwargs),
                                      f("modes", kwargs),
                                      f("params", kwargs, ''))

    # TOPIC
    # https://tools.ietf.org/html/rfc2812#section-3.2.4
    # TOPIC <channel> :[<message>]
    # ----------
    # TOPIC #test :New topic
    # TOPIC #test :
    # TOPIC #test
    elif command == "TOPIC":
        base = "TOPIC " + f("channel", kwargs)
        if "message" in kwargs:
            return base + " :" + f("message", kwargs)
        return base

    # NAMES
    # https://tools.ietf.org/html/rfc2812#section-3.2.5
    # NAMES [<channel>] [<target>]
    # ----------
    # NAMES #twilight_zone remote.*.edu
    # NAMES #twilight_zone
    # NAMES
    elif command == "NAMES":
        if "channel" in kwargs:
            return "NAMES {} {}".format(pack("channel", kwargs),
                                        f("target", kwargs, ''))
        return "NAMES"

    # LIST
    # https://tools.ietf.org/html/rfc2812#section-3.2.6
    # LIST [<channel>] [<target>]
    # ----------
    # LIST #twilight_zone remote.*.edu
    # LIST #twilight_zone
    # LIST
    elif command == "LIST":
        if "channel" in kwargs:
            return "LIST {} {}".format(pack("channel", kwargs),
                                       f("target", kwargs, ''))
        return "LIST"

    # INVITE
    # https://tools.ietf.org/html/rfc2812#section-3.2.7
    # INVITE <nick> <channel>
    # ----------
    # INVITE Wiz #Twilight_Zone
    elif command == "INVITE":
        return "INVITE {} {}".format(f("nick", kwargs),
                                     f("channel", kwargs))

    # KICK
    # https://tools.ietf.org/html/rfc2812#section-3.2.8
    # KICK <channel> <nick> :[<message>]
    # ----------
    # KICK #Finnish WiZ :Speaking English
    # KICK #Finnish WiZ,Wiz-Bot :Both speaking English
    # KICK #Finnish,#English WiZ,ZiW :Speaking wrong language
    elif command == "KICK":
        base = "KICK {} {}".format(pack("channel", kwargs),
                                   pack("nick", kwargs))
        if "message" in kwargs:
            return base + " :" + pack("message", kwargs)
        return base

    # PRIVMSG
    # https://tools.ietf.org/html/rfc2812#section-3.3.1
    # PRIVMSG <target> :<message>
    # ----------
    # PRIVMSG Angel :yes I'm receiving it !
    # PRIVMSG $*.fi :Server tolsun.oulu.fi rebooting.
    # PRIVMSG #Finnish :This message is in english
    elif command == "PRIVMSG":
        return "PRIVMSG {} :{}".format(f("target", kwargs),
                                       f("message", kwargs))

    # NOTICE
    # https://tools.ietf.org/html/rfc2812#section-3.3.2
    # NOTICE <target> :<message>
    # ----------
    # NOTICE Angel :yes I'm receiving it !
    # NOTICE $*.fi :Server tolsun.oulu.fi rebooting.
    # NOTICE #Finnish :This message is in english
    elif command == "NOTICE":
        return "NOTICE {} :{}".format(f("target", kwargs),
                                      f("message", kwargs))

    # MOTD
    # https://tools.ietf.org/html/rfc2812#section-3.4.1
    # MOTD [<target>]
    # ----------
    # MOTD remote.*.edu
    # MOTD
    elif command == "MOTD":
        return "MOTD " + f("target", kwargs, '')

    # LUSERS
    # https://tools.ietf.org/html/rfc2812#section-3.4.2
    # LUSERS [<mask>] [<target>]
    # ----------
    # LUSERS *.edu remote.*.edu
    # LUSERS *.edu
    # LUSERS
    elif command == "LUSERS":
        if "mask" in kwargs:
            return "LUSERS {} {}".format(f("mask", kwargs),
                                         f("target", kwargs, ''))
        return "LUSERS"

    # VERSION
    # https://tools.ietf.org/html/rfc2812#section-3.4.3
    # VERSION [<target>]
    # ----------
    # VERSION remote.*.edu
    # VERSION
    elif command == "VERSION":
        return "VERSION " + f("target", kwargs, '')

    # STATS
    # https://tools.ietf.org/html/rfc2812#section-3.4.4
    # STATS [<query>] [<target>]
    # ----------
    # STATS m remote.*.edu
    # STATS m
    # STATS
    elif command == "STATS":
        if "query" in kwargs:
            return "STATS {} {}".format(f("query", kwargs),
                                        f("target", kwargs, ''))
        return "STATS"

    # LINKS
    # https://tools.ietf.org/html/rfc2812#section-3.4.5
    # LINKS [<remote>] [<mask>]
    # ----------
    # LINKS *.edu *.bu.edu
    # LINKS *.au
    # LINKS
    elif command == "LINKS":
        if "remote" in kwargs:
            return "LINKS {} {}".format(f("remote", kwargs), f("mask", kwargs))
        elif "mask" in kwargs:
            return "LINKS " + f("mask", kwargs)
        return "LINKS"

    # TIME
    # https://tools.ietf.org/html/rfc2812#section-3.4.6
    # TIME [<target>]
    # ----------
    # TIME remote.*.edu
    # TIME
    elif command == "TIME":
        return "TIME " + f("target", kwargs, '')

    # CONNECT
    # https://tools.ietf.org/html/rfc2812#section-3.4.7
    # CONNECT <target> <port> [<remote>]
    # ----------
    # CONNECT tolsun.oulu.fi 6667 *.edu
    # CONNECT tolsun.oulu.fi 6667
    elif command == "CONNECT":
        return "CONNECT {} {} {}".format(f("target", kwargs),
                                         f("port", kwargs),
                                         f("remote", kwargs, ''))

    # TRACE
    # https://tools.ietf.org/html/rfc2812#section-3.4.8
    # TRACE [<target>]
    # ----------
    # TRACE
    elif command == "TRACE":
        return "TRACE " + f("target", kwargs, '')

    # ADMIN
    # https://tools.ietf.org/html/rfc2812#section-3.4.9
    # ADMIN [<target>]
    # ----------
    # ADMIN
    elif command == "ADMIN":
        return "ADMIN " + f("target", kwargs, '')

    # INFO
    # https://tools.ietf.org/html/rfc2812#section-3.4.10
    # INFO [<target>]
    # ----------
    # INFO
    elif command == "INFO":
        return "INFO " + f("target", kwargs, '')

    # SERVLIST
    # https://tools.ietf.org/html/rfc2812#section-3.5.1
    # SERVLIST [<mask>] [<type>]
    # ----------
    # SERVLIST *SERV 3
    # SERVLIST *SERV
    # SERVLIST
    elif command == "SERVLIST":
        return "SERVLIST {} {}".format(f("mask", kwargs, ''),
                                       f("type", kwargs, ''))

    # SQUERY
    # https://tools.ietf.org/html/rfc2812#section-3.5.2
    # SQUERY <target> :<message>
    # ----------
    # SQUERY irchelp :HELP privmsg
    elif command == "SQUERY":
        return "SQUERY {} :{}".format(f("target", kwargs),
                                      f("message", kwargs))

    # WHO
    # https://tools.ietf.org/html/rfc2812#section-3.6.1
    # WHO [<mask>] ["o"]
    # ----------
    # WHO jto* o
    # WHO *.fi
    # WHO
    elif command == "WHO":
        return "WHO {} {}".format(f("mask", kwargs, ''), b("o", kwargs))

    # WHOIS
    # https://tools.ietf.org/html/rfc2812#section-3.6.2
    # WHOIS <mask> [<target>]
    # ----------
    # WHOIS jto* o remote.*.edu
    # WHOIS jto* o
    # WHOIS *.fi
    elif command == "WHOIS":
        return "WHOIS {} {}".format(pack("mask", kwargs),
                                    f("target", kwargs, ''))

    # WHOWAS
    # https://tools.ietf.org/html/rfc2812#section-3.6.3
    # WHOWAS <nick> [<count>] [<target>]
    # ----------
    # WHOWAS Wiz 9 remote.*.edu
    # WHOWAS Wiz 9
    # WHOWAS Mermaid
    elif command == "WHOWAS":
        if "count" in kwargs:
            return "WHOWAS {} {} {}".format(pack("nick", kwargs),
                                            f("count", kwargs),
                                            f("target", kwargs, ''))
        return "WHOWAS " + pack("nick", kwargs)

    # KILL
    # https://tools.ietf.org/html/rfc2812#section-3.7.1
    # KILL <nick> :<message>
    # ----------
    # KILL WiZ :Spamming joins
    elif command == "KILL":
        return "KILL {} :{}".format(f("nick", kwargs), f("message", kwargs))

    # PING
    # https://tools.ietf.org/html/rfc2812#section-3.7.2
    # PING :[<message>]
    # ----------
    # PING :I'm still here
    # PING
    elif command == "PING":
        if "message" in kwargs:
            return "PING :{}".format(f("message", kwargs))
        else:
            return "PING"

    # PONG
    # https://tools.ietf.org/html/rfc2812#section-3.7.3
    # PONG :[<message>]
    # ----------
    # PONG :I'm still here
    # PONG
    elif command == "PONG":
        if "message" in kwargs:
            return "PONG :{}".format(f("message", kwargs))
        else:
            return "PONG"

    # AWAY
    # https://tools.ietf.org/html/rfc2812#section-4.1
    # AWAY :[<message>]
    # ----------
    # AWAY :Gone to lunch.
    # AWAY
    elif command == "AWAY":
        if "message" in kwargs:
            return "AWAY :" + f("message", kwargs)
        return "AWAY"

    # REHASH
    # https://tools.ietf.org/html/rfc2812#section-4.2
    # REHASH
    # ----------
    # REHASH
    elif command == "REHASH":
        return "REHASH"

    # DIE
    # https://tools.ietf.org/html/rfc2812#section-4.3
    # DIE
    # ----------
    # DIE
    elif command == "DIE":
        return "DIE"

    # RESTART
    # https://tools.ietf.org/html/rfc2812#section-4.4
    # RESTART
    # ----------
    # RESTART
    elif command == "RESTART":
        return "RESTART"

    # SUMMON
    # https://tools.ietf.org/html/rfc2812#section-4.5
    # SUMMON <nick> [<target>] [<channel>]
    # ----------
    # SUMMON Wiz remote.*.edu #Finnish
    # SUMMON Wiz remote.*.edu
    # SUMMON Wiz
    elif command == "SUMMON":
        if "target" in kwargs:
            return "SUMMON {} {} {}".format(f("nick", kwargs),
                                            f("target", kwargs),
                                            f("channel", kwargs, ''))
        return "SUMMON " + f("nick", kwargs)

    # USERS
    # https://tools.ietf.org/html/rfc2812#section-4.6
    # USERS [<target>]
    # ----------
    # USERS remote.*.edu
    # USERS
    elif command == "USERS":
        return "USERS " + f("target", kwargs, '')

    # WALLOPS
    # https://tools.ietf.org/html/rfc2812#section-4.7
    # WALLOPS :<message>
    # ----------
    # WALLOPS :Maintenance in 5 minutes
    elif command == "WALLOPS":
        return "WALLOPS :" + f("message", kwargs)

    # USERHOST
    # https://tools.ietf.org/html/rfc2812#section-4.8
    # USERHOST <nick>
    # ----------
    # USERHOST Wiz Michael syrk
    # USERHOST syrk
    elif command == "USERHOST":
        return "USERHOST " + pack("nick", kwargs, sep=" ")

    # ISON
    # https://tools.ietf.org/html/rfc2812#section-4.9
    # ISON <nick>
    # ----------
    # ISON Wiz Michael syrk
    # ISON syrk
    elif command == "ISON":
        return "ISON " + pack("nick", kwargs, sep=" ")

    else:
        raise ValueError("Unknown command '{}'".format(command))
869294
function Pack(commit, options, rollCall, command) {
	if (!commit || !options || !rollCall || !command) {
		throw new Error('Invalid arguments: ' + arguments);
	}
	this.commit = commit;
	this.options = options;
	this.rollCall = rollCall;
	this.command = command;
}
1119157
def __send_command(self, command, command_string=b'', response_size=8):
        
        if command not in [const.CMD_CONNECT, const.CMD_AUTH] and not self.is_connect:
            raise ZKErrorConnection("instance are not connected.")

        buf = self.__create_header(command, command_string, self.__session_id, self.__reply_id)
        try:
            if self.tcp:
                top = self.__create_tcp_top(buf)
                self.__sock.send(top)
                self.__tcp_data_recv = self.__sock.recv(response_size + 8)
                self.__tcp_length = self.__test_tcp_top(self.__tcp_data_recv)
                if self.__tcp_length == 0:
                    raise ZKNetworkError("TCP packet invalid")
                self.__header = unpack('<4H', self.__tcp_data_recv[8:16])
                self.__data_recv = self.__tcp_data_recv[8:]
            else:
                self.__sock.sendto(buf, self.__address)
                self.__data_recv = self.__sock.recv(response_size)
                self.__header = unpack('<4H', self.__data_recv[:8])
        except Exception as e:
            raise ZKNetworkError(str(e))

        self.__response = self.__header[0]
        self.__reply_id = self.__header[3]
        self.__data = self.__data_recv[8:]
        if self.__response in [const.CMD_ACK_OK, const.CMD_PREPARE_DATA, const.CMD_DATA]:
            return {
                'status': True,
                'code': self.__response
            }
        return {
            'status': False,
            'code': self.__response
        }
80388
function sendCommand(command, data, options, callback) {
  return this.sendJson({ command: command, data: data }, options, callback);
}
604883
def _send_command(self, command):
        
        try:
            if isinstance(command, list):
                for cmd in command:
                    output = self.device.send_command(cmd)
                    if "% Invalid" not in output:
                        break
            else:
                output = self.device.send_command(command)
            return self._send_command_postprocess(output)
        except (socket.error, EOFError) as e:
            raise ConnectionClosedException(str(e))
737704
function send_command(command, cb) {
        var cmd = commands[command.toUpperCase()];
        if(parseInt(cmd)) {
            post('/roap/api/command', `<?xml version='1.0' encoding='utf-8'?><command><name>HandleKeyInput</name><value>${cmd}</value></command>`, (body) => {
                try {
                    var doc = new dom().parseFromString(body);
                    if(cb) cb(xpath.select('//ROAPErrorDetail/text()', doc).toString() == 'OK')
                } catch(error) {
                    log(`error send_command:  ${error.message}`)
                    if(cb) cb(false)
                }
            });
        }
    }
1320282
def __send_command(self, command, args=[]):
        ''''''
        self.ws.send(json.dumps({"op": command, "args": args}))
264125
def _send_cmd(self, cmd: str):
        """"""
        self._sock.sendall(cmd.encode(encoding='latin-1', errors='strict'))
848760
def _send_command(self, cmd_class, command, payload, timeout=3.0):
        

        if len(payload) > 60:
            return ValueError("Attempting to send a BGAPI packet with length > 60 is not allowed", actual_length=len(payload), command=command, command_class=cmd_class)

        header = bytearray(4)
        header[0] = 0
        header[1] = len(payload)
        header[2] = cmd_class
        header[3] = command

        packet = header + bytearray(payload)
        self._stream.write(bytes(packet))

        #Every command has a response so wait for the response here
        response = self._receive_packet(timeout)
        return response
199060
def send(self, commands):
        ""
        if not commands.endswith("\n"):
            commands += "\n"
        self.sock.send(commands)
1059031
def communicate(sock, command, settings=[]):
    """"""
    try:
        COMMUNICATE_LOCK.acquire()
        write_packet(sock, command)
        for option in settings:
            write_packet(sock, option)
        return read_packet(sock)
    finally:
        COMMUNICATE_LOCK.release()
631178
def cmd(send, msg, _):
    
    msg = msg.encode('utf-8')
    send(hashlib.sha512(msg).hexdigest())
1329156
def pack_command(self, *args):
        ""
        output = []
        # the client might have included 1 or more literal arguments in
        # the command name, e.g., 'CONFIG GET'. The Redis server expects these
        # arguments to be sent separately, so split the first argument
        # manually. All of these arguements get wrapped in the Token class
        # to prevent them from being encoded.
        command = args[0]
        if ' ' in command:
            args = tuple(Token.get_token(s)
                         for s in command.split()) + args[1:]
        else:
            args = (Token.get_token(command),) + args[1:]

        buff = SYM_EMPTY.join((SYM_STAR, str(len(args)).encode(), SYM_CRLF))

        buffer_cutoff = self._buffer_cutoff
        for arg in imap(self.encoder.encode, args):
            # to avoid large string mallocs, chunk the command into the
            # output list if we're sending large values
            if len(buff) > buffer_cutoff or len(arg) > buffer_cutoff:
                buff = SYM_EMPTY.join(
                    (buff, SYM_DOLLAR, str(len(arg)).encode(), SYM_CRLF))
                output.append(buff)
                output.append(arg)
                buff = SYM_CRLF
            else:
                buff = SYM_EMPTY.join(
                    (buff, SYM_DOLLAR, str(len(arg)).encode(),
                     SYM_CRLF, arg, SYM_CRLF))
        output.append(buff)
        return output
364248
def sendline(self, cmd):
        '''
        
        '''
        self.conn.sendline(cmd, self.linesep)

        # saw_prompt = False
        ret_stdout = []
        ret_stderr = []
        while self.conn.has_unread_data:
            stdout, stderr = self.conn.recv()

            if stdout:
                ret_stdout.append(stdout)
            if stderr:
                log.debug('Error while executing command.')
                ret_stderr.append(stderr)

            if stdout and self.prompt_re.search(stdout):
                break

        return ''.join(ret_stdout), ''.join(ret_stderr)
272346
def transfercmd(cmd, rest_offset = nil) # :nodoc:
      if @passive
        host, port = makepasv
        conn = open_socket(host, port)
        if @resume and rest_offset
          resp = sendcmd("REST " + rest_offset.to_s)
          if resp[0] != ?3
            raise FTPReplyError, resp
          end
        end
        resp = sendcmd(cmd)
        # skip 2XX for some ftp servers
        resp = getresp if resp[0] == ?2
        if resp[0] != ?1
          raise FTPReplyError, resp
        end
      else
        sock = makeport
        if @resume and rest_offset
          resp = sendcmd("REST " + rest_offset.to_s)
          if resp[0] != ?3
            raise FTPReplyError, resp
          end
        end
        resp = sendcmd(cmd)
        # skip 2XX for some ftp servers
        resp = getresp if resp[0] == ?2
        if resp[0] != ?1
          raise FTPReplyError, resp
        end
        conn = BufferedSocket.new(sock.accept)
        conn.read_timeout = @read_timeout
        sock.shutdown(Socket::SHUT_WR) rescue nil
        sock.read rescue nil
        sock.close
      end
      return conn
    end
458650
def SendCommand(self, command, arg=None):
        
        if arg is not None:
            if not isinstance(arg, bytes):
                arg = arg.encode('utf8')
            command = b'%s:%s' % (command, arg)

        self._Write(io.BytesIO(command), len(command))
12397
def command(cmd):
    """"""
    message = create(protobuf.SEND_COMMAND_MESSAGE)
    send_command = message.inner()
    send_command.command = cmd
    return message