text:
"""
Linux specific functions.
"""

from __future__ import absolute_import

from fcntl import ioctl
from select import select

import array
import ctypes
import os
import socket
import struct
import subprocess
import sys
import time

import scapy.utils
import scapy.utils6
from scapy.compat import raw, plain_str
from scapy.consts import LINUX
from scapy.arch.common import (
    _iff_flags,
    compile_filter,
    get_if,
    get_if_raw_hwaddr,
)
from scapy.config import conf
from scapy.data import MTU, ETH_P_ALL, SOL_PACKET, SO_ATTACH_FILTER, \
    SO_TIMESTAMPNS
from scapy.error import (
    ScapyInvalidPlatformException,
    Scapy_Exception,
    log_loading,
    log_runtime,
    warning,
)
from scapy.interfaces import IFACES, InterfaceProvider, NetworkInterface, \
    network_name
from scapy.libs.structures import sock_fprog
from scapy.packet import Packet, Padding
from scapy.pton_ntop import inet_ntop
from scapy.supersocket import SuperSocket

import scapy.modules.six as six
from scapy.modules.six.moves import range

# Typing imports
from scapy.compat import (
    Any,
    Callable,
    Dict,
    List,
    NoReturn,
    Optional,
    Tuple,
    Type,
    Union,
)

# From bits/ioctls.h
SIOCGIFHWADDR = 0x8927          # Get hardware address
SIOCGIFADDR = 0x8915          # get PA address
SIOCGIFNETMASK = 0x891b          # get network PA mask
SIOCGIFNAME = 0x8910          # get iface name
SIOCSIFLINK = 0x8911          # set iface channel
SIOCGIFCONF = 0x8912          # get iface list
SIOCGIFFLAGS = 0x8913          # get flags
SIOCSIFFLAGS = 0x8914          # set flags
SIOCGIFINDEX = 0x8933          # name -> if_index mapping
SIOCGIFCOUNT = 0x8938          # get number of devices
SIOCGSTAMP = 0x8906          # get packet timestamp (as a timeval)

# From if.h
IFF_UP = 0x1               # Interface is up.
IFF_BROADCAST = 0x2        # Broadcast address valid.
IFF_DEBUG = 0x4            # Turn on debugging.
IFF_LOOPBACK = 0x8         # Is a loopback net.
IFF_POINTOPOINT = 0x10     # Interface is point-to-point link.
IFF_NOTRAILERS = 0x20      # Avoid use of trailers.
IFF_RUNNING = 0x40         # Resources allocated.
IFF_NOARP = 0x80           # No address resolution protocol.
IFF_PROMISC = 0x100        # Receive all packets.

# From netpacket/packet.h
PACKET_ADD_MEMBERSHIP = 1
PACKET_DROP_MEMBERSHIP = 2
PACKET_RECV_OUTPUT = 3
PACKET_RX_RING = 5
PACKET_STATISTICS = 6
PACKET_MR_MULTICAST = 0
PACKET_MR_PROMISC = 1
PACKET_MR_ALLMULTI = 2

# From net/route.h
RTF_UP = 0x0001  # Route usable
RTF_REJECT = 0x0200

# From if_packet.h
PACKET_HOST = 0  # To us
PACKET_BROADCAST = 1  # To all
PACKET_MULTICAST = 2  # To group
PACKET_OTHERHOST = 3  # To someone else
PACKET_OUTGOING = 4  # Outgoing of any type
PACKET_LOOPBACK = 5  # MC/BRD frame looped back
PACKET_USER = 6  # To user space
PACKET_KERNEL = 7  # To kernel space
PACKET_AUXDATA = 8
PACKET_FASTROUTE = 6  # Fastrouted frame
# Unused, PACKET_FASTROUTE and PACKET_LOOPBACK are invisible to user space

# Utils

def get_if_raw_addr(iff):
    # type: (Union[NetworkInterface, str]) -> bytes
    r"""
    Return the raw IPv4 address of an interface.
    If unavailable, returns b"\0\0\0\0"
    """
    try:
        return get_if(iff, SIOCGIFADDR)[20:24]
    except IOError:
        return b"\0\0\0\0"

def _get_if_list():
    # type: () -> List[str]
    """
    Function to read the interfaces from /proc/net/dev
    """
    try:
        f = open("/proc/net/dev", "rb")
    except IOError:
        try:
            f.close()
        except Exception:
            pass
        log_loading.critical("Can't open /proc/net/dev !")
        return []
    lst = []
    f.readline()
    f.readline()
    for line in f:
        lst.append(plain_str(line).split(":")[0].strip())
    f.close()
    return lst

def attach_filter(sock, bpf_filter, iface):
    # type: (socket.socket, str, Union[NetworkInterface, str]) -> None
    """
    Compile bpf filter and attach it to a socket

    :param sock: the python socket
    :param bpf_filter: the bpf string filter to compile
    :param iface: the interface used to compile
    """
    bp = compile_filter(bpf_filter, iface)
    if conf.use_pypy and sys.pypy_version_info <= (7, 3, 2):  # type: ignore
        # PyPy < 7.3.2 has a broken behavior
        # https://foss.heptapod.net/pypy/pypy/-/issues/3298
        bp = struct.pack(
            'HL',
            bp.bf_len, ctypes.addressof(bp.bf_insns.contents)
        )
    else:
        bp = sock_fprog(bp.bf_len, bp.bf_insns)
    sock.setsockopt(socket.SOL_SOCKET, SO_ATTACH_FILTER, bp)

def set_promisc(s, iff, val=1):
    # type: (socket.socket, Union[NetworkInterface, str], int) -> None
    mreq = struct.pack("IHH8s", get_if_index(iff), PACKET_MR_PROMISC, 0, b"")
    if val:
        cmd = PACKET_ADD_MEMBERSHIP
    else:
        cmd = PACKET_DROP_MEMBERSHIP
    s.setsockopt(SOL_PACKET, cmd, mreq)

def get_alias_address(iface_name,  # type: str
                      ip_mask,  # type: int
                      gw_str,  # type: str
                      metric  # type: int
                      ):
    # type: (...) -> Optional[Tuple[int, int, str, str, str, int]]
    """
    Get the correct source IP address of an interface alias
    """

    # Detect the architecture
    if scapy.consts.IS_64BITS:
        offset, name_len = 16, 40
    else:
        offset, name_len = 32, 32

    # Retrieve interfaces structures
    sck = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    names_ar = array.array('B', b'\0' * 4096)
    ifreq = ioctl(sck.fileno(), SIOCGIFCONF,
                  struct.pack("iL", len(names_ar), names_ar.buffer_info()[0]))

    # Extract interfaces names
    out = struct.unpack("iL", ifreq)[0]
    names_b = names_ar.tobytes() if six.PY3 else names_ar.tostring()
    names = [names_b[i:i + offset].split(b'\0', 1)[0] for i in range(0, out, name_len)]  # noqa: E501

    # Look for the IP address
    for ifname_b in names:
        ifname = plain_str(ifname_b)
        # Only look for a matching interface name
        if not ifname.startswith(iface_name):
            continue

        # Retrieve and convert addresses
        ifreq = ioctl(sck, SIOCGIFADDR, struct.pack("16s16x", ifname_b))
        ifaddr = struct.unpack(">I", ifreq[20:24])[0]  # type: int
        ifreq = ioctl(sck, SIOCGIFNETMASK, struct.pack("16s16x", ifname_b))
        msk = struct.unpack(">I", ifreq[20:24])[0]  # type: int

        # Get the full interface name
        if ':' in ifname:
            ifname = ifname[:ifname.index(':')]
        else:
            continue

        # Check if the source address is included in the network
        if (ifaddr & msk) == ip_mask:
            sck.close()
            return (ifaddr & msk, msk, gw_str, ifname,
                    scapy.utils.ltoa(ifaddr), metric)

    sck.close()
    return None

def read_routes():
    # type: () -> List[Tuple[int, int, str, str, str, int]]
    try:
        f = open("/proc/net/route", "rb")
    except IOError:
        log_loading.critical("Can't open /proc/net/route !")
        return []
    routes = []
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    try:
        ifreq = ioctl(s, SIOCGIFADDR, struct.pack("16s16x", conf.loopback_name.encode("utf8")))  # noqa: E501
        addrfamily = struct.unpack("h", ifreq[16:18])[0]
        if addrfamily == socket.AF_INET:
            ifreq2 = ioctl(s, SIOCGIFNETMASK, struct.pack("16s16x", conf.loopback_name.encode("utf8")))  # noqa: E501
            msk = socket.ntohl(struct.unpack("I", ifreq2[20:24])[0])
            dst = socket.ntohl(struct.unpack("I", ifreq[20:24])[0]) & msk
            ifaddr = scapy.utils.inet_ntoa(ifreq[20:24])
            routes.append((dst, msk, "0.0.0.0", conf.loopback_name, ifaddr, 1))  # noqa: E501
        else:
            warning("Interface %s: unknown address family (%i)" % (conf.loopback_name, addrfamily))  # noqa: E501
    except IOError as err:
        if err.errno == 99:
            warning("Interface %s: no address assigned" % conf.loopback_name)  # noqa: E501
        else:
            warning("Interface %s: failed to get address config (%s)" % (conf.loopback_name, str(err)))  # noqa: E501

    for line_b in f.readlines()[1:]:
        line = plain_str(line_b)
        iff, dst_b, gw, flags_b, _, _, metric_b, msk_b, _, _, _ = line.split()
        flags = int(flags_b, 16)
        if flags & RTF_UP == 0:
            continue
        if flags & RTF_REJECT:
            continue
        try:
            ifreq = ioctl(s, SIOCGIFADDR, struct.pack("16s16x", iff.encode("utf8")))  # noqa: E501
        except IOError:  # interface is present in routing tables but does not have any assigned IP  # noqa: E501
            ifaddr = "0.0.0.0"
            ifaddr_int = 0
        else:
            addrfamily = struct.unpack("h", ifreq[16:18])[0]
            if addrfamily == socket.AF_INET:
                ifaddr = scapy.utils.inet_ntoa(ifreq[20:24])
                ifaddr_int = struct.unpack("!I", ifreq[20:24])[0]
            else:
                warning("Interface %s: unknown address family (%i)", iff, addrfamily)  # noqa: E501
                continue

        # Attempt to detect an interface alias based on addresses inconsistencies  # noqa: E501
        dst_int = socket.htonl(int(dst_b, 16)) & 0xffffffff
        msk_int = socket.htonl(int(msk_b, 16)) & 0xffffffff
        gw_str = scapy.utils.inet_ntoa(struct.pack("I", int(gw, 16)))
        metric = int(metric_b)

        route = (dst_int, msk_int, gw_str, iff, ifaddr, metric)
        if ifaddr_int & msk_int != dst_int:
            tmp_route = get_alias_address(iff, dst_int, gw_str, metric)
            if tmp_route:
                route = tmp_route
        routes.append(route)

    f.close()
    s.close()
    return routes

############
#   IPv6   #
############

def in6_getifaddr():
    # type: () -> List[Tuple[str, int, str]]
    """
    Returns a list of 3-tuples of the form (addr, scope, iface) where
    'addr' is the address of scope 'scope' associated to the interface
    'iface'.

    This is the list of all addresses of all interfaces available on
    the system.
    """
    ret = []  # type: List[Tuple[str, int, str]]
    try:
        fdesc = open("/proc/net/if_inet6", "rb")
    except IOError:
        return ret
    for line in fdesc:
        # addr, index, plen, scope, flags, ifname
        tmp = plain_str(line).split()
        addr = scapy.utils6.in6_ptop(
            b':'.join(
                struct.unpack('4s4s4s4s4s4s4s4s', tmp[0].encode())
            ).decode()
        )
        # (addr, scope, iface)
        ret.append((addr, int(tmp[3], 16), tmp[5]))
    fdesc.close()
    return ret

def read_routes6():
    # type: () -> List[Tuple[str, int, str, str, List[str], int]]
    try:
        f = open("/proc/net/ipv6_route", "rb")
    except IOError:
        return []
    # 1. destination network
    # 2. destination prefix length
    # 3. source network displayed
    # 4. source prefix length
    # 5. next hop
    # 6. metric
    # 7. reference counter (?!?)
    # 8. use counter (?!?)
    # 9. flags
    # 10. device name
    routes = []

    def proc2r(p):
        # type: (bytes) -> str
        ret = struct.unpack('4s4s4s4s4s4s4s4s', p)
        addr = b':'.join(ret).decode()
        return scapy.utils6.in6_ptop(addr)

    lifaddr = in6_getifaddr()
    for line in f.readlines():
        d_b, dp_b, _, _, nh_b, metric_b, rc, us, fl_b, dev_b = line.split()
        metric = int(metric_b, 16)
        fl = int(fl_b, 16)
        dev = plain_str(dev_b)

        if fl & RTF_UP == 0:
            continue
        if fl & RTF_REJECT:
            continue

        d = proc2r(d_b)
        dp = int(dp_b, 16)
        nh = proc2r(nh_b)

        cset = []  # candidate set (possible source addresses)
        if dev == conf.loopback_name:
            if d == '::':
                continue
            cset = ['::1']
        else:
            devaddrs = (x for x in lifaddr if x[2] == dev)
            cset = scapy.utils6.construct_source_candidate_set(d, dp, devaddrs)

        if len(cset) != 0:
            routes.append((d, dp, nh, dev, cset, metric))
    f.close()
    return routes

def get_if_index(iff):
    # type: (Union[NetworkInterface, str]) -> int
    return int(struct.unpack("I", get_if(iff, SIOCGIFINDEX)[16:20])[0])

class LinuxInterfaceProvider(InterfaceProvider):
    name = "sys"

    def _is_valid(self, dev):
        # type: (NetworkInterface) -> bool
        return bool(dev.flags & IFF_UP)

    def load(self):
        # type: () -> Dict[str, NetworkInterface]
        from scapy.fields import FlagValue
        data = {}
        ips = in6_getifaddr()
        for i in _get_if_list():
            ifflags = struct.unpack("16xH14x", get_if(i, SIOCGIFFLAGS))[0]
            index = get_if_index(i)
            mac = scapy.utils.str2mac(
                get_if_raw_hwaddr(i, siocgifhwaddr=SIOCGIFHWADDR)[1]
            )
            ip = None  # type: Optional[str]
            ip = inet_ntop(socket.AF_INET, get_if_raw_addr(i))
            if ip == "0.0.0.0":
                ip = None
            ifflags = FlagValue(ifflags, _iff_flags)
            if_data = {
                "name": i,
                "network_name": i,
                "description": i,
                "flags": ifflags,
                "index": index,
                "ip": ip,
                "ips": [x[0] for x in ips if x[2] == i] + [ip] if ip else [],
                "mac": mac
            }
            data[i] = NetworkInterface(self, if_data)
        return data

IFACES.register_provider(LinuxInterfaceProvider)

if os.uname()[4] in ['x86_64', 'aarch64']:
    def get_last_packet_timestamp(sock):
        # type: (socket.socket) -> float
        ts = ioctl(sock, SIOCGSTAMP, "1234567890123456")  # type: ignore
        s, us = struct.unpack("QQ", ts)  # type: Tuple[int, int]
        return s + us / 1000000.0
else:
    def get_last_packet_timestamp(sock):
        # type: (socket.socket) -> float
        ts = ioctl(sock, SIOCGSTAMP, "12345678")  # type: ignore
        s, us = struct.unpack("II", ts)  # type: Tuple[int, int]
        return s + us / 1000000.0

def _flush_fd(fd):
    # type: (int) -> None
    while True:
        r, w, e = select([fd], [], [], 0)
        if r:
            os.read(fd, MTU)
        else:
            break

class L2Socket(SuperSocket):
    desc = "read/write packets at layer 2 using Linux PF_PACKET sockets"

    def __init__(self,
                 iface=None,  # type: Optional[Union[str, NetworkInterface]]
                 type=ETH_P_ALL,  # type: int
                 promisc=None,  # type: Optional[Any]
                 filter=None,  # type: Optional[Any]
                 nofilter=0,  # type: int
                 monitor=None,  # type: Optional[Any]
                 ):
        # type: (...) -> None
        self.iface = network_name(iface or conf.iface)
        self.type = type
        self.promisc = conf.sniff_promisc if promisc is None else promisc
        if monitor is not None:
            log_runtime.info(
                "The 'monitor' argument has no effect on native linux sockets."
            )
        self.ins = socket.socket(
            socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type))
        self.ins.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 0)
        if not nofilter:
            if conf.except_filter:
                if filter:
                    filter = "(%s) and not (%s)" % (filter, conf.except_filter)
                else:
                    filter = "not (%s)" % conf.except_filter
            if filter is not None:
                try:
                    attach_filter(self.ins, filter, self.iface)
                except ImportError as ex:
                    log_runtime.error("Cannot set filter: %s", ex)
        if self.promisc:
            set_promisc(self.ins, self.iface)
        self.ins.bind((self.iface, type))
        _flush_fd(self.ins.fileno())
        self.ins.setsockopt(
            socket.SOL_SOCKET,
            socket.SO_RCVBUF,
            conf.bufsize
        )
        if not six.PY2:
            # Receive Auxiliary Data (VLAN tags)
            try:
                self.ins.setsockopt(SOL_PACKET, PACKET_AUXDATA, 1)
                self.ins.setsockopt(
                    socket.SOL_SOCKET,
                    SO_TIMESTAMPNS,
                    1
                )
                self.auxdata_available = True
            except OSError:
                # Note: Auxiliary Data is only supported since
                #       Linux 2.6.21
                msg = "Your Linux Kernel does not support Auxiliary Data!"
                log_runtime.info(msg)
        if not isinstance(self, L2ListenSocket):
            self.outs = self.ins  # type: socket.socket
            self.outs.setsockopt(
                socket.SOL_SOCKET,
                socket.SO_SNDBUF,
                conf.bufsize
            )
        else:
            self.outs = None  # type: ignore
        sa_ll = self.ins.getsockname()
        if sa_ll[3] in conf.l2types:
            self.LL = conf.l2types.num2layer[sa_ll[3]]
            self.lvl = 2
        elif sa_ll[1] in conf.l3types:
            self.LL = conf.l3types.num2layer[sa_ll[1]]
            self.lvl = 3
        else:
            self.LL = conf.default_l2
            self.lvl = 2
            warning("Unable to guess type (interface=%s protocol=%#x family=%i). Using %s", sa_ll[0], sa_ll[1], sa_ll[3], self.LL.name)  # noqa: E501

    def close(self):
        # type: () -> None
        if self.closed:
            return
        try:
            if self.promisc and self.ins:
                set_promisc(self.ins, self.iface, 0)
        except (AttributeError, OSError):
            pass
        SuperSocket.close(self)

    def recv_raw(self, x=MTU):
        # type: (int) -> Tuple[Optional[Type[Packet]], Optional[bytes], Optional[float]]  # noqa: E501
        """Receives a packet, then returns a tuple containing (cls, pkt_data, time)"""  # noqa: E501
        pkt, sa_ll, ts = self._recv_raw(self.ins, x)
        if self.outs and sa_ll[2] == socket.PACKET_OUTGOING:
            return None, None, None
        if ts is None:
            ts = get_last_packet_timestamp(self.ins)
        return self.LL, pkt, ts

    def send(self, x):
        # type: (Packet) -> int
        try:
            return SuperSocket.send(self, x)
        except socket.error as msg:
            if msg.errno == 22 and len(x) < conf.min_pkt_size:
                padding = b"\x00" * (conf.min_pkt_size - len(x))
                if isinstance(x, Packet):
                    return SuperSocket.send(self, x / Padding(load=padding))
                else:
                    return SuperSocket.send(self, raw(x) + padding)
            raise

class L2ListenSocket(L2Socket):
    desc = "read packets at layer 2 using Linux PF_PACKET sockets. Also receives the packets going OUT"  # noqa: E501

    def send(self, x):
        # type: (Packet) -> NoReturn
        raise Scapy_Exception("Can't send anything with L2ListenSocket")

class L3PacketSocket(L2Socket):
    desc = "read/write packets at layer 3 using Linux PF_PACKET sockets"

    def recv(self, x=MTU):
        # type: (int) -> Optional[Packet]
        pkt = SuperSocket.recv(self, x)
        if pkt and self.lvl == 2:
            pkt.payload.time = pkt.time
            return pkt.payload
        return pkt

    def send(self, x):
        # type: (Packet) -> int
        iff = x.route()[0]
        if iff is None:
            iff = conf.iface
        sdto = (iff, self.type)
        self.outs.bind(sdto)
        sn = self.outs.getsockname()
        ll = lambda x: x  # type: Callable[[Packet], Packet]
        type_x = type(x)
        if type_x in conf.l3types:
            sdto = (iff, conf.l3types.layer2num[type_x])
        if sn[3] in conf.l2types:
            ll = lambda x: conf.l2types.num2layer[sn[3]]() / x
        if self.lvl == 3 and type_x != self.LL:
            warning("Incompatible L3 types detected using %s instead of %s !",
                    type_x, self.LL)
            self.LL = type_x
        sx = raw(ll(x))
        x.sent_time = time.time()
        try:
            return self.outs.sendto(sx, sdto)
        except socket.error as msg:
            if msg.errno == 22 and len(sx) < conf.min_pkt_size:
                return self.outs.send(
                    sx + b"\x00" * (conf.min_pkt_size - len(sx))
                )
            elif conf.auto_fragment and msg.errno == 90:
                i = 0
                for p in x.fragment():
                    i += self.outs.sendto(raw(ll(p)), sdto)
                return i
            else:
                raise

class VEthPair(object):
    """
    encapsulates a virtual Ethernet interface pair
    """

    def __init__(self, iface_name, peer_name):
        # type: (str, str) -> None
        if not LINUX:
            # ToDo: do we need a kernel version check here?
            raise ScapyInvalidPlatformException(
                'Virtual Ethernet interface pair only available on Linux'
            )

        self.ifaces = [iface_name, peer_name]

    def iface(self):
        # type: () -> str
        return self.ifaces[0]

    def peer(self):
        # type: () -> str
        return self.ifaces[1]

    def setup(self):
        # type: () -> None
        """
        create veth pair links
        :raises subprocess.CalledProcessError if operation fails
        """
        subprocess.check_call(['ip', 'link', 'add', self.ifaces[0], 'type', 'veth', 'peer', 'name', self.ifaces[1]])  # noqa: E501

    def destroy(self):
        # type: () -> None
        """
        remove veth pair links
        :raises subprocess.CalledProcessError if operation fails
        """
        subprocess.check_call(['ip', 'link', 'del', self.ifaces[0]])

    def up(self):
        # type: () -> None
        """
        set veth pair links up
        :raises subprocess.CalledProcessError if operation fails
        """
        for idx in [0, 1]:
            subprocess.check_call(["ip", "link", "set", self.ifaces[idx], "up"])  # noqa: E501

    def down(self):
        # type: () -> None
        """
        set veth pair links down
        :raises subprocess.CalledProcessError if operation fails
        """
        for idx in [0, 1]:
            subprocess.check_call(["ip", "link", "set", self.ifaces[idx], "down"])  # noqa: E501

    def __enter__(self):
        # type: () -> VEthPair
        self.setup()
        self.up()
        conf.ifaces.reload()
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        # type: (Any, Any, Any) -> None
        self.destroy()
        conf.ifaces.reload()


text:
<?php

namespace Laravel\Forge\Services;

use Laravel\Forge\Contracts\ServiceContract;
use Laravel\Forge\Services\Commands\StopServiceCommand;
use Laravel\Forge\Services\Commands\RebootServiceCommand;
use Laravel\Forge\Services\Commands\InstallServiceCommand;
use Laravel\Forge\Services\Commands\UninstallServiceCommand;

class ServicesManager
{
    /**
     * Install the service.
     *
     * @param \Laravel\Forge\Contracts\ServiceContract $service
     *
     * @return \Laravel\Forge\Services\Commands\InstallServiceCommand
     */
    public function install(ServiceContract $service)
    {
        return new InstallServiceCommand($service);
    }

    /**
     * Reboot the service.
     *
     * @param \Laravel\Forge\Contracts\ServiceContract $service
     *
     * @return \Laravel\Forge\Services\Commands\RebootServiceCommand
     */
    public function reboot(ServiceContract $service)
    {
        return new RebootServiceCommand($service);
    }

    /**
     * Stop the service.
     *
     * @param \Laravel\Forge\Contracts\ServiceContract $service
     *
     * @return \Laravel\Forge\Services\Commands\StopServiceCommand
     */
    public function stop(ServiceContract $service)
    {
        return new StopServiceCommand($service);
    }

    /**
     * Uninstall the service.
     *
     * @param \Laravel\Forge\Contracts\ServiceContract $service
     *
     * @return \Laravel\Forge\Services\Commands\UninstallServiceCommand
     */
    public function uninstall(ServiceContract $service)
    {
        return new UninstallServiceCommand($service);
    }
}

redpajama_set_name: RedPajamaGithub


text:
<?php defined('SYSPATH') or die('No direct access allowed.');

class Model_Kohana_Ulogin extends ORM {

	protected $_belongs_to = array(
		'user' => array(),
	);

	public function rules()
	{
		return array(
			'network' => array(
				array('not_empty'),
				array('max_length', array(':value', 255)),
			),
			'identity' => array(
				array('not_empty'),
				array('max_length', array(':value', 255)),
				array(array($this, 'unique'), array('identity', ':value')),
			),
		);
	}
}


text:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    style="@style/MyCustomTheme"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="bottom" >

    <!--
    <TextView
        android:id="@+id/txtLabel"
         android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:textSize="16sp"
        android:text="Home View"/>

    <ImageView android:layout_width="wrap_content"

        android:layout_height="wrap_content"
        android:layout_below="@id/txtLabel"
        android:src="@drawable/ic_home"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp"/>

-->

    <WebView
        android:id="@+id/webView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" />

    <Button
        android:id="@+id/buttonrefresh"
        style="@style/DefaultButtonText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"

        android:text="@string/refresh"
        android:visibility="gone"
        android:padding="10dp"
        android:textSize="20sp"
        android:background="@drawable/button_2"/>

    <ProgressBar
        android:id="@+id/progressBar1web"
        style="?android:attr/progressBarStyleHorizontal"

   android:background="#1E88E5"

        android:layout_width="match_parent"
        android:layout_height="25dp"
        android:layout_marginTop="-5dp"
        android:layout_alignParentRight="true"
         />

    <TextView
        android:id="@+id/loadin"
        style="@style/DefaultButtonText2"
        android:background="#1E88E5"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/progressBar1web"
        android:text="@string/loading"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textSize="20sp" />
<!--
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:background="#000"
        android:orientation="vertical" >

        <HorizontalScrollView
            android:id="@+id/horizontalScrollView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Hello" />

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Hello" />

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Hello" />
            </LinearLayout>
        </HorizontalScrollView>
    </LinearLayout>
    -->

</RelativeLayout>


text:
class ExpectationNotMetError < StandardError; end

class Expectation
  def self.fail_with(expected, actual)
    if expected.to_s.size + actual.to_s.size > 80
      message = expected.to_s.chomp + "\n" + actual.to_s
    else
      message = expected.to_s + " " + actual.to_s
    end
    Kernel.raise ExpectationNotMetError, message
  end
end


text:
require 'pathname'
require 'singleton'
require 'yaml'

module CloudApp
  class TUI
    class Config
      def initialize(path = File.expand_path('~/.cloudapprc'))
        @path   = path
        @config = read_config
      end

      def token
        @config[:token]
      end

      def token=(token)
        if token
          @config[:token] = token
        else
          @config.delete :token
        end

        write_config
      end

    private

      def read_config
        return {} unless File.exist?(@path)
        File.open(@path) {|file| YAML.load(file) }
      end

      def write_config
        File.open(@path, 'w', 0600) {|file|
          YAML.dump @config, file
        }
      end
    end
  end
end


text:
ACCEPTED

#### According to
The Catalogue of Life, 3rd January 2011

#### Published in
null

#### Original name
Odontoglossum ioplocon Rchb.f.

### Remarks
null


text:
@interface JICoreDataOperation : NSOperation

@property (nonatomic, strong, readwrite) NSManagedObjectContext *parentContext;
@property (nonatomic, strong, readonly) NSManagedObjectContext *managedObjectContext;

- (id)initWithParentContext:(NSManagedObjectContext *)parentContext;

- (void)doWork;
- (void)finish;
- (BOOL)resolveSaveError:(NSError *)error;

@end


text:
import time
from datetime import datetime

class Stopwatch:
    __slots__ = ["start_ticks", "stop_ticks", "start_ts", "stop_ts", "flag"]

    def __init__(self):
        self.flag = 0
        self.start_ticks = time.time()
        self.start_ts = datetime.now()
        self.stop_ticks = 0
        self.stop_ts = None

    def start(self):
        if self.flag == None:
            print "The stopwatch is frozen."
            return self
        self.flag = 0
        self.start_ticks = time.time()
        self.start_ts = datetime.now()
        self.stop_ticks = 0
        self.stop_ts = None
        return self

    def stop(self):
        if self.flag == None:
            print "The stopwatch is frozen."
            return self

        self.flag = 1
        self.stop_ticks = time.time()
        self.stop_ts = datetime.now()
        return self

    def reset(self):
        if self.flag == None:
            print "The stopwatch is frozen."
            return self

        self.flag = 0
        self.start_ticks = time.time()
        self.start_ts = datetime.now()
        self.stop_ticks = 0
        self.stop_ts = None
        return self

    def rewind(self, ticks):
        self.start_ticks = (self.start_ticks - ticks)
        return self

    def offset(self, ticks):
        self.start_ticks = (self.start_ticks + ticks)
        return self

    def freeze(self):
        if self.flag == None:
            print "The stopwatch is frozen."
            return self

        self.flag = None
        self.stop_ticks = time.time()
        self.stop_ts = datetime.now()
        return self

    def elapsed(self, precision=4):
        start = self.start_ticks
        stop = time.time() if self.flag == 0 else self.stop_ticks
        #stop = self.stop_ticks if self.flag == 1 else ticks()
        diff = (stop - start)
        diff = round(diff, precision)
        return diff

    def average(self, count, precision=3):
        assert count is not None, "The count parameter is null!"
        time = self.elapsed()
        if count <= 1:
            return time

        avg = (time / float(count))
        try:
            avg = round(avg, precision)
        except:
            avg = round(avg, 3)

        return avg

    def sleep_until(self, milliseconds=0, seconds=0):
        if seconds > 0:
            while self.seconds < seconds:
                time.sleep(.05)
            return self

        if milliseconds > 0:
            while self.milliseconds < milliseconds:
                time.sleep(.05)
            return self
        return self

    @property
    def milliseconds(self):
        return self.elapsed()

    @property
    def seconds(self):
        time = self.elapsed()
        secs = round(time, 1)
        return secs

    def trace_average(self, count, precision=3):
        txt = self.emit_average(count, precision=precision)
        txt = self._format_pretty(txt)
        #sys.stdout.write(txt + "\n")
        return txt

    def __str__(self):
        #return self.emit()
        return "%s milliseconds" % str(self.milliseconds)

    def __repr__(self):
        return self.__str__()

    @staticmethod
    def create():
        return Stopwatch()


text:
package com.miaotu.result;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.miaotu.model.BlackInfo;
import com.miaotu.model.RemindLike;

import java.util.List;

/**
 * Created by Jayden on 2015/5/29.
 */
public class RemindLikeResult extends BaseResult {
    @JsonProperty("Items")
    private List<RemindLike> remindLikes;

    public List<RemindLike> getRemindLikes() {
        return remindLikes;
    }

    public void setRemindLikes(List<RemindLike> remindLikes) {
        this.remindLikes = remindLikes;
    }
}