def build_response(self, request, response, from_cache=False):

if not from_cache and request.method == '<STR_LIT:GET>':<EOL><INDENT>if response.status == <NUM_LIT>:<EOL><INDENT>cached_response = self.controller.update_cached_response(<EOL>request, response<EOL>)<EOL>if cached_response is not response:<EOL><INDENT>from_cache = True<EOL><DEDENT>response.read(decode_content=False)<EOL>response.release_conn()<EOL>response = cached_response<EOL><DEDENT>else:<EOL><INDENT>if self.heuristic:<EOL><INDENT>response = self.heuristic.apply(response)<EOL><DEDENT>response._fp = CallbackFileWrapper(<EOL>response._fp,<EOL>functools.partial(<EOL>self.controller.cache_response,<EOL>request,<EOL>response,<EOL>)<EOL>)<EOL><DEDENT><DEDENT>resp = super(CacheControlAdapter, self).build_response(<EOL>request, response<EOL>)<EOL>if request.method in self.invalidating_methods and resp.ok:<EOL><INDENT>cache_url = self.controller.cache_url(request.url)<EOL>self.cache.delete(cache_url)<EOL><DEDENT>resp.from_cache = from_cache<EOL>return resp<EOL>

Build a response by making a request or using the cache.

This will end up calling send and returning a potentially
cached response


for key in self.conn.keys():<EOL><INDENT>self.conn.delete(key)<EOL><DEDENT>

Helper for clearing all the keys in a database. Use with
        caution!


def _prefix_from_ip_int(self, ip_int, mask=<NUM_LIT:32>):

return mask - _count_righthand_zero_bits(ip_int, mask)<EOL>

Return prefix length from the decimal netmask.

        Args:
            ip_int: An integer, the IP address.
            mask: The netmask.  Defaults to 32.

        Returns:
            An integer, the prefix length.


_BaseAddress.__init__(self, address)<EOL>_BaseV6.__init__(self, address)<EOL>if isinstance(address, _compat_int_types):<EOL><INDENT>self._check_int_address(address)<EOL>self._ip = address<EOL>return<EOL><DEDENT>if isinstance(address, bytes):<EOL><INDENT>self._check_packed_address(address, <NUM_LIT:16>)<EOL>bvs = _compat_bytes_to_byte_vals(address)<EOL>self._ip = _compat_int_from_byte_vals(bvs, '<STR_LIT>')<EOL>return<EOL><DEDENT>addr_str = _compat_str(address)<EOL>self._ip = self._ip_int_from_string(addr_str)<EOL>

Instantiate a new IPv6 address object.

        Args:
            address: A string or integer representing the IP

              Additionally, an integer can be passed, so
              IPv6Address('2001:db8::') ==
                IPv6Address(42540766411282592856903984951653826560)
              or, more generally
              IPv6Address(int(IPv6Address('2001:db8::'))) ==
                IPv6Address('2001:db8::')

        Raises:
            AddressValueError: If address isn't a valid IPv6 address.


if not octet_str:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not self._DECIMAL_DIGITS.issuperset(octet_str):<EOL><INDENT>msg = "<STR_LIT>"<EOL>raise ValueError(msg % octet_str)<EOL><DEDENT>if len(octet_str) > <NUM_LIT:3>:<EOL><INDENT>msg = "<STR_LIT>"<EOL>raise ValueError(msg % octet_str)<EOL><DEDENT>octet_int = int(octet_str, <NUM_LIT:10>)<EOL>if octet_int > <NUM_LIT:7> and octet_str[<NUM_LIT:0>] == '<STR_LIT:0>':<EOL><INDENT>msg = "<STR_LIT>"<EOL>raise ValueError(msg % octet_str)<EOL><DEDENT>if octet_int > <NUM_LIT:255>:<EOL><INDENT>raise ValueError("<STR_LIT>" % octet_int)<EOL><DEDENT>return octet_int<EOL>

Convert a decimal octet into an integer.

        Args:
            octet_str: A string, the number to parse.

        Returns:
            The octet as an integer.

        Raises:
            ValueError: if the octet isn't strictly a decimal from [0..255].


return _compat_str(self)<EOL>

Return the shorthand version of the IP address as a string.


if (not (isinstance(first, _BaseAddress) and<EOL>isinstance(last, _BaseAddress))):<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>if first.version != last.version:<EOL><INDENT>raise TypeError("<STR_LIT>" %<EOL>(first, last))<EOL><DEDENT>if first > last:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if first.version == <NUM_LIT:4>:<EOL><INDENT>ip = IPv4Network<EOL><DEDENT>elif first.version == <NUM_LIT:6>:<EOL><INDENT>ip = IPv6Network<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>ip_bits = first._max_prefixlen<EOL>first_int = first._ip<EOL>last_int = last._ip<EOL>while first_int <= last_int:<EOL><INDENT>nbits = min(_count_righthand_zero_bits(first_int, ip_bits),<EOL>_compat_bit_length(last_int - first_int + <NUM_LIT:1>) - <NUM_LIT:1>)<EOL>net = ip('<STR_LIT>' % (first, ip_bits - nbits))<EOL>yield net<EOL>first_int += <NUM_LIT:1> << nbits<EOL>if first_int - <NUM_LIT:1> == ip._ALL_ONES:<EOL><INDENT>break<EOL><DEDENT>first = first.__class__(first_int)<EOL><DEDENT>

Summarize a network range given the first and last IP addresses.

    Example:
        >>> list(summarize_address_range(IPv4Address('192.0.2.0'),
        ...                              IPv4Address('192.0.2.130')))
        ...                                #doctest: +NORMALIZE_WHITESPACE
        [IPv4Network('192.0.2.0/25'), IPv4Network('192.0.2.128/31'),
         IPv4Network('192.0.2.130/32')]

    Args:
        first: the first IPv4Address or IPv6Address in the range.
        last: the last IPv4Address or IPv6Address in the range.

    Returns:
        An iterator of the summarized IPv(4|6) network objects.

    Raise:
        TypeError:
            If the first and last objects are not IP addresses.
            If the first and last objects are not the same version.
        ValueError:
            If the last object is not greater than the first.
            If the version of the first address is not 4 or 6.


return self._ip == <NUM_LIT:0><EOL>

Test if the address is unspecified.

        Returns:
            A boolean, True if this is the unspecified address as defined in
            RFC 2373 2.5.2.


<EOL>if not self._HEX_DIGITS.issuperset(hextet_str):<EOL><INDENT>raise ValueError("<STR_LIT>" % hextet_str)<EOL><DEDENT>if len(hextet_str) > <NUM_LIT:4>:<EOL><INDENT>msg = "<STR_LIT>"<EOL>raise ValueError(msg % hextet_str)<EOL><DEDENT>return int(hextet_str, <NUM_LIT:16>)<EOL>

Convert an IPv6 hextet string into an integer.

        Args:
            hextet_str: A string, the number to parse.

        Returns:
            The hextet as an integer.

        Raises:
            ValueError: if the input isn't strictly a hex number from
              [0..FFFF].


return (self.network_address.is_site_local and<EOL>self.broadcast_address.is_site_local)<EOL>

Test if the address is reserved for site-local.

        Note that the site-local address space has been deprecated by RFC 3879.
        Use is_private to test if this address is in the space of unique local
        addresses as defined by RFC 4193.

        Returns:
            A boolean, True if the address is reserved per RFC 3513 2.5.6.


def __init__(self, address, strict=True):

_BaseV4.__init__(self, address)<EOL>_BaseNetwork.__init__(self, address)<EOL>if isinstance(address, bytes):<EOL><INDENT>self.network_address = IPv4Address(address)<EOL>self._prefixlen = self._max_prefixlen<EOL>self.netmask = IPv4Address(self._ALL_ONES)<EOL>return<EOL><DEDENT>if isinstance(address, _compat_int_types):<EOL><INDENT>self.network_address = IPv4Address(address)<EOL>self._prefixlen = self._max_prefixlen<EOL>self.netmask = IPv4Address(self._ALL_ONES)<EOL>return<EOL><DEDENT>addr = _split_optional_netmask(address)<EOL>self.network_address = IPv4Address(self._ip_int_from_string(addr[<NUM_LIT:0>]))<EOL>if len(addr) == <NUM_LIT:2>:<EOL><INDENT>mask = addr[<NUM_LIT:1>].split('<STR_LIT:.>')<EOL>if len(mask) == <NUM_LIT:4>:<EOL><INDENT>if self._is_valid_netmask(addr[<NUM_LIT:1>]):<EOL><INDENT>self.netmask = IPv4Address(self._ip_int_from_string(<EOL>addr[<NUM_LIT:1>]))<EOL><DEDENT>elif self._is_hostmask(addr[<NUM_LIT:1>]):<EOL><INDENT>self.netmask = IPv4Address(<EOL>self._ip_int_from_string(addr[<NUM_LIT:1>]) ^ self._ALL_ONES)<EOL><DEDENT>else:<EOL><INDENT>raise NetmaskValueError('<STR_LIT>'<EOL>% addr[<NUM_LIT:1>])<EOL><DEDENT>self._prefixlen = self._prefix_from_ip_int(int(self.netmask))<EOL><DEDENT>else:<EOL><INDENT>if not self._is_valid_netmask(addr[<NUM_LIT:1>]):<EOL><INDENT>raise NetmaskValueError('<STR_LIT>'<EOL>% addr[<NUM_LIT:1>])<EOL><DEDENT>self._prefixlen = int(addr[<NUM_LIT:1>])<EOL>self.netmask = IPv4Address(self._ip_int_from_prefix(<EOL>self._prefixlen))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>self._prefixlen = self._max_prefixlen<EOL>self.netmask = IPv4Address(self._ip_int_from_prefix(<EOL>self._prefixlen))<EOL><DEDENT>if strict:<EOL><INDENT>if (IPv4Address(int(self.network_address) & int(self.netmask)) !=<EOL>self.network_address):<EOL><INDENT>raise ValueError('<STR_LIT>' % self)<EOL><DEDENT><DEDENT>self.network_address = IPv4Address(int(self.network_address) &<EOL>int(self.netmask))<EOL>if self._prefixlen == (self._max_prefixlen - <NUM_LIT:1>):<EOL><INDENT>self.hosts = self.__iter__<EOL><DEDENT>

Instantiate a new IPv4 network object.

        Args:
            address: A string or integer representing the IP [& network].
              '192.0.2.0/24'
              '192.0.2.0/255.255.255.0'
              '192.0.0.2/0.0.0.255'
              are all functionally the same in IPv4. Similarly,
              '192.0.2.1'
              '192.0.2.1/255.255.255.255'
              '192.0.2.1/32'
              are also functionaly equivalent. That is to say, failing to
              provide a subnetmask will create an object with a mask of /32.

              If the mask (portion after the / in the argument) is given in
              dotted quad form, it is treated as a netmask if it starts with a
              non-zero field (e.g. /255.0.0.0 == /8) and as a hostmask if it
              starts with a zero field (e.g. 0.255.255.255 == /8), with the
              single exception of an all-zero mask which is treated as a
              netmask == /0. If no mask is given, a default of /32 is used.

              Additionally, an integer can be passed, so
              IPv4Network('192.0.2.1') == IPv4Network(3221225985)
              or, more generally
              IPv4Interface(int(IPv4Interface('192.0.2.1'))) ==
                IPv4Interface('192.0.2.1')

        Raises:
            AddressValueError: If ipaddress isn't a valid IPv4 address.
            NetmaskValueError: If the netmask isn't valid for
              an IPv4 address.
            ValueError: If strict is True and a network address is not
              supplied.


return (self.network_address.is_loopback and<EOL>self.broadcast_address.is_loopback)<EOL>

Test if the address is a loopback address.

        Returns:
            A boolean, True if the address is a loopback address as defined in
            RFC 2373 2.5.3.


if isinstance(self, IPv6Network):<EOL><INDENT>ip_str = _compat_str(self.network_address)<EOL><DEDENT>elif isinstance(self, IPv6Interface):<EOL><INDENT>ip_str = _compat_str(self.ip)<EOL><DEDENT>else:<EOL><INDENT>ip_str = _compat_str(self)<EOL><DEDENT>ip_int = self._ip_int_from_string(ip_str)<EOL>hex_str = '<STR_LIT>' % ip_int<EOL>parts = [hex_str[x:x + <NUM_LIT:4>] for x in range(<NUM_LIT:0>, <NUM_LIT:32>, <NUM_LIT:4>)]<EOL>if isinstance(self, (_BaseNetwork, IPv6Interface)):<EOL><INDENT>return '<STR_LIT>' % ('<STR_LIT::>'.join(parts), self._prefixlen)<EOL><DEDENT>return '<STR_LIT::>'.join(parts)<EOL>

Expand a shortened IPv6 address.

        Args:
            ip_str: A string, the IPv6 address.

        Returns:
            A string, the expanded IPv6 address.


i = <NUM_LIT:0><EOL>addrs = []<EOL>ips = []<EOL>nets = []<EOL>for ip in addresses:<EOL><INDENT>if isinstance(ip, _BaseAddress):<EOL><INDENT>if ips and ips[-<NUM_LIT:1>]._version != ip._version:<EOL><INDENT>raise TypeError("<STR_LIT>" % (<EOL>ip, ips[-<NUM_LIT:1>]))<EOL><DEDENT>ips.append(ip)<EOL><DEDENT>elif ip._prefixlen == ip._max_prefixlen:<EOL><INDENT>if ips and ips[-<NUM_LIT:1>]._version != ip._version:<EOL><INDENT>raise TypeError("<STR_LIT>" % (<EOL>ip, ips[-<NUM_LIT:1>]))<EOL><DEDENT>try:<EOL><INDENT>ips.append(ip.ip)<EOL><DEDENT>except AttributeError:<EOL><INDENT>ips.append(ip.network_address)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if nets and nets[-<NUM_LIT:1>]._version != ip._version:<EOL><INDENT>raise TypeError("<STR_LIT>" % (<EOL>ip, nets[-<NUM_LIT:1>]))<EOL><DEDENT>nets.append(ip)<EOL><DEDENT><DEDENT>ips = sorted(set(ips))<EOL>nets = sorted(set(nets))<EOL>while i < len(ips):<EOL><INDENT>(first, last) = _find_address_range(ips[i:])<EOL>i = ips.index(last) + <NUM_LIT:1><EOL>addrs.extend(summarize_address_range(first, last))<EOL><DEDENT>return iter(_collapse_addresses_recursive(sorted(<EOL>addrs + nets, key=_BaseNetwork._get_networks_key)))<EOL>

Collapse a list of IP objects.

    Example:
        collapse_addresses([IPv4Network('192.0.2.0/25'),
                            IPv4Network('192.0.2.128/25')]) ->
                           [IPv4Network('192.0.2.0/24')]

    Args:
        addresses: An iterator of IPv4Network or IPv6Network objects.

    Returns:
        An iterator of the collapsed IPv(4|6)Network objects.

    Raises:
        TypeError: If passed a list of mixed version objects.


try:<EOL><INDENT>prefixlen = int(prefixlen)<EOL><DEDENT>except ValueError:<EOL><INDENT>return False<EOL><DEDENT>return <NUM_LIT:0> <= prefixlen <= self._max_prefixlen<EOL>

Verify that the netmask/prefixlen is valid.

        Args:
            prefixlen: A string, the netmask in prefix length format.

        Returns:
            A boolean, True if the prefix represents a valid IPv6
            netmask.


def _format_option_strings(self, option, mvarfmt='<STR_LIT>', optsep='<STR_LIT:U+002CU+0020>'):

opts = []<EOL>if option._short_opts:<EOL><INDENT>opts.append(option._short_opts[<NUM_LIT:0>])<EOL><DEDENT>if option._long_opts:<EOL><INDENT>opts.append(option._long_opts[<NUM_LIT:0>])<EOL><DEDENT>if len(opts) > <NUM_LIT:1>:<EOL><INDENT>opts.insert(<NUM_LIT:1>, optsep)<EOL><DEDENT>if option.takes_value():<EOL><INDENT>metavar = option.metavar or option.dest.lower()<EOL>opts.append(mvarfmt % metavar.lower())<EOL><DEDENT>return '<STR_LIT>'.join(opts)<EOL>

Return a comma-separated list of option strings and metavars.

:param option:  tuple of (short opt, long opt), e.g: ('-f', '--format')
:param mvarfmt: metavar format string - evaluated as mvarfmt % metavar
:param optsep:  separator


for key, val in os.environ.items():<EOL><INDENT>if _environ_prefix_re.search(key):<EOL><INDENT>yield (_environ_prefix_re.sub("<STR_LIT>", key).lower(), val)<EOL><DEDENT><DEDENT>

Returns a generator with all environmental vars with prefix PIP_


<EOL>config = {}<EOL>for section in ('<STR_LIT>', self.name):<EOL><INDENT>config.update(<EOL>self.normalize_keys(self.get_config_section(section))<EOL>)<EOL><DEDENT>if not self.isolated:<EOL><INDENT>config.update(self.normalize_keys(self.get_environ_vars()))<EOL><DEDENT>for key, val in config.items():<EOL><INDENT>option = self.get_option(key)<EOL>if option is not None:<EOL><INDENT>if not val:<EOL><INDENT>continue<EOL><DEDENT>if option.action in ('<STR_LIT:store_true>', '<STR_LIT>', '<STR_LIT:count>'):<EOL><INDENT>val = strtobool(val)<EOL><DEDENT>if option.action == '<STR_LIT>':<EOL><INDENT>val = val.split()<EOL>val = [self.check_default(option, key, v) for v in val]<EOL><DEDENT>else:<EOL><INDENT>val = self.check_default(option, key, val)<EOL><DEDENT>defaults[option.dest] = val<EOL><DEDENT><DEDENT>return defaults<EOL>

Updates the given defaults with values from the config files and
        the environ. Does a little special handling for certain types of
        options (lists).


res = self.option_list[:]<EOL>for i in self.option_groups:<EOL><INDENT>res.extend(i.option_list)<EOL><DEDENT>return res<EOL>

Get a list of all options, including those in option groups.


<EOL>return distutils.util.get_platform().replace('<STR_LIT:.>', '<STR_LIT:_>').replace('<STR_LIT:->', '<STR_LIT:_>')<EOL>

Return our platform name 'win32', 'linux_x86_64


return '<STR_LIT>'.join(map(str, sys.version_info[:<NUM_LIT:2>]))<EOL>


return False<EOL>

Test for symbolic link.
    On WindowsNT/95 and OS/2 always returns false


if '<STR_LIT:$>' not in path and '<STR_LIT:%>' not in path:<EOL><INDENT>return path<EOL><DEDENT>import string<EOL>varchars = string.ascii_letters + string.digits + '<STR_LIT>'<EOL>if isinstance(path, _unicode):<EOL><INDENT>encoding = sys.getfilesystemencoding()<EOL>def getenv(var):<EOL><INDENT>return os.environ[var.encode(encoding)].decode(encoding)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>def getenv(var):<EOL><INDENT>return os.environ[var]<EOL><DEDENT><DEDENT>res = '<STR_LIT>'<EOL>index = <NUM_LIT:0><EOL>pathlen = len(path)<EOL>while index < pathlen:<EOL><INDENT>c = path[index]<EOL>if c == '<STR_LIT>':   <EOL><INDENT>path = path[index + <NUM_LIT:1>:]<EOL>pathlen = len(path)<EOL>try:<EOL><INDENT>index = path.index('<STR_LIT>')<EOL>res = res + '<STR_LIT>' + path[:index + <NUM_LIT:1>]<EOL><DEDENT>except ValueError:<EOL><INDENT>res = res + c + path<EOL>index = pathlen - <NUM_LIT:1><EOL><DEDENT><DEDENT>elif c == '<STR_LIT:%>':  <EOL><INDENT>if path[index + <NUM_LIT:1>:index + <NUM_LIT:2>] == '<STR_LIT:%>':<EOL><INDENT>res = res + c<EOL>index = index + <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>path = path[index+<NUM_LIT:1>:]<EOL>pathlen = len(path)<EOL>try:<EOL><INDENT>index = path.index('<STR_LIT:%>')<EOL><DEDENT>except ValueError:<EOL><INDENT>res = res + '<STR_LIT:%>' + path<EOL>index = pathlen - <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>var = path[:index]<EOL>try:<EOL><INDENT>res = res + getenv(var)<EOL><DEDENT>except KeyError:<EOL><INDENT>res = res + '<STR_LIT:%>' + var + '<STR_LIT:%>'<EOL><DEDENT><DEDENT><DEDENT><DEDENT>elif c == '<STR_LIT:$>':  <EOL><INDENT>if path[index + <NUM_LIT:1>:index + <NUM_LIT:2>] == '<STR_LIT:$>':<EOL><INDENT>res = res + c<EOL>index = index + <NUM_LIT:1><EOL><DEDENT>elif path[index + <NUM_LIT:1>:index + <NUM_LIT:2>] == '<STR_LIT:{>':<EOL><INDENT>path = path[index+<NUM_LIT:2>:]<EOL>pathlen = len(path)<EOL>try:<EOL><INDENT>index = path.index('<STR_LIT:}>')<EOL>var = path[:index]<EOL>try:<EOL><INDENT>res = res + getenv(var)<EOL><DEDENT>except KeyError:<EOL><INDENT>res = res + '<STR_LIT>' + var + '<STR_LIT:}>'<EOL><DEDENT><DEDENT>except ValueError:<EOL><INDENT>res = res + '<STR_LIT>' + path<EOL>index = pathlen - <NUM_LIT:1><EOL><DEDENT><DEDENT>else:<EOL><INDENT>var = '<STR_LIT>'<EOL>index = index + <NUM_LIT:1><EOL>c = path[index:index + <NUM_LIT:1>]<EOL>while c != '<STR_LIT>' and c in varchars:<EOL><INDENT>var = var + c<EOL>index = index + <NUM_LIT:1><EOL>c = path[index:index + <NUM_LIT:1>]<EOL><DEDENT>try:<EOL><INDENT>res = res + getenv(var)<EOL><DEDENT>except KeyError:<EOL><INDENT>res = res + '<STR_LIT:$>' + var<EOL><DEDENT>if c != '<STR_LIT>':<EOL><INDENT>index = index - <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>res = res + c<EOL><DEDENT>index = index + <NUM_LIT:1><EOL><DEDENT>return res<EOL>

Expand shell variables of the forms $var, ${var} and %var%.

    Unknown variables are left unchanged.


if path[:<NUM_LIT:1>] != '<STR_LIT>':<EOL><INDENT>return path<EOL><DEDENT>i, n = <NUM_LIT:1>, len(path)<EOL>while i < n and path[i] not in '<STR_LIT>':<EOL><INDENT>i = i + <NUM_LIT:1><EOL><DEDENT>if '<STR_LIT>' in os.environ:<EOL><INDENT>userhome = os.environ['<STR_LIT>']<EOL><DEDENT>elif '<STR_LIT>' in os.environ:<EOL><INDENT>userhome = os.environ['<STR_LIT>']<EOL><DEDENT>elif not '<STR_LIT>' in os.environ:<EOL><INDENT>return path<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>drive = os.environ['<STR_LIT>']<EOL><DEDENT>except KeyError:<EOL><INDENT>drive = '<STR_LIT>'<EOL><DEDENT>userhome = join(drive, os.environ['<STR_LIT>'])<EOL><DEDENT>if i != <NUM_LIT:1>: <EOL><INDENT>userhome = join(dirname(userhome), path[<NUM_LIT:1>:i])<EOL><DEDENT>return userhome + path[i:]<EOL>

Expand ~ and ~user constructs.

    If user or $HOME is unknown, do nothing.


warnings.warnpy3k("<STR_LIT>",<EOL>stacklevel=<NUM_LIT:2>)<EOL>try:<EOL><INDENT>names = os.listdir(top)<EOL><DEDENT>except os.error:<EOL><INDENT>return<EOL><DEDENT>func(arg, top, names)<EOL>for name in names:<EOL><INDENT>name = join(top, name)<EOL>if isdir(name):<EOL><INDENT>walk(name, func, arg)<EOL><DEDENT><DEDENT>

Directory tree walk with callback function.

    For each directory in the directory tree rooted at top (including top
    itself, but excluding '.' and '..'), call func(arg, dirname, fnames).
    dirname is the name of the directory, and fnames a list of the names of
    the files and subdirectories in dirname (excluding '.' and '..').  func
    may modify the fnames list in-place (e.g. via del or slice assignment),
    and walk will only recurse into the subdirectories whose names remain in
    fnames; this can be used to implement a filter, or to impose a specific
    order of visiting.  No semantics are defined for, or required of, arg,
    beyond that arg is always passed to func.  It can be used, e.g., to pass
    a filename pattern, or a mutable object designed to accumulate
    statistics.  Passing None for arg is common.


return s.replace("<STR_LIT:/>", "<STR_LIT:\\>").lower()<EOL>

Normalize case of pathname.

    Makes all characters lowercase and all slashes into backslashes.


try:<EOL><INDENT>st = os.stat(s)<EOL><DEDENT>except os.error:<EOL><INDENT>return False<EOL><DEDENT>return stat.S_ISDIR(st.st_mode)<EOL>

Return true if the pathname refers to an existing directory.


return sum(<NUM_LIT:1> for v in self if v == value)<EOL>

S.count(value) -> integer -- return number of occurrences of value


return [self[key] for key in self]<EOL>


raise StopIteration<EOL>

Return the next item from the iterator. When exhausted, raise StopIteration


MAX = sys.maxint<EOL>MASK = <NUM_LIT:2> * MAX + <NUM_LIT:1><EOL>n = len(self)<EOL>h = <NUM_LIT> * (n + <NUM_LIT:1>)<EOL>h &= MASK<EOL>for x in self:<EOL><INDENT>hx = hash(x)<EOL>h ^= (hx ^ (hx << <NUM_LIT:16>) ^ <NUM_LIT>)  * <NUM_LIT><EOL>h &= MASK<EOL><DEDENT>h = h * <NUM_LIT> + <NUM_LIT><EOL>h &= MASK<EOL>if h > MAX:<EOL><INDENT>h -= MASK + <NUM_LIT:1><EOL><DEDENT>if h == -<NUM_LIT:1>:<EOL><INDENT>h = <NUM_LIT><EOL><DEDENT>return h<EOL>

Compute the hash value of a set.

        Note that we don't define __hash__: not all sets are hashable.
        But if you define a hashable set type, its __hash__ should
        call this function.

        This must be compatible __eq__.

        All sets ought to compare equal if they contain the same
        elements, regardless of how they are implemented, and
        regardless of the order of the elements; so there's not much
        freedom for __eq__ or __hash__.  We match the algorithm used
        by the built-in frozenset type.


return [(key, self[key]) for key in self]<EOL>

D.items() -> list of D's (key, value) pairs, as 2-tuples


try:<EOL><INDENT>while True:<EOL><INDENT>self.pop()<EOL><DEDENT><DEDENT>except KeyError:<EOL><INDENT>pass<EOL><DEDENT>

This is slow (creates N new iterators!) but effective.


for v in values:<EOL><INDENT>self.append(v)<EOL><DEDENT>

S.extend(iterable) -- extend sequence by appending elements from the iterable


for key in self:<EOL><INDENT>yield (key, self[key])<EOL><DEDENT>

D.iteritems() -> an iterator over the (key, value) items of D


if value not in self:<EOL><INDENT>raise KeyError(value)<EOL><DEDENT>self.discard(value)<EOL>

Remove an element. If not a member, raise a KeyError.


del self[self.index(value)]<EOL>

S.remove(value) -- remove first occurrence of value.
           Raise ValueError if the value is not present.


_cache.clear()<EOL>_cache_repl.clear()<EOL>


def sub(pattern, repl, string, count=<NUM_LIT:0>, flags=<NUM_LIT:0>):

return _compile(pattern, flags).sub(repl, string, count)<EOL>

Return the string obtained by replacing the leftmost
    non-overlapping occurrences of the pattern in string by the
    replacement repl.  repl can be either a string or a callable;
    if a string, backslash escapes in it are processed.  If it is
    a callable, it's passed the match object and must return
    a replacement string to be used.


def findall(pattern, string, flags=<NUM_LIT:0>):

return _compile(pattern, flags).findall(string)<EOL>

Return a list of all non-overlapping matches in the string.

    If one or more groups are present in the pattern, return a
    list of groups; this will be a list of tuples if the pattern
    has more than one group.

    Empty matches are included in the result.


def search(pattern, string, flags=<NUM_LIT:0>):

return _compile(pattern, flags).search(string)<EOL>

Scan through string looking for a match to the pattern, returning
    a match object, or None if no match was found.


def split(pattern, string, maxsplit=<NUM_LIT:0>, flags=<NUM_LIT:0>):

return _compile(pattern, flags).split(string, maxsplit)<EOL>

Split the source string by the occurrences of the pattern,
    returning a list containing the resulting substrings.


return _compile(pattern, flags|T)<EOL>

Compile a template pattern, returning a pattern object


def warn(message, category=None, stacklevel=<NUM_LIT:1>):

<EOL>if isinstance(message, Warning):<EOL><INDENT>category = message.__class__<EOL><DEDENT>if category is None:<EOL><INDENT>category = UserWarning<EOL><DEDENT>assert issubclass(category, Warning)<EOL>try:<EOL><INDENT>caller = sys._getframe(stacklevel)<EOL><DEDENT>except ValueError:<EOL><INDENT>globals = sys.__dict__<EOL>lineno = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>globals = caller.f_globals<EOL>lineno = caller.f_lineno<EOL><DEDENT>if '<STR_LIT>' in globals:<EOL><INDENT>module = globals['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>module = "<STR_LIT>"<EOL><DEDENT>filename = globals.get('<STR_LIT>')<EOL>if filename:<EOL><INDENT>fnl = filename.lower()<EOL>if fnl.endswith(("<STR_LIT>", "<STR_LIT>")):<EOL><INDENT>filename = filename[:-<NUM_LIT:1>]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if module == "<STR_LIT:__main__>":<EOL><INDENT>try:<EOL><INDENT>filename = sys.argv[<NUM_LIT:0>]<EOL><DEDENT>except AttributeError:<EOL><INDENT>filename = '<STR_LIT:__main__>'<EOL><DEDENT><DEDENT>if not filename:<EOL><INDENT>filename = module<EOL><DEDENT><DEDENT>registry = globals.setdefault("<STR_LIT>", {})<EOL>warn_explicit(message, category, filename, lineno, module, registry,<EOL>globals)<EOL>

Issue a warning, or maybe ignore it or raise an exception.


def formatwarning(message, category, filename, lineno, line=None):

try:<EOL><INDENT>unicodetype = str<EOL><DEDENT>except NameError:<EOL><INDENT>unicodetype = ()<EOL><DEDENT>try:<EOL><INDENT>message = str(message)<EOL><DEDENT>except UnicodeEncodeError:<EOL><INDENT>pass<EOL><DEDENT>s =  "<STR_LIT>" % (lineno, category.__name__, message)<EOL>line = linecache.getline(filename, lineno) if line is None else line<EOL>if line:<EOL><INDENT>line = line.strip()<EOL>if isinstance(s, unicodetype) and isinstance(line, str):<EOL><INDENT>line = str(line, '<STR_LIT>')<EOL><DEDENT>s += "<STR_LIT>" % line<EOL><DEDENT>if isinstance(s, unicodetype) and isinstance(filename, str):<EOL><INDENT>enc = sys.getfilesystemencoding()<EOL>if enc:<EOL><INDENT>try:<EOL><INDENT>filename = str(filename, enc)<EOL><DEDENT>except UnicodeDecodeError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT><DEDENT>s = "<STR_LIT>" % (filename, s)<EOL>return s<EOL>

Function to format a warning the standard way.


import os,posixpath<EOL>result=[]<EOL>pat=os.path.normcase(pat)<EOL>try:<EOL><INDENT>re_pat = _cache[pat]<EOL><DEDENT>except KeyError:<EOL><INDENT>res = translate(pat)<EOL>if len(_cache) >= _MAXCACHE:<EOL><INDENT>_cache.clear()<EOL><DEDENT>_cache[pat] = re_pat = re.compile(res)<EOL><DEDENT>match = re_pat.match<EOL>if os.path is posixpath:<EOL><INDENT>for name in names:<EOL><INDENT>if match(name):<EOL><INDENT>result.append(name)<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>for name in names:<EOL><INDENT>if match(os.path.normcase(name)):<EOL><INDENT>result.append(name)<EOL><DEDENT><DEDENT><DEDENT>return result<EOL>

Return the subset of the list NAMES that match PAT


if not val:<EOL><INDENT>return None<EOL><DEDENT>if not isinstance(val, six.string_types):<EOL><INDENT>if six.PY3 and isinstance(val, bytes):<EOL><INDENT>val = val.decode('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>val = str(val)<EOL><DEDENT><DEDENT>return {'<STR_LIT>': _prefix_score(val)}<EOL>

This is a basic case-sensitive "sorted order" index keygen function for
strings. This will return a value that is suitable to be used for ordering
by a 7-byte prefix of a string (that is 7 characters from a byte-string, and
1.75-7 characters from a unicode string, depending on character -> encoding
length).

.. warning:: Case sensitivity is based on the (encoded) byte prefixes of the
    strings/text being indexed, so ordering *may be different* than a native
    comparison ordering (especially if an order is different based on
    characters past the 7th encoded byte).


def flush(self, full=False, all=False, force=False):

self._init()<EOL>return self.save(*self.known.values(), full=full, all=all, force=force)<EOL>

Call ``.save()`` on all modified entities in the session. Use when you
want to flush changes to Redis, but don't want to lose your local
session cache.

See the ``.commit()`` method for arguments and their meanings.


return SIMPLE(val.lower())<EOL>

The same as SIMPLE, only case-insensitive.


def clean_old_index(model, block_size=<NUM_LIT:100>, **kwargs):

conn = _connect(model)<EOL>version = list(map(int, conn.info()['<STR_LIT>'].split('<STR_LIT:.>')[:<NUM_LIT:2>]))<EOL>has_hscan = version >= [<NUM_LIT:2>, <NUM_LIT:8>]<EOL>pipe = conn.pipeline(True)<EOL>prefix = '<STR_LIT>'%model._namespace<EOL>index = prefix + '<STR_LIT::>'<EOL>block_size = max(block_size, <NUM_LIT:10>)<EOL>force_hscan = kwargs.get('<STR_LIT>', False)<EOL>if (has_hscan or force_hscan) and force_hscan is not None:<EOL><INDENT>max_id = conn.hlen(index)<EOL>cursor = None<EOL>scanned = <NUM_LIT:0><EOL>while cursor != b'<STR_LIT:0>':<EOL><INDENT>cursor, remove = _scan_index_lua(conn, [index, prefix], [cursor or '<STR_LIT:0>', block_size, <NUM_LIT:0>, <NUM_LIT:0>])<EOL>if remove:<EOL><INDENT>_clean_index_lua(conn, [model._namespace], remove)<EOL><DEDENT>scanned += block_size<EOL>if scanned > max_id:<EOL><INDENT>max_id = scanned + <NUM_LIT:1><EOL><DEDENT>yield scanned, max_id<EOL><DEDENT>for uniq in chain(model._unique, model._cunique):<EOL><INDENT>name = uniq if isinstance(uniq, six.string_types) else '<STR_LIT::>'.join(uniq)<EOL>idx = prefix + name + '<STR_LIT>'<EOL>cursor = None<EOL>while cursor != b'<STR_LIT:0>':<EOL><INDENT>cursor, remove = _scan_index_lua(conn, [idx, prefix], [cursor or '<STR_LIT:0>', block_size, <NUM_LIT:1>, <NUM_LIT:0>])<EOL>if remove:<EOL><INDENT>conn.hdel(idx, *remove)<EOL><DEDENT>scanned += block_size<EOL>if scanned > max_id:<EOL><INDENT>max_id = scanned + <NUM_LIT:1><EOL><DEDENT>yield scanned, max_id<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>if model._unique or model._cunique:<EOL><INDENT>if has_hscan:<EOL><INDENT>warnings.warn("<STR_LIT>", stacklevel=<NUM_LIT:2>)<EOL><DEDENT>else:<EOL><INDENT>warnings.warn("<STR_LIT>", stacklevel=<NUM_LIT:2>)<EOL><DEDENT><DEDENT>max_id = int(conn.get('<STR_LIT>'%(prefix, model._pkey)) or '<STR_LIT:0>')<EOL>for i in range(<NUM_LIT:1>, max_id+<NUM_LIT:1>, block_size):<EOL><INDENT>ids = list(range(i, min(i+block_size, max_id+<NUM_LIT:1>)))<EOL>for id in ids:<EOL><INDENT>pipe.exists(prefix + str(id))<EOL>pipe.hexists(index, id)<EOL><DEDENT>result = iter(pipe.execute())<EOL>remove = [id for id, ent, ind in zip(ids, result, result) if ind and not ent]<EOL>if remove:<EOL><INDENT>_clean_index_lua(conn, [model._namespace], remove)<EOL><DEDENT>yield min(i+block_size, max_id-<NUM_LIT:1>), max_id<EOL><DEDENT><DEDENT>yield max_id, max_id<EOL>

This utility function will clean out old index data that was accidentally
left during item deletion in rom versions <= 0.27.0 . You should run this
after you have upgraded all of your clients to version 0.28.0 or later.

Arguments:

    * *model* - the model whose entities you want to reindex
    * *block_size* - the maximum number of items to check at a time
      defaulting to 100

This function will yield its progression through re-checking all of the
data that could be left over.

Example use::

    for progress, total in clean_old_index(MyModel, block_size=200):
        print "%s of %s"%(progress, total)


if isinstance(val, float):<EOL><INDENT>val = repr(val)<EOL><DEDENT>elif val in (None, '<STR_LIT>'):<EOL><INDENT>return None<EOL><DEDENT>elif not isinstance(val, six.string_types):<EOL><INDENT>if six.PY3 and isinstance(val, bytes):<EOL><INDENT>val = val.decode('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>val = str(val)<EOL><DEDENT><DEDENT>r = sorted(set([x for x in [s.lower().strip(string.punctuation) for s in val.split()] if x]))<EOL>if not isinstance(val, str):  <EOL><INDENT>return [s.encode('<STR_LIT:utf-8>') for s in r]<EOL><DEDENT>return r<EOL>

This is a basic full-text index keygen function. Words are lowercased, split
by whitespace, and stripped of punctuation from both ends before an inverted
index is created for term searching.


from rom import Model<EOL>full = kwargs.get('<STR_LIT>')<EOL>all = kwargs.get('<STR_LIT:all>')<EOL>force = kwargs.get('<STR_LIT>')<EOL>changes = <NUM_LIT:0><EOL>items = deque()<EOL>items.extend(objects)<EOL>while items:<EOL><INDENT>o = items.popleft()<EOL>if isinstance(o, (list, tuple)):<EOL><INDENT>items.extendleft(reversed(o))<EOL><DEDENT>elif isinstance(o, Model):<EOL><INDENT>if not o._deleted and (all or o._modified):<EOL><INDENT>changes += o.save(full, force)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise ORMError(<EOL>"<STR_LIT>"%(<EOL>o,))<EOL><DEDENT><DEDENT>return changes<EOL>

This method is an alternate API for saving many entities (possibly not
tracked by the session). You can call::

    session.save(obj)
    session.save(obj1, obj2, ...)
    session.save([obj1, obj2, ...])

And the entities will be flushed to Redis.

You can pass the keyword arguments ``full``, ``all``, and ``force`` with
the same meaning and semantics as the ``.commit()`` method.


self._init()<EOL>return self.known.get(pk) or self.wknown.get(pk)<EOL>

Fetches an entity from the session based on primary key.


if not val:<EOL><INDENT>return None<EOL><DEDENT>if not isinstance(val, six.string_types_ex):<EOL><INDENT>val = str(val)<EOL><DEDENT>return [val]<EOL>

This is a basic "equality" index keygen, primarily meant to be used for
things like::

    Model.query.filter(col='value')

Where ``FULL_TEXT`` would transform a sentence like "A Simple Sentence" into
an inverted index searchable by the words "a", "simple", and/or "sentence",
``IDENTITY`` will only be searchable by the orginal full sentence with the
same capitalization - "A Simple Sentence". See ``IDENTITY_CI`` for the
same function, only case-insensitive.


script = script.encode('<STR_LIT:utf-8>') if isinstance(script, six.text_type) else script<EOL>sha = [None, sha1(script).hexdigest()]<EOL>def call(conn, keys=[], args=[], force_eval=False):<EOL><INDENT>keys = tuple(keys)<EOL>args = tuple(args)<EOL>if not force_eval:<EOL><INDENT>if not sha[<NUM_LIT:0>]:<EOL><INDENT>try:<EOL><INDENT>return conn.execute_command(<EOL>'<STR_LIT>', script, len(keys), *(keys + args))<EOL><DEDENT>finally:<EOL><INDENT>del sha[:-<NUM_LIT:1>]<EOL><DEDENT><DEDENT>try:<EOL><INDENT>return conn.execute_command(<EOL>"<STR_LIT>", sha[<NUM_LIT:0>], len(keys), *(keys+args))<EOL><DEDENT>except redis.exceptions.ResponseError as msg:<EOL><INDENT>if not any(msg.args[<NUM_LIT:0>].startswith(nsm) for nsm in NO_SCRIPT_MESSAGES):<EOL><INDENT>raise<EOL><DEDENT><DEDENT><DEDENT>return conn.execute_command(<EOL>"<STR_LIT>", script, len(keys), *(keys+args))<EOL><DEDENT>return call<EOL>

Borrowed/modified from my book, Redis in Action:
https://github.com/josiahcarlson/redis-in-action/blob/master/python/ch11_listing_source.py

Used for Lua scripting support when writing against Redis 2.6+ to allow
for multiple unique columns per model.


return Query(cls)<EOL>

Returns a ``Query`` object that refers to this model to handle
subsequent filtering.


def redis_prefix_lua(conn, dest, index, prefix, is_first, pattern=None):

tkey = '<STR_LIT>'%(index.partition('<STR_LIT::>')[<NUM_LIT:0>], uuid.uuid4())<EOL>start, end = _start_end(prefix)<EOL>return _redis_prefix_lua(conn,<EOL>[dest, tkey, index],<EOL>[start, end, pattern or prefix, int(pattern is not None), int(bool(is_first))]<EOL>)<EOL>

Performs the actual prefix, suffix, and pattern match operations.


pipe, intersect, temp_id = self._prepare(conn, filters)<EOL>pipe.zcard(temp_id)<EOL>pipe.delete(temp_id)<EOL>return pipe.execute()[-<NUM_LIT:2>]<EOL>

Returns the count of the items that match the provided filters.

For the meaning of what the ``filters`` argument means, see the
``.search()`` method docs.


return self.execute()<EOL>


new = []<EOL>for k, v in kwargs.items():<EOL><INDENT>v = self._check(k, v, '<STR_LIT>')<EOL>new.append(Pattern(k, v))<EOL><DEDENT>return self.replace(filters=self._filters+tuple(new))<EOL>

When provided with keyword arguments of the form ``col=pattern``, this
will limit the entities returned to those that include the provided
pattern. Note that 'like' queries require that the ``prefix=True``
option must have been provided as part of the column definition.

Patterns allow for 4 wildcard characters, whose semantics are as
follows:

    * *?* - will match 0 or 1 of any character
    * *\** - will match 0 or more of any character
    * *+* - will match 1 or more of any character
    * *!* - will match exactly 1 of any character

As an example, imagine that you have enabled the required prefix
matching on your ``User.email`` column. And lets say that you want to
find everyone with an email address that contains the name 'frank'
before the ``@`` sign. You can use either of the following patterns
to discover those users.

    * *\*frank\*@*
    * *\*frank\*@*

.. note:: Like queries implicitly start at the beginning of strings
  checked, so if you want to match a pattern that doesn't start at
  the beginning of a string, you should prefix it with one of the
  wildcard characters (like ``*`` as we did with the 'frank' pattern).


def GetParam(tag, param, default=__SENTINEL):

if tag.HasParam(param):<EOL><INDENT>return tag.GetParam(param)<EOL><DEDENT>else:<EOL><INDENT>if default == __SENTINEL:<EOL><INDENT>raise KeyError<EOL><DEDENT>else:<EOL><INDENT>return default<EOL><DEDENT><DEDENT>

Convenience function for accessing tag parameters


ret = {}<EOL>for k, v in bg.items():<EOL><INDENT>if k == '<STR_LIT:type>':<EOL><INDENT>v = WIN_MAP[v]._meta.name<EOL><DEDENT>elif k == '<STR_LIT>':<EOL><INDENT>menus = v['<STR_LIT>']<EOL>v = [migrate_control(menu) for menu in menus]<EOL><DEDENT>elif k == '<STR_LIT>':<EOL><INDENT>v = [migrate_control(comp) for comp in v]<EOL><DEDENT>else:<EOL><INDENT>k = SPEC_MAP['<STR_LIT>'].get(k, k)<EOL><DEDENT>ret[k] = v<EOL><DEDENT>return ret<EOL>

Take a pythoncard background resource and convert to a gui2py window


<EOL>child = self.tree.FindItem(self.root, kwargs['<STR_LIT:name>'])<EOL>if DEBUG: print("<STR_LIT>", child, kwargs)<EOL>if child:<EOL><INDENT>self.tree.ScrollTo(child)<EOL>self.tree.SetCurrentItem(child)<EOL>self.tree.SelectItem(child)<EOL>child.Selected = True<EOL>self.tree.SetItemText(child, obj.name, <NUM_LIT:0>)<EOL><DEDENT>

Update the tree item when the object name changes


def activate_item(self, child, edit_prop=False, select=False):

d = self.tree.GetItemData(child)<EOL>if d:<EOL><INDENT>o = d.GetData()<EOL>self.selected_obj = o<EOL>callback = lambda o=o, **kwargs: self.update(o, **kwargs)<EOL>self.propeditor.load_object(o, callback)<EOL>if edit_prop:<EOL><INDENT>wx.CallAfter(self.propeditor.edit)<EOL><DEDENT>if select and self.designer:<EOL><INDENT>self.designer.select(o)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>self.selected_obj = None<EOL><DEDENT>

load the selected item in the property editor


def show_context_menu(self, item, mouse_pos=None):

if item:<EOL><INDENT>d = self.tree.GetItemData(item)<EOL>if d:<EOL><INDENT>obj = d.GetData()<EOL>if obj:<EOL><INDENT>self.highlight(obj.wx_obj)<EOL>self.obj = obj<EOL>menu = wx.Menu()<EOL>id_del, id_dup, id_raise, id_lower = [wx.NewId() for i<EOL>in range(<NUM_LIT:4>)]<EOL>menu.Append(id_del, "<STR_LIT>")<EOL>menu.Append(id_dup, "<STR_LIT>")<EOL>menu.Append(id_raise, "<STR_LIT>")<EOL>menu.Append(id_lower, "<STR_LIT>")<EOL>sm = wx.Menu()<EOL>for ctrl in sorted(obj._meta.valid_children,<EOL>key=lambda c: <EOL>registry.ALL.index(c._meta.name)):<EOL><INDENT>new_id = wx.NewId()<EOL>sm.Append(new_id, ctrl._meta.name)<EOL>self.Bind(wx.EVT_MENU, <EOL>lambda evt, ctrl=ctrl: self.add_child(ctrl, mouse_pos), <EOL>id=new_id)<EOL><DEDENT>menu.AppendMenu(wx.NewId(), "<STR_LIT>", sm)<EOL>self.Bind(wx.EVT_MENU, self.delete, id=id_del)<EOL>self.Bind(wx.EVT_MENU, self.duplicate, id=id_dup)<EOL>self.Bind(wx.EVT_MENU, self.bring_to_front, id=id_raise)<EOL>self.Bind(wx.EVT_MENU, self.send_to_back, id=id_lower)<EOL>self.PopupMenu(menu)<EOL>menu.Destroy()<EOL>self.load_object(self.root_obj)<EOL><DEDENT><DEDENT><DEDENT>

Open a popup menu with options regarding the selected object


def set_default_tlw(self, tlw, designer, inspector):

self.designer = designer<EOL>self.inspector = inspector<EOL>

track default top level window for toolbox menu default action


<EOL>ok = gui.confirm("<STR_LIT>", "<STR_LIT>", <EOL>cancel=True, default=True)<EOL>if ok:<EOL><INDENT>wx_obj = evt.GetEventObject()<EOL>w = wx_obj.obj<EOL>try:<EOL><INDENT>if DEBUG: print("<STR_LIT>")<EOL>fin = open(designer.filename, "<STR_LIT:r>")<EOL>fout = open(designer.filename + "<STR_LIT>", "<STR_LIT:w>")<EOL>fout.write(fin.read())<EOL>fout.close()<EOL>fin.close()<EOL>if designer.filename.endswith("<STR_LIT>"):<EOL><INDENT>gui.save(designer.filename, [gui.dump(w)])<EOL><DEDENT>else:<EOL><INDENT>fin = open(designer.filename + "<STR_LIT>", "<STR_LIT:r>")<EOL>fout = open(designer.filename, "<STR_LIT:w>")<EOL>copy = True<EOL>newlines = fin.newlines or "<STR_LIT:\n>"<EOL>def dump(obj, indent=<NUM_LIT:1>):<EOL><INDENT>"<STR_LIT>"<EOL>for ctl in obj[:]:<EOL><INDENT>write(ctl, indent)<EOL><DEDENT><DEDENT>def write(ctl, indent):<EOL><INDENT>if ctl[:]:<EOL><INDENT>fout.write("<STR_LIT:U+0020>" * indent * <NUM_LIT:4>)<EOL>fout.write("<STR_LIT>" % ctl.__repr__(parent=None, indent=indent, context=True))<EOL>fout.write(newlines)<EOL>dump(ctl, indent + <NUM_LIT:1>)                <EOL><DEDENT>else:<EOL><INDENT>fout.write("<STR_LIT:U+0020>" * indent * <NUM_LIT:4>)<EOL>fout.write(ctl.__repr__(parent=None, indent=indent))<EOL>fout.write(newlines)<EOL><DEDENT><DEDENT>dumped = False<EOL>for line in fin:<EOL><INDENT>if line.startswith("<STR_LIT>"):<EOL><INDENT>fout.write(line)<EOL>fout.write(newlines)<EOL>write(w, indent=<NUM_LIT:0>)<EOL>fout.write(newlines)<EOL>dumped = True<EOL>copy = False<EOL><DEDENT>if line.startswith("<STR_LIT>"):<EOL><INDENT>copy = True<EOL><DEDENT>if copy:<EOL><INDENT>fout.write(line)<EOL><DEDENT><DEDENT>if not dumped:<EOL><INDENT>gui.alert("<STR_LIT>"<EOL>"<STR_LIT>", <EOL>"<STR_LIT>")<EOL><DEDENT><DEDENT>fout.close()<EOL>fin.close()<EOL><DEDENT>except Exception as e:<EOL><INDENT>import traceback<EOL>print((traceback.print_exc()))<EOL>ok = gui.confirm("<STR_LIT>" % str(e), '<STR_LIT>', <EOL>ok=True, cancel=True)<EOL><DEDENT><DEDENT>if ok is not None:<EOL><INDENT>wx.CallAfter(exit)    <EOL><DEDENT>return ok                 <EOL>

Basic save functionality: just replaces the gui code


<EOL>new_selection = []<EOL>for obj in self.selection:<EOL><INDENT>if obj:<EOL><INDENT>if DEBUG: print("<STR_LIT>", obj.name)<EOL>obj.sel_marker.destroy()<EOL>obj.sel_marker = None<EOL>obj2 = obj.duplicate()<EOL>obj2.sel_marker = SelectionMarker(obj2)<EOL>obj2.sel_marker.show(True)<EOL>new_selection.append(obj2)<EOL><DEDENT><DEDENT>self.selection = new_selection              <EOL>self.inspector.load_object()                <EOL>


def do_resize(self, evt, wx_obj, xxx_todo_changeme):

(n, w, s, e) = xxx_todo_changeme<EOL>pos = wx_obj.ScreenToClient(wx.GetMousePosition())<EOL>x, y = pos<EOL>if evt.ShiftDown():     <EOL><INDENT>x = x / GRID_SIZE[<NUM_LIT:0>] * GRID_SIZE[<NUM_LIT:0>]<EOL>y = y / GRID_SIZE[<NUM_LIT:1>] * GRID_SIZE[<NUM_LIT:1>]<EOL><DEDENT>pos = wx.Point(x, y)<EOL>if not self.resizing or self.resizing != (wx_obj, (n, w, s, e)):<EOL><INDENT>self.pos = list(pos)                        <EOL>self.resizing = (wx_obj, (n, w, s, e))      <EOL><DEDENT>else:<EOL><INDENT>delta = pos - self.pos <EOL>if DEBUG: print("<STR_LIT>", n, w, s, e)<EOL>if n or w or s or e:<EOL><INDENT>x = wx_obj.Position[<NUM_LIT:0>] + e * delta[<NUM_LIT:0>]<EOL>y = wx_obj.Position[<NUM_LIT:1>] + n * delta[<NUM_LIT:1>]<EOL>if w or e:<EOL><INDENT>if not isinstance(wx_obj, wx.TopLevelWindow):<EOL><INDENT>width = wx_obj.Size[<NUM_LIT:0>] + (w - e) * delta[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>width = wx_obj.ClientSize[<NUM_LIT:0>] + (w - e) * delta[<NUM_LIT:0>]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>width = None<EOL><DEDENT>if n or s:<EOL><INDENT>height = wx_obj.Size[<NUM_LIT:1>] + (s - n) * delta[<NUM_LIT:1>]<EOL><DEDENT>else:<EOL><INDENT>height = None<EOL><DEDENT><DEDENT>else:<EOL><INDENT>x = wx_obj.Position[<NUM_LIT:0>] + delta[<NUM_LIT:0>]<EOL>y = wx_obj.Position[<NUM_LIT:1>] + delta[<NUM_LIT:1>]<EOL>width = height = None<EOL><DEDENT>new_pos = (x, y)<EOL>new_size = (width, height)<EOL>if new_size != wx_obj.GetSize() or new_pos != wx_obj.GetPosition():<EOL><INDENT>wx_obj.obj.margin_left = <NUM_LIT:0><EOL>wx_obj.obj.margin_right = <NUM_LIT:0><EOL>wx_obj.obj.margin_top = <NUM_LIT:0><EOL>wx_obj.obj.margin_bottom = <NUM_LIT:0><EOL>wx_obj.obj.pos = new_pos      <EOL>if width is not None and height is not None:<EOL><INDENT>wx_obj.obj.width = width<EOL>wx_obj.obj.height = height<EOL><DEDENT>elif width is not None:<EOL><INDENT>wx_obj.obj.width = width<EOL><DEDENT>elif height is not None:<EOL><INDENT>wx_obj.obj.height = height<EOL><DEDENT>if w:<EOL><INDENT>self.pos[<NUM_LIT:0>] = pos[<NUM_LIT:0>]        <EOL><DEDENT>if s:<EOL><INDENT>self.pos[<NUM_LIT:1>] = pos[<NUM_LIT:1>]        <EOL><DEDENT><DEDENT><DEDENT>


def set_parent(self, new_parent, init=False):

<EOL>self.wx_obj.SetOwner(new_parent.wx_obj.GetEventHandler())<EOL>

Re-parent a child control with the new wx_obj parent (owner)


<EOL>if not controller or isinstance(controller, dict):<EOL><INDENT>if not controller:<EOL><INDENT>controller = util.get_caller_module_dict()<EOL><DEDENT>controller_name = controller['<STR_LIT>']<EOL>controller_dict = controller<EOL><DEDENT>else:<EOL><INDENT>controller_name = controller.__class__.__name__<EOL>controller_dict = dict([(k, getattr(controller, k)) for k <EOL>in dir(controller) if k.startswith("<STR_LIT>")])<EOL><DEDENT>for fn in [n for n in controller_dict if n.startswith("<STR_LIT>")]:<EOL><INDENT>names = fn.split("<STR_LIT:_>")<EOL>event_name = names.pop(<NUM_LIT:0>) + names.pop(-<NUM_LIT:1>)<EOL>obj = component<EOL>for name in names:<EOL><INDENT>try:<EOL><INDENT>obj = obj[name]<EOL><DEDENT>except KeyError:<EOL><INDENT>obj = None<EOL>break<EOL><DEDENT><DEDENT>if not obj:<EOL><INDENT>from .component import COMPONENTS<EOL>for key, obj in list(COMPONENTS.items()):<EOL><INDENT>if obj.name == name:<EOL><INDENT>print("<STR_LIT>" % (name, key.replace("<STR_LIT:.>", "<STR_LIT:_>")))<EOL>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise NameError("<STR_LIT>" % <EOL>(name, controller_name, fn))<EOL><DEDENT><DEDENT>if event_name in PYTHONCARD_EVENT_MAP:<EOL><INDENT>new_name = PYTHONCARD_EVENT_MAP[event_name]<EOL>print("<STR_LIT>" % (event_name, new_name, fn))<EOL>event_name = new_name<EOL><DEDENT>if not hasattr(obj, event_name):<EOL><INDENT>raise NameError("<STR_LIT>" % <EOL>(event_name, controller_name, fn))<EOL><DEDENT>setattr(obj, event_name, controller_dict[fn])<EOL><DEDENT>


s = pprint.pformat(rsrc)<EOL>open(filename, "<STR_LIT:w>").write(s)<EOL>


<EOL>s = open(filename).read()<EOL>import datetime, decimal<EOL>rsrc = eval(s)<EOL>return rsrc<EOL>

Open, read and eval the resource from the source file


if icon is not None:<EOL><INDENT>try:<EOL><INDENT>wx_icon = wx.Icon(icon, wx.BITMAP_TYPE_ICO)<EOL>self.wx_obj.SetIcon(wx_icon)<EOL><DEDENT>except:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>


env = self.state.document.settings.env<EOL>prefixes = get_import_prefixes_from_env(env)<EOL>items = []<EOL>max_item_chars = <NUM_LIT:50><EOL>for name in names:<EOL><INDENT>display_name = name<EOL>if name.startswith('<STR_LIT>'):<EOL><INDENT>name = name[<NUM_LIT:1>:]<EOL>display_name = name.split('<STR_LIT:.>')[-<NUM_LIT:1>]<EOL><DEDENT>try:<EOL><INDENT>real_name, obj, parent = import_by_name(name, prefixes=prefixes)<EOL><DEDENT>except ImportError:<EOL><INDENT>self.warn('<STR_LIT>' % name)<EOL>items.append((name, '<STR_LIT>', '<STR_LIT>', name))<EOL>continue<EOL><DEDENT>documenter = get_documenter(obj, parent)(self, real_name)<EOL>if not documenter.parse_name():<EOL><INDENT>self.warn('<STR_LIT>' % real_name)<EOL>items.append((display_name, '<STR_LIT>', '<STR_LIT>', real_name))<EOL>continue<EOL><DEDENT>if not documenter.import_object():<EOL><INDENT>self.warn('<STR_LIT>' % real_name)<EOL>items.append((display_name, '<STR_LIT>', '<STR_LIT>', real_name))<EOL>continue<EOL><DEDENT>sig = documenter.format_signature()<EOL>if not sig:<EOL><INDENT>sig = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>max_chars = max(<NUM_LIT:10>, max_item_chars - len(display_name))<EOL>sig = mangle_signature(sig, max_chars=max_chars)<EOL>sig = sig.replace('<STR_LIT:*>', r'<STR_LIT>')<EOL><DEDENT>doc = list(documenter.process_doc(documenter.get_doc()))<EOL>while doc and not doc[<NUM_LIT:0>].strip():<EOL><INDENT>doc.pop(<NUM_LIT:0>)<EOL><DEDENT>m = re.search(r"<STR_LIT>", "<STR_LIT:U+0020>".join(doc).strip())<EOL>if m:<EOL><INDENT>summary = m.group(<NUM_LIT:1>).strip()<EOL><DEDENT>elif doc:<EOL><INDENT>summary = doc[<NUM_LIT:0>].strip()<EOL><DEDENT>else:<EOL><INDENT>summary = '<STR_LIT>'<EOL><DEDENT>items.append((display_name, sig, summary, real_name))<EOL><DEDENT>return items<EOL>

Try to import the given names, and return a list of
        ``[(name, signature, summary_string, real_name), ...]``.


try:<EOL><INDENT>tbody = node[<NUM_LIT:0>][<NUM_LIT:0>][-<NUM_LIT:1>]<EOL>for row in tbody:<EOL><INDENT>col1_entry = row[<NUM_LIT:0>]<EOL>par = col1_entry[<NUM_LIT:0>]<EOL>for j, subnode in enumerate(list(par)):<EOL><INDENT>if isinstance(subnode, nodes.Text):<EOL><INDENT>new_text = str(subnode.astext())<EOL>new_text = new_text.replace("<STR_LIT:U+0020>", "<STR_LIT>")<EOL>par[j] = nodes.Text(new_text)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>except IndexError:<EOL><INDENT>pass<EOL><DEDENT>

Make the first column of the table non-breaking.


s = re.sub(r"<STR_LIT>", r"<STR_LIT>", sig).strip()<EOL>s = re.sub(r"<STR_LIT>", "<STR_LIT>", s)<EOL>s = re.sub(r"<STR_LIT>", "<STR_LIT>", s)<EOL>s = re.sub(r"<STR_LIT>", "<STR_LIT>", s)<EOL>args = []<EOL>opts = []<EOL>opt_re = re.compile(r"<STR_LIT>")<EOL>while s:<EOL><INDENT>m = opt_re.search(s)<EOL>if not m:<EOL><INDENT>args = s.split('<STR_LIT:U+002CU+0020>')<EOL>break<EOL><DEDENT>opts.insert(<NUM_LIT:0>, m.group(<NUM_LIT:2>))<EOL>s = m.group(<NUM_LIT:1>)[:-<NUM_LIT:2>]<EOL><DEDENT>sig = limited_join("<STR_LIT:U+002CU+0020>", args, max_chars=max_chars-<NUM_LIT:2>)<EOL>if opts:<EOL><INDENT>if not sig:<EOL><INDENT>sig = "<STR_LIT>" % limited_join("<STR_LIT:U+002CU+0020>", opts, max_chars=max_chars-<NUM_LIT:4>)<EOL><DEDENT>elif len(sig) < max_chars - <NUM_LIT:4> - <NUM_LIT:2> - <NUM_LIT:3>:<EOL><INDENT>sig += "<STR_LIT>" % limited_join("<STR_LIT:U+002CU+0020>", opts,<EOL>max_chars=max_chars-len(sig)-<NUM_LIT:4>-<NUM_LIT:2>)<EOL><DEDENT><DEDENT>return "<STR_LIT>" % sig<EOL>

Reformat a function signature to a more compact form.


def autolink_role(typ, rawtext, etext, lineno, inliner,<EOL>options={}, content=[]):

env = inliner.document.settings.env<EOL>r = env.get_domain('<STR_LIT>').role('<STR_LIT>')(<EOL>'<STR_LIT>', rawtext, etext, lineno, inliner, options, content)<EOL>pnode = r[<NUM_LIT:0>][<NUM_LIT:0>]<EOL>prefixes = get_import_prefixes_from_env(env)<EOL>try:<EOL><INDENT>name, obj, parent = import_by_name(pnode['<STR_LIT>'], prefixes)<EOL><DEDENT>except ImportError:<EOL><INDENT>content = pnode[<NUM_LIT:0>]<EOL>r[<NUM_LIT:0>][<NUM_LIT:0>] = nodes.emphasis(rawtext, content[<NUM_LIT:0>].astext(),<EOL>classes=content['<STR_LIT>'])<EOL><DEDENT>return r<EOL>

Smart linking role.

    Expands to ':obj:`text`' if `text` is an object that can be imported;
    otherwise expands to '*text*'.


env = app.builder.env<EOL>crawled = {}<EOL>def crawl_toc(node, depth=<NUM_LIT:1>):<EOL><INDENT>crawled[node] = True<EOL>for j, subnode in enumerate(node):<EOL><INDENT>try:<EOL><INDENT>if (isinstance(subnode, autosummary_toc)<EOL>and isinstance(subnode[<NUM_LIT:0>], addnodes.toctree)):<EOL><INDENT>env.note_toctree(env.docname, subnode[<NUM_LIT:0>])<EOL>continue<EOL><DEDENT><DEDENT>except IndexError:<EOL><INDENT>continue<EOL><DEDENT>if not isinstance(subnode, nodes.section):<EOL><INDENT>continue<EOL><DEDENT>if subnode not in crawled:<EOL><INDENT>crawl_toc(subnode, depth+<NUM_LIT:1>)<EOL><DEDENT><DEDENT><DEDENT>crawl_toc(doctree)<EOL>

Insert items described in autosummary:: to the TOC tree, but do
    not generate the toctree:: list.


INITPY = '<STR_LIT>'<EOL>rootpath = os.path.normpath(os.path.abspath(rootpath))<EOL>if INITPY in os.listdir(rootpath):<EOL><INDENT>root_package = rootpath.split(os.path.sep)[-<NUM_LIT:1>]<EOL>print("<STR_LIT>", rootpath)<EOL><DEDENT>else:<EOL><INDENT>print("<STR_LIT>", rootpath)<EOL>return<EOL><DEDENT>def makename(package, module):<EOL><INDENT>"""<STR_LIT>"""<EOL>if package:<EOL><INDENT>name = package<EOL>if module:<EOL><INDENT>name += '<STR_LIT:.>' + module<EOL><DEDENT><DEDENT>else:<EOL><INDENT>name = module<EOL><DEDENT>return name<EOL><DEDENT>skipall = []<EOL>for m in list(skip.keys()):<EOL><INDENT>if skip[m] is None: skipall.append(m)<EOL><DEDENT>tree = {}<EOL>saved = <NUM_LIT:0><EOL>found = <NUM_LIT:0><EOL>def save(module, submodule):<EOL><INDENT>name = module+ "<STR_LIT:.>"+ submodule<EOL>for s in skipall:<EOL><INDENT>if name.startswith(s):<EOL><INDENT>print("<STR_LIT>"+name)<EOL>return False<EOL><DEDENT><DEDENT>if module in skip:<EOL><INDENT>if submodule in skip[module]:<EOL><INDENT>print("<STR_LIT>"+name)<EOL>return False<EOL><DEDENT><DEDENT>if module not in tree:<EOL><INDENT>tree[module] = []<EOL><DEDENT>tree[module].append(submodule)<EOL>return True<EOL><DEDENT>for root, subs, files in os.walk(rootpath):<EOL><INDENT>py_files = sorted([f for f in files if os.path.splitext(f)[<NUM_LIT:1>] == '<STR_LIT>'])<EOL>if INITPY in py_files:<EOL><INDENT>subpackage = root[len(rootpath):].lstrip(os.path.sep).replace(os.path.sep, '<STR_LIT:.>')<EOL>full = makename(root_package, subpackage)<EOL>part = full.rpartition('<STR_LIT:.>')<EOL>base_package, submodule = part[<NUM_LIT:0>], part[<NUM_LIT:2>]<EOL>found += <NUM_LIT:1><EOL>if save(base_package, submodule): saved += <NUM_LIT:1><EOL>py_files.remove(INITPY)    <EOL>for py_file in py_files:<EOL><INDENT>found += <NUM_LIT:1><EOL>module = os.path.splitext(py_file)[<NUM_LIT:0>]<EOL>if save(full, module): saved += <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>for item in list(tree.keys()):<EOL><INDENT>tree[item].sort()<EOL><DEDENT>print("<STR_LIT>" %(root_package, found, found-saved))<EOL>return tree<EOL>

Look for every file in the directory tree and return a dict
Hacked from sphinx.autodoc


for it in self:<EOL><INDENT>found = it.find(item_id)<EOL>if found:<EOL><INDENT>return found<EOL><DEDENT><DEDENT>

Recursively find a menu item by its id (useful for event handlers)


for i in range(self.GetMenuCount()):<EOL><INDENT>if not self.IsEnabledTop(i):<EOL><INDENT>return False<EOL><DEDENT><DEDENT>return True<EOL>


from gui.tools.debug import Shell    <EOL>shell = Shell()<EOL>shell.show()<EOL>return shell<EOL>


from gui.tools.inspector import InspectorTool<EOL>inspector = InspectorTool()<EOL>inspector.show(obj)<EOL>return inspector<EOL>

Open the inspector windows for a given object


def represent(obj, prefix, parent="<STR_LIT>", indent=<NUM_LIT:0>, context=False, max_cols=<NUM_LIT>):

try:<EOL><INDENT>name = getattr(obj, "<STR_LIT:name>", "<STR_LIT>")<EOL>class_name = "<STR_LIT>" % (prefix, obj.__class__.__name__)<EOL>padding = len(class_name) + <NUM_LIT:1> + indent * <NUM_LIT:4> + (<NUM_LIT:5> if context else <NUM_LIT:0>)<EOL>params = []<EOL>for (k, spec) in sorted(list(obj._meta.specs.items()), key=get_sort_key):<EOL><INDENT>if k == "<STR_LIT:index>":        <EOL><INDENT>continue            <EOL><DEDENT>if k == "<STR_LIT>" and parent != "<STR_LIT>":<EOL><INDENT>v = parent<EOL><DEDENT>else:<EOL><INDENT>v = getattr(obj, k, "<STR_LIT>")<EOL>if (not isinstance(spec, InternalSpec) <EOL>and v != spec.default<EOL>and (k != '<STR_LIT:id>' or v > <NUM_LIT:0>) <EOL>and isinstance(v, <EOL>(str, int, float, bool, dict, list, <EOL>decimal.Decimal, <EOL>datetime.datetime, datetime.date, datetime.time,<EOL>Font, Color))                <EOL>and repr(v) != '<STR_LIT:None>'<EOL>):<EOL><INDENT>v = repr(v)<EOL><DEDENT>else:<EOL><INDENT>v = None<EOL><DEDENT><DEDENT>if v is not None:<EOL><INDENT>params.append("<STR_LIT>" % (k, v)) <EOL><DEDENT><DEDENT>param_lines = []<EOL>line = "<STR_LIT>"<EOL>for param in params:<EOL><INDENT>if len(line + param) + <NUM_LIT:3> > max_cols - padding:<EOL><INDENT>param_lines.append(line)<EOL>line = "<STR_LIT>"<EOL><DEDENT>line += param + "<STR_LIT:U+002CU+0020>"<EOL><DEDENT>param_lines.append(line)<EOL>param_str = ("<STR_LIT>" % ("<STR_LIT:U+0020>" * padding)).join(param_lines)<EOL>return "<STR_LIT>" % (class_name, param_str)<EOL><DEDENT>except:<EOL><INDENT>raise<EOL>return object.__repr__(obj)<EOL><DEDENT>

Construct a string representing the object


kwargs = {}<EOL>for spec_name, spec in list(self._meta.specs.items()):<EOL><INDENT>value = getattr(self, spec_name)<EOL>if isinstance(value, Color):<EOL><INDENT>print("<STR_LIT>", value, value.default)<EOL>if value.default:<EOL><INDENT>value = None<EOL><DEDENT><DEDENT>if value is not None:<EOL><INDENT>kwargs[spec_name] = value<EOL><DEDENT><DEDENT>del kwargs['<STR_LIT>'] <EOL>new_id = wx.NewId()<EOL>kwargs['<STR_LIT:id>'] = new_id<EOL>kwargs['<STR_LIT:name>'] = "<STR_LIT>" % (kwargs['<STR_LIT:name>'], new_id)<EOL>new_obj = self.__class__(new_parent or self.get_parent(), **kwargs)<EOL>for child in self:<EOL><INDENT>child.duplicate(new_obj)<EOL><DEDENT>return new_obj<EOL>

Create a new object exactly similar to self


parent_name = self._get_parent_name()<EOL>if not parent_name:<EOL><INDENT>return self._name<EOL><DEDENT>else:<EOL><INDENT>return "<STR_LIT>" % (parent_name, self._name)<EOL><DEDENT>

return full parents name + self name (useful as key)


parent = self.get_parent()<EOL>parent_names = []<EOL>while parent:<EOL><INDENT>if isinstance(parent, Component):<EOL><INDENT>parent_name = parent.name<EOL>if parent_name:<EOL><INDENT>parent_names.insert(<NUM_LIT:0>, parent_name)<EOL><DEDENT>parent = parent.get_parent()<EOL><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT>if not parent_names:<EOL><INDENT>return None<EOL><DEDENT>else:<EOL><INDENT>return '<STR_LIT:.>'.join(parent_names)<EOL><DEDENT>

Return parent window name (used in __repr__ parent spec)


self.destroy()<EOL>


for name, value in list(kwargs.items()):<EOL><INDENT>setattr(self, name, value)<EOL><DEDENT>

Update a property value with (used by the designer)


return self.wx_obj.GetId()<EOL>

return the id is generated using NewId by the base wxPython control


Component.set_parent(self, new_parent, init)<EOL>if not init:<EOL><INDENT>if DEBUG: print("<STR_LIT>", ctrl.name)<EOL>if hasattr(self.wx_obj, "<STR_LIT>"):<EOL><INDENT>self.wx_obj.Reparent(self._parent.wx_obj)<EOL><DEDENT><DEDENT>

Re-parent a child control with the new wx_obj parent


def _calc_dimension(self, dim_val, dim_max, font_dim):

if dim_val is None:<EOL><INDENT>return -<NUM_LIT:1>   <EOL><DEDENT>elif isinstance(dim_val, int):<EOL><INDENT>return dim_val  <EOL><DEDENT>elif isinstance(dim_val, str):<EOL><INDENT>if dim_val.endswith("<STR_LIT:%>"):<EOL><INDENT>dim_val = int(dim_val[:-<NUM_LIT:1>])<EOL>dim_val = dim_val / <NUM_LIT> * dim_max<EOL><DEDENT>elif dim_val.endswith("<STR_LIT>"):<EOL><INDENT>dim_val = float(dim_val[:-<NUM_LIT:2>])<EOL>dim_val = dim_val * font_dim<EOL><DEDENT>elif dim_val.endswith("<STR_LIT>"):<EOL><INDENT>dim_val = dim_val[:-<NUM_LIT:2>]<EOL><DEDENT>elif dim_val == "<STR_LIT>" or dim_val == "<STR_LIT>":<EOL><INDENT>dim_val = -<NUM_LIT:1><EOL><DEDENT>return int(dim_val)<EOL><DEDENT>

Calculate final pos and size (auto, absolute in pixels & relativa)


def choose_directory(message='<STR_LIT>', path="<STR_LIT>", parent=None):

result = dialogs.directoryDialog(parent, message, path)<EOL>return result.path<EOL>


def confirm(message="<STR_LIT>", title="<STR_LIT>", default=False, ok=False, cancel=False,<EOL>parent=None):

style = wx.CENTRE<EOL>if ok:<EOL><INDENT>style |= wx.OK <EOL><DEDENT>else:<EOL><INDENT>style |= wx.YES | wx.NO<EOL>if default:<EOL><INDENT>style |= wx.YES_DEFAULT<EOL><DEDENT>else:<EOL><INDENT>style |= wx.NO_DEFAULT<EOL><DEDENT><DEDENT>if cancel:<EOL><INDENT>style |= wx.CANCEL<EOL><DEDENT>result = dialogs.messageDialog(parent, message, title, style)<EOL>if cancel and result.returned == wx.ID_CANCEL:<EOL><INDENT>return None<EOL><DEDENT>return result.accepted<EOL>

Ask for confirmation (yes/no or ok and cancel), returns True or False


def save_file(title="<STR_LIT>",  directory='<STR_LIT>', filename='<STR_LIT>', <EOL>wildcard='<STR_LIT>', overwrite=False, parent=None):

style = wx.SAVE <EOL>if not overwrite:<EOL><INDENT>style |= wx.OVERWRITE_PROMPT<EOL><DEDENT>result = dialogs.fileDialog(parent, title, directory, filename, wildcard, <EOL>style)<EOL>return result.paths<EOL>

Show a dialog to select file to save, return path(s) if accepted


return self.wx_obj.GetCount()<EOL>

Returns the number of items in the control.


self.wx_obj.Clear()<EOL>self._items_dict = {}<EOL>


self.wx_obj.SetClientData(n, data)<EOL>self._items_dict[data] = self.get_string(n)<EOL>

Associate the given client data with the item at position n.


return self.wx_obj.SetMaxLength(max)<EOL>

sets the maximum number of characters allowed into the control


self.clear()<EOL>for ch in reversed(self.columns):<EOL><INDENT>del self[ch.name]<EOL><DEDENT>


wx_data = self.GetItemData(item)<EOL>py_data = self._py_data_map.get(wx_data)<EOL>return py_data<EOL>

Returns the pyth item data associated with the item


wx_data = self.GetItemData(item)<EOL>py_data = self._py_data_map[wx_data]<EOL>del self._py_data_map[wx_data]<EOL>del self._wx_data_map[py_data]<EOL>wx.ListCtrl.DeleteItem(self, item)<EOL>

Remove the item from the list and unset the related data


self._buf_image.DrawArcPoint(x1y1, x2y2, xcyc)<EOL>if self.auto_refresh:<EOL><INDENT>dc = wx.ClientDC(self.wx_obj)<EOL>dc.BlitPointSize((<NUM_LIT:0>, <NUM_LIT:0>), (self._size[<NUM_LIT:0>], self._size[<NUM_LIT:1>]), self._buf_image, (<NUM_LIT:0>, <NUM_LIT:0>))<EOL><DEDENT>

Draws an arc of a circle, centered on (xc, yc), with starting
point (x1, y1) and ending at (x2, y2). The current pen is used
for the outline and the current brush for filling the shape.

The arc is drawn in an anticlockwise direction from the start
point to the end point.


if isinstance(values, dict):<EOL><INDENT>row = GridRow(self, **values)<EOL><DEDENT>else:<EOL><INDENT>row = GridRow(self, *values)<EOL><DEDENT>list.append(self, row)<EOL>self._grid_view.wx_obj.AppendRows(numRows=<NUM_LIT:1>)<EOL>

Insert a number of rows into the grid (and associated table)


return self._grid_model.index(self)<EOL>

Get the actual position (can vary due insertion/deletions and sorting)


self._created = False<EOL>SubComponent.set_parent(self, new_parent, init)<EOL>if self.index == -<NUM_LIT:1> or self.index >= len(self._parent.columns):<EOL><INDENT>self.index = len(self._parent.columns) - <NUM_LIT:1><EOL><DEDENT>self._parent.wx_obj.AppendCols(<NUM_LIT:1>)<EOL>self._created = True<EOL>

Associate the header to the control (it could be recreated)


<EOL>msg = gridlib.GridTableMessage(self, <EOL>gridlib.GRIDTABLE_REQUEST_VIEW_GET_VALUES)<EOL>grid.ProcessTableMessage(msg)<EOL>


<EOL>return (not (evt.ControlDown() or evt.AltDown()) and<EOL>evt.GetKeyCode() != wx.WXK_SHIFT)<EOL>

Return True to allow the given key to start editing


for child in self:<EOL><INDENT>if isinstance(child, Control):<EOL><INDENT>child.resize(evt)<EOL><DEDENT><DEDENT>if evt:<EOL><INDENT>evt.Skip()<EOL><DEDENT>

automatically adjust relative pos and size of children controls


return self.wx_obj.GetPageCount()<EOL>


if wx_item is not None:<EOL><INDENT>key = self._tree_view.wx_obj.GetPyData(wx_item)<EOL>return self[key]<EOL><DEDENT>else:<EOL><INDENT>return self.items()<EOL><DEDENT>

Look for a item based on the wx_item or return a key/value pair


ctrl_output.value += msg + "<STR_LIT:\n>"<EOL>

Append the message to the output text box control


def validate_integer(self, action, index, value_if_allowed, prior_value,<EOL>text, validation_type, trigger_type, widget_name):

if(action == '<STR_LIT:1>'):<EOL><INDENT>if text in '<STR_LIT>':<EOL><INDENT>try:<EOL><INDENT>int(value_if_allowed)<EOL>return True<EOL><DEDENT>except ValueError:<EOL><INDENT>return False<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return False<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return True<EOL><DEDENT>

Check if text Entry is valid (number).

        I have no idea what all these arguments are doing here but took this from
        https://stackoverflow.com/questions/8959815/restricting-the-value-in-tkinter-entry-widget


start_time = dt.fromtimestamp(time.time()).strftime('<STR_LIT>')<EOL>logname = os.path.join(os.path.expanduser("<STR_LIT>") + "<STR_LIT>" + start_time + "<STR_LIT>")<EOL>handlers = [logging.FileHandler(logname)]<EOL>logging.basicConfig(<EOL>format='<STR_LIT>',<EOL>handlers=handlers,<EOL>level=logging.INFO)<EOL>logging.info('<STR_LIT>'.format(__version__, nanoplot.__version__))<EOL>logging.info('<STR_LIT>'.format(sys.version.replace('<STR_LIT:\n>', '<STR_LIT:U+0020>')))<EOL>return logname<EOL>


return self._call(JSONRPCMethods.GET_BLOCK_COUNT.value, **kwargs)<EOL>

Returns the number of blocks in the chain.

        :return: number of blocks in the chain
        :rtype: int


return self._call(JSONRPCMethods.GET_PEERS.value, **kwargs)<EOL>

Returns a list of nodes that the node is currently connected/disconnected from.

        :return: dictionary containing the nodes the current node is connected/disconnected from
        :rtype: dict


def get_block_sys_fee(self, block_index, **kwargs):

return self._call(JSONRPCMethods.GET_BLOCK_SYS_FEE.value, [block_index, ], **kwargs)<EOL>

Returns the system fees associated with a specific block index.

        :param block_index: a block index (block height)
        :type block_index: int
        :return: system fees of the block, expressed in NeoGas units
        :rtype: str


def get_account_state(self, address, **kwargs):

return self._call(JSONRPCMethods.GET_ACCOUNT_STATE.value, params=[address, ], **kwargs)<EOL>

Returns the account state information associated with a specific address.

        :param address: a 34-bit length address (eg. AJBENSwajTzQtwyJFkiJSv7MAaaMc7DsRz)
        :type address: str
        :return: dictionary containing the account state information
        :rtype: dict


def get_block_hash(self, block_index, **kwargs):

return self._call(JSONRPCMethods.GET_BLOCK_HASH.value, [block_index, ], **kwargs)<EOL>

Returns the hash value associated with a specific block index.

        :param block_index: a block index (block height)
        :type block_index: int
        :return: hash of the block associated with the considered index
        :rtype: str


return self._call(JSONRPCMethods.GET_RAW_MEM_POOL.value, **kwargs)<EOL>

Returns a list of unconfirmed transactions in memory associated with the node.

        :return: list of unconfirmed transaction hashes
        :rtype: list


return cls(host='<STR_LIT>', port=<NUM_LIT>)<EOL>

Creates a ``Client`` instance for use with the NEO Main Net.


return self._call(JSONRPCMethods.GET_CONNECTION_COUNT.value, **kwargs)<EOL>

Returns the current number of connections for the considered node.

        :return: number of connections for the node
        :rtype: int


def invoke_script(self, script, **kwargs):

raw_result = self._call(JSONRPCMethods.INVOKE_SCRIPT.value, [script, ], **kwargs)<EOL>return decode_invocation_result(raw_result)<EOL>

Invokes a script on the VM and returns the result.

        :param script: script runnable by the VM
        :type script: str
        :return: result of the invocation
        :rtype: dictionary


def get_storage(self, script_hash, key, **kwargs):

hexkey = binascii.hexlify(key.encode('<STR_LIT:utf-8>')).decode('<STR_LIT:utf-8>')<EOL>hexresult = self._call(<EOL>JSONRPCMethods.GET_STORAGE.value, params=[script_hash, hexkey, ], **kwargs)<EOL>try:<EOL><INDENT>assert hexresult<EOL>result = bytearray(binascii.unhexlify(hexresult.encode('<STR_LIT:utf-8>')))<EOL><DEDENT>except AssertionError:<EOL><INDENT>result = hexresult<EOL><DEDENT>return result<EOL>

Returns the value stored in the storage of a contract script hash for a given key.

        :param script_hash: contract script hash
        :param key: key to look up in the storage
        :type script_hash: str
        :type key: str
        :return: value associated with the storage key
        :rtype: bytearray


self.small_delay()<EOL>user_id = self.convert_to_user_id(user_id)<EOL>if not user_id:<EOL><INDENT>return False<EOL><DEDENT>if user_id in self.whitelist:<EOL><INDENT>return True<EOL><DEDENT>if user_id in self.blacklist:<EOL><INDENT>return False<EOL><DEDENT>user_info = self.get_user_info(user_id)<EOL>if not user_info:<EOL><INDENT>return True  <EOL><DEDENT>skipped = self.skipped_file<EOL>if "<STR_LIT>" in user_info and user_info["<STR_LIT>"] > self.max_following_to_block:<EOL><INDENT>msg = '<STR_LIT>'<EOL>self.console_print(msg, '<STR_LIT>')<EOL>skipped.append(user_id)<EOL>return False  <EOL><DEDENT>if search_stop_words_in_user(self, user_info):<EOL><INDENT>msg = '<STR_LIT>'<EOL>skipped.append(user_id)<EOL>return False<EOL><DEDENT>return True<EOL>


def send_like(self, user_ids, thread_id=None):

user_ids = _get_user_ids(self, user_ids)<EOL>if not isinstance(user_ids, (list, str)):<EOL><INDENT>self.logger.error('<STR_LIT>')<EOL>return False<EOL><DEDENT>if self.reached_limit('<STR_LIT>'):<EOL><INDENT>self.logger.info("<STR_LIT>")<EOL>return False<EOL><DEDENT>self.delay('<STR_LIT:message>')<EOL>if self.api.send_direct_item('<STR_LIT>', user_ids, thread=thread_id):<EOL><INDENT>self.total['<STR_LIT>'] += <NUM_LIT:1><EOL>return True<EOL><DEDENT>self.logger.info("<STR_LIT>".format(user_ids=user_ids))<EOL>return False<EOL>

:param self: bot
:param text: text of message
:param user_ids: list of user_ids for creating group or one user_id for send to one person
:param thread_id: thread_id


def comment_user(self, user_id, amount=None):

if not self.check_user(user_id, filter_closed_acc=True):<EOL><INDENT>return False<EOL><DEDENT>self.logger.info("<STR_LIT>" % user_id)<EOL>user_id = self.convert_to_user_id(user_id)<EOL>medias = self.get_user_medias(user_id, is_comment=True)<EOL>if not medias:<EOL><INDENT>self.logger.info(<EOL>"<STR_LIT>")<EOL>return False<EOL><DEDENT>return self.comment_medias(medias[:amount])<EOL>


def get_last_user_medias(self, user_id, count):

return get_last_user_medias(self, user_id, count)<EOL>

Returns the last number of posts specified in count in media ids array.
:type count: int
:param count: Count of posts
:return: array


last_action, target_delay = self.last[key], self.delays[key]<EOL>elapsed_time = time.time() - last_action<EOL>if elapsed_time < target_delay:<EOL><INDENT>t_remaining = target_delay - elapsed_time<EOL>time.sleep(t_remaining * random.uniform(<NUM_LIT>, <NUM_LIT>))<EOL><DEDENT>self.last[key] = time.time()<EOL>

Sleep only if elapsed time since `self.last[key]` < `self.delay[key]`.


return get_your_medias(self, as_dict)<EOL>

Returns your media ids. With parameter as_dict=True returns media as dict.
:type as_dict: bool


while not check_secret():<EOL><INDENT>pass<EOL><DEDENT>while True:<EOL><INDENT>try:<EOL><INDENT>with open(SECRET_FILE, "<STR_LIT:r>") as f:<EOL><INDENT>lines = [line.strip().split("<STR_LIT::>", <NUM_LIT:2>) for line in f.readlines()]<EOL><DEDENT><DEDENT>except ValueError:<EOL><INDENT>msg = '<STR_LIT>'<EOL>raise Exception(msg.format(SECRET_FILE))<EOL><DEDENT>if username is not None:<EOL><INDENT>for login, password in lines:<EOL><INDENT>if login == username.strip():<EOL><INDENT>return login, password<EOL><DEDENT><DEDENT><DEDENT>print("<STR_LIT>")<EOL>for ind, (login, password) in enumerate(lines):<EOL><INDENT>print("<STR_LIT>" % (ind + <NUM_LIT:1>, login))<EOL><DEDENT>print("<STR_LIT>" % (<NUM_LIT:0>, "<STR_LIT>"))<EOL>print("<STR_LIT>" % (-<NUM_LIT:1>, "<STR_LIT>"))<EOL>try:<EOL><INDENT>ind = int(sys.stdin.readline())<EOL>if ind == <NUM_LIT:0>:<EOL><INDENT>add_credentials()<EOL>continue<EOL><DEDENT>elif ind == -<NUM_LIT:1>:<EOL><INDENT>delete_credentials()<EOL>check_secret()<EOL>continue<EOL><DEDENT>elif <NUM_LIT:0> <= ind - <NUM_LIT:1> < len(lines):<EOL><INDENT>return lines[ind - <NUM_LIT:1>]<EOL><DEDENT><DEDENT>except Exception:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT><DEDENT>

Returns login and password stored in `secret.txt`.


url = '<STR_LIT>'<EOL>return self.send_request(url)<EOL>


af_readers = {<EOL>'<STR_LIT>': missile.AmmoFileReader,<EOL>'<STR_LIT>': missile.SlowLogReader,<EOL>'<STR_LIT>': missile.LineReader,<EOL>'<STR_LIT>': missile.UriReader,<EOL>'<STR_LIT>': missile.UriPostReader,<EOL>'<STR_LIT>': missile.AccessLogReader,<EOL>'<STR_LIT>': missile.CaseLineReader,<EOL>}<EOL>if self.uris and self.ammo_file:<EOL><INDENT>raise StepperConfigurationError(<EOL>'<STR_LIT>'<EOL>)<EOL><DEDENT>elif self.uris:<EOL><INDENT>ammo_gen = missile.UriStyleGenerator(<EOL>self.uris, self.headers, http_ver=self.http_ver)<EOL><DEDENT>elif self.ammo_file:<EOL><INDENT>if self.ammo_type in af_readers:<EOL><INDENT>if self.ammo_type == '<STR_LIT>':<EOL><INDENT>opener = resource.get_opener(self.ammo_file)<EOL>with opener(self.use_cache) as ammo:<EOL><INDENT>try:<EOL><INDENT>if not ammo.next()[<NUM_LIT:0>].isdigit():<EOL><INDENT>self.ammo_type = '<STR_LIT>'<EOL>self.log.info(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>else:<EOL><INDENT>self.log.info(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT><DEDENT>except StopIteration:<EOL><INDENT>self.log.exception(<EOL>"<STR_LIT>")<EOL>raise AmmoFileError(<EOL>"<STR_LIT>")<EOL><DEDENT><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>raise NotImplementedError(<EOL>'<STR_LIT>' % self.ammo_type)<EOL><DEDENT>ammo_gen = af_readers[self.ammo_type](<EOL>self.ammo_file, headers=self.headers, http_ver=self.http_ver, use_cache=self.use_cache)<EOL><DEDENT>else:<EOL><INDENT>raise StepperConfigurationError(<EOL>'<STR_LIT>')<EOL><DEDENT>self.log.info("<STR_LIT>" % type(ammo_gen).__name__)<EOL>return ammo_gen<EOL>


if self.rps_schedule and self.instances_schedule:<EOL><INDENT>raise StepperConfigurationError(<EOL>'<STR_LIT>'<EOL>)<EOL><DEDENT>elif self.rps_schedule:<EOL><INDENT>info.status.publish('<STR_LIT>', self.rps_schedule)<EOL>return lp.create(self.rps_schedule)<EOL><DEDENT>elif self.instances_schedule:<EOL><INDENT>info.status.publish('<STR_LIT>', self.instances_schedule)<EOL>return ip.create(self.instances_schedule)<EOL><DEDENT>else:<EOL><INDENT>self.instances_schedule = []<EOL>info.status.publish('<STR_LIT>', self.instances_schedule)<EOL>return ip.create(self.instances_schedule)<EOL><DEDENT>


_re_token = re.compile("<STR_LIT>")<EOL>def parse_token(time, multiplier):<EOL><INDENT>multipliers = {<EOL>'<STR_LIT:d>': <NUM_LIT>,<EOL>'<STR_LIT:h>': <NUM_LIT>,<EOL>'<STR_LIT:m>': <NUM_LIT>,<EOL>'<STR_LIT:s>': <NUM_LIT:1>,<EOL>}<EOL>if multiplier:<EOL><INDENT>if multiplier in multipliers:<EOL><INDENT>return int(float(time) * multipliers[multiplier] * <NUM_LIT:1000>)<EOL><DEDENT>else:<EOL><INDENT>raise StepperConfigurationError(<EOL>'<STR_LIT>' % duration)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return int(float(time) * <NUM_LIT:1000>)<EOL><DEDENT><DEDENT>return sum(parse_token(*token) for token in _re_token.findall(duration))<EOL>

Parse duration string, such as '3h2m3s' into milliseconds

>>> parse_duration('3h2m3s')
10923000

>>> parse_duration('0.3s')
300

>>> parse_duration('5')
5000


return sum(step.get_duration() for step in self.steps)<EOL>


int_rps = range(int(self.minrps), int(self.maxrps) + <NUM_LIT:1>)<EOL>step_duration = float(self.duration) / len(int_rps)<EOL>rps_list = [(rps, int(step_duration)) for rps in int_rps]<EOL>return rps_list<EOL>

get list of constant load parts (we have no constant load at all, but tank will think so),
with parts durations (float)


try:<EOL><INDENT>root1, root2 = solve_quadratic(self.slope / <NUM_LIT>, self.minrps, -n)<EOL><DEDENT>except ZeroDivisionError:<EOL><INDENT>root2 = float(n) / self.minrps<EOL><DEDENT>return int(root2 * <NUM_LIT:1000>)<EOL>

:param n: number of charge
:return: when to shoot nth charge, milliseconds


seconds = range(<NUM_LIT:0>, int(self.duration) + <NUM_LIT:1>)<EOL>rps_groups = groupby([proper_round(self.rps_at(t)) for t in seconds],<EOL>lambda x: x)<EOL>rps_list = [(rps, len(list(rpl))) for rps, rpl in rps_groups]<EOL>return rps_list<EOL>

get list of each second's rps
:returns: list of tuples (rps, duration of corresponding rps in seconds)
:rtype: list


return int(self.duration / <NUM_LIT:1000> * self.rps)<EOL>


def __init__(self, minrps, maxrps, duration):

self.minrps = float(minrps)<EOL>self.maxrps = float(maxrps)<EOL>self.duration = duration / <NUM_LIT><EOL>self.slope = (self.maxrps - self.minrps) / self.duration<EOL>

:param minrps:
:param maxrps:
:param duration: milliseconds


if len(rps_schedule) > <NUM_LIT:1>:<EOL><INDENT>lp = Composite(<EOL>[StepFactory.produce(step_config) for step_config in rps_schedule])<EOL><DEDENT>else:<EOL><INDENT>lp = StepFactory.produce(rps_schedule[<NUM_LIT:0>])<EOL><DEDENT>info.status.publish('<STR_LIT>', lp.get_duration() / <NUM_LIT:1000>)<EOL>info.status.publish('<STR_LIT>', lp.get_rps_list())<EOL>info.status.lp_len = len(lp)<EOL>return lp<EOL>

Create Load Plan as defined in schedule. Publish info about its duration.


def get_option(self, option, param2=None):

result = self.cfg[option]<EOL>self.log.debug(<EOL>"<STR_LIT>", option, result)<EOL>return result<EOL>


ammo_stream = (<EOL>ammo<EOL>for ammo in ((missile, marker or self.marker(missile))<EOL>for missile, marker in self.ammo_generator)<EOL>if self.filter(ammo))<EOL>return ((timestamp, marker or self.marker(missile), missile)<EOL>for timestamp, (missile, marker<EOL>) in zip(self.load_plan, ammo_stream))<EOL>

Returns a generator of (timestamp, marker, missile) tuples
where missile is in a string representation. Load Plan (timestamps
generator) and ammo generator are taken from the previously
configured ComponentFactory, passed as a parameter to the
__init__ method of this class.


def init_logging(events_log_fname, verbose, quiet):

logger = logging.getLogger('<STR_LIT>')<EOL>logger.setLevel(logging.DEBUG)<EOL>console_handler = logging.StreamHandler(sys.stdout)<EOL>stderr_hdl = logging.StreamHandler(sys.stderr)<EOL>fmt_verbose = logging.Formatter(<EOL>"<STR_LIT>"<EOL>)<EOL>fmt_regular = logging.Formatter(<EOL>"<STR_LIT>", "<STR_LIT>")<EOL>if verbose:<EOL><INDENT>console_handler.setLevel(logging.DEBUG)<EOL>console_handler.setFormatter(fmt_verbose)<EOL>stderr_hdl.setFormatter(fmt_verbose)<EOL><DEDENT>elif quiet:<EOL><INDENT>console_handler.setLevel(logging.WARNING)<EOL>console_handler.setFormatter(fmt_regular)<EOL>stderr_hdl.setFormatter(fmt_regular)<EOL><DEDENT>else:<EOL><INDENT>console_handler.setLevel(logging.INFO)<EOL>console_handler.setFormatter(fmt_regular)<EOL>stderr_hdl.setFormatter(fmt_regular)<EOL><DEDENT>f_err = SingleLevelFilter(logging.ERROR, True)<EOL>f_warn = SingleLevelFilter(logging.WARNING, True)<EOL>f_crit = SingleLevelFilter(logging.CRITICAL, True)<EOL>console_handler.addFilter(f_err)<EOL>console_handler.addFilter(f_warn)<EOL>console_handler.addFilter(f_crit)<EOL>logger.addHandler(console_handler)<EOL>f_info = SingleLevelFilter(logging.INFO, True)<EOL>f_debug = SingleLevelFilter(logging.DEBUG, True)<EOL>stderr_hdl.addFilter(f_info)<EOL>stderr_hdl.addFilter(f_debug)<EOL>logger.addHandler(stderr_hdl)<EOL>if events_log_fname:<EOL><INDENT>err_file_handler = logging.FileHandler(events_log_fname)<EOL>err_file_handler.setLevel(logging.WARNING)<EOL>err_file_handler.setFormatter(<EOL>logging.Formatter(<EOL>"<STR_LIT>"<EOL>))<EOL>return [err_file_handler, console_handler, stderr_hdl]<EOL><DEDENT>else:<EOL><INDENT>return [console_handler, stderr_hdl]<EOL><DEDENT>

Set up logging, as it is very important for console tool


def mkstemp(self, suffix, prefix, directory=None):

if not directory:<EOL><INDENT>directory = self.artifacts_dir<EOL><DEDENT>fd, fname = tempfile.mkstemp(suffix, prefix, directory)<EOL>os.close(fd)<EOL>os.chmod(fname, <NUM_LIT>)  <EOL>return fname<EOL>

Generate temp file name in artifacts base dir
and close temp file handle


if not self.interrupted.is_set():<EOL><INDENT>logger.info("<STR_LIT>")<EOL>logger.info('<STR_LIT>'.format(dir=self.artifacts_dir))<EOL>self.publish("<STR_LIT>", "<STR_LIT>", "<STR_LIT>")<EOL>if not self.plugins:<EOL><INDENT>raise RuntimeError("<STR_LIT>")<EOL><DEDENT><DEDENT>while not self.interrupted.is_set():<EOL><INDENT>begin_time = time.time()<EOL>aggr_retcode = self.job.aggregator.is_test_finished()<EOL>if aggr_retcode >= <NUM_LIT:0>:<EOL><INDENT>return aggr_retcode<EOL><DEDENT>for plugin in self.plugins.values():<EOL><INDENT>logger.debug("<STR_LIT>", plugin)<EOL>retcode = plugin.is_test_finished()<EOL>if retcode >= <NUM_LIT:0>:<EOL><INDENT>return retcode<EOL><DEDENT><DEDENT>end_time = time.time()<EOL>diff = end_time - begin_time<EOL>logger.debug("<STR_LIT>", diff)<EOL>logger.debug("<STR_LIT>", json.dumps(self.status))<EOL>if diff < <NUM_LIT:0.5>:<EOL><INDENT>time.sleep(<NUM_LIT:0.5> - diff)<EOL><DEDENT><DEDENT>return <NUM_LIT:1><EOL>

Call is_test_finished() on all plugins 'till one of them initiates exit


logger.info("<STR_LIT>")<EOL>self.publish("<STR_LIT>", "<STR_LIT>", "<STR_LIT>")<EOL>for plugin in self.plugins.values():<EOL><INDENT>logger.debug("<STR_LIT>", plugin)<EOL>try:<EOL><INDENT>logger.debug("<STR_LIT>", retcode)<EOL>retcode = plugin.post_process(retcode)<EOL>logger.debug("<STR_LIT>", retcode)<EOL><DEDENT>except Exception:  <EOL><INDENT>logger.error("<STR_LIT>", plugin, exc_info=True)<EOL>if not retcode:<EOL><INDENT>retcode = <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>return retcode<EOL>


logger.debug("<STR_LIT>", plugin_class)<EOL>matches = [plugin for plugin in self.plugins.values() if isinstance(plugin, plugin_class)]<EOL>if matches:<EOL><INDENT>if len(matches) > <NUM_LIT:1>:<EOL><INDENT>logger.debug(<EOL>"<STR_LIT>",<EOL>plugin_class)<EOL><DEDENT>return matches[-<NUM_LIT:1>]<EOL><DEDENT>else:<EOL><INDENT>raise KeyError("<STR_LIT>" % plugin_class)<EOL><DEDENT>

Retrieve a plugin of desired class, KeyError raised otherwise


def add_artifact_file(self, filename, keep_original=False):

if filename:<EOL><INDENT>logger.debug(<EOL>"<STR_LIT>", keep_original,<EOL>filename)<EOL>self.artifact_files[filename] = keep_original<EOL><DEDENT>

Add file to be stored as result artifact on post-process phase


def set_option(self, section, option, value):

raise NotImplementedError<EOL>


logger.info("<STR_LIT>")<EOL>for plugin in self.plugins.values():<EOL><INDENT>logger.debug("<STR_LIT>", plugin)<EOL>try:<EOL><INDENT>plugin.close()<EOL><DEDENT>except Exception as ex:<EOL><INDENT>logger.error("<STR_LIT>", plugin, ex)<EOL>logger.debug(<EOL>"<STR_LIT>", traceback.format_exc(ex))<EOL><DEDENT><DEDENT>


self.publish("<STR_LIT>", "<STR_LIT>", "<STR_LIT>")<EOL>logger.info("<STR_LIT>")<EOL>self.taskset_affinity = self.get_option(self.SECTION, '<STR_LIT>')<EOL>if self.taskset_affinity:<EOL><INDENT>self.__setup_taskset(self.taskset_affinity, pid=os.getpid())<EOL><DEDENT>for plugin in self.plugins.values():<EOL><INDENT>if not self.interrupted.is_set():<EOL><INDENT>logger.debug("<STR_LIT>", plugin)<EOL>plugin.configure()<EOL><DEDENT><DEDENT>


if is_ini(cfg_filename):<EOL><INDENT>return convert_ini(cfg_filename)<EOL><DEDENT>else:<EOL><INDENT>with open(cfg_filename) as f:<EOL><INDENT>return yaml.load(f)<EOL><DEDENT><DEDENT>


if options is None:<EOL><INDENT>return []<EOL><DEDENT>else:<EOL><INDENT>return [<EOL>convert_single_option(key.strip(), value.strip())<EOL>for key, value<EOL>in [option.split('<STR_LIT:=>', <NUM_LIT:1>) for option in options]<EOL>]<EOL><DEDENT>

:type options: list of str
:rtype: list of dict


logger.debug("<STR_LIT>")<EOL>try:<EOL><INDENT>self.gun.setup()<EOL><DEDENT>except Exception:<EOL><INDENT>logger.exception("<STR_LIT>")<EOL>return<EOL><DEDENT>while not self.quit.is_set():<EOL><INDENT>try:<EOL><INDENT>task = self.task_queue.get(timeout=<NUM_LIT:1>)<EOL>if not task:<EOL><INDENT>logger.debug("<STR_LIT>")<EOL>break<EOL><DEDENT>timestamp, missile, marker = task<EOL>planned_time = self.start_time + (timestamp / <NUM_LIT>)<EOL>delay = planned_time - time.time()<EOL>if delay > <NUM_LIT:0>:<EOL><INDENT>time.sleep(delay)<EOL><DEDENT>try:<EOL><INDENT>with self.instance_counter.get_lock():<EOL><INDENT>self.instance_counter.value += <NUM_LIT:1><EOL><DEDENT>self.gun.shoot(missile, marker)<EOL><DEDENT>finally:<EOL><INDENT>with self.instance_counter.get_lock():<EOL><INDENT>self.instance_counter.value -= <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>except (KeyboardInterrupt, SystemExit):<EOL><INDENT>break<EOL><DEDENT>except Empty:<EOL><INDENT>if self.quit.is_set():<EOL><INDENT>logger.debug("<STR_LIT>")<EOL>return<EOL><DEDENT><DEDENT>except Full:<EOL><INDENT>logger.warning("<STR_LIT>")<EOL><DEDENT>except Exception:<EOL><INDENT>logger.exception("<STR_LIT>")<EOL><DEDENT><DEDENT>try:<EOL><INDENT>self.gun.teardown()<EOL><DEDENT>except Exception:<EOL><INDENT>logger.exception("<STR_LIT>")<EOL>return<EOL><DEDENT>logger.debug("<STR_LIT>")<EOL>


return not self.workers_finished<EOL>

True while there are alive workers out there. Tank
will quit when this would become False


while not self.quit.is_set():<EOL><INDENT>try:<EOL><INDENT>task = self.green_queue.get(timeout=<NUM_LIT:1>)<EOL>timestamp, missile, marker = task<EOL>planned_time = self.start_time + (timestamp / <NUM_LIT>)<EOL>delay = planned_time - time.time()<EOL>if delay > <NUM_LIT:0>:<EOL><INDENT>time.sleep(delay)<EOL><DEDENT>try:<EOL><INDENT>with self.instance_counter.get_lock():<EOL><INDENT>self.instance_counter.value += <NUM_LIT:1><EOL><DEDENT>self.gun.shoot(missile, marker)<EOL><DEDENT>finally:<EOL><INDENT>with self.instance_counter.get_lock():<EOL><INDENT>self.instance_counter.value -= <NUM_LIT:1><EOL><DEDENT>self._free_threads_count += <NUM_LIT:1><EOL><DEDENT><DEDENT>except (KeyboardInterrupt, SystemExit):<EOL><INDENT>break<EOL><DEDENT>except Empty:<EOL><INDENT>continue<EOL><DEDENT>except Full:<EOL><INDENT>logger.warning("<STR_LIT>")<EOL><DEDENT>except Exception:<EOL><INDENT>logger.exception("<STR_LIT>")<EOL><DEDENT><DEDENT>


if self.is_relative:<EOL><INDENT>level_str = str(<NUM_LIT:100> * self.level) + "<STR_LIT:%>"<EOL><DEDENT>else:<EOL><INDENT>level_str = self.level<EOL><DEDENT>return level_str<EOL>


if len(tangents) < <NUM_LIT:2>:<EOL><INDENT>return <NUM_LIT:0.0><EOL><DEDENT>avg_tan = float(sum(tangents) / len(tangents))<EOL>numerator = float()<EOL>for i in tangents:<EOL><INDENT>numerator += (i - avg_tan) * (i - avg_tan)<EOL><DEDENT>return math.sqrt(numerator / len(tangents) / (len(tangents) - <NUM_LIT:1>))<EOL>

formula for measurement error
sqrt ( (sum(1, n, (k_i - <k>)**2) / (n*(n-1)))


if self.is_relative:<EOL><INDENT>level_str = str(self.level) + "<STR_LIT:%>"<EOL><DEDENT>else:<EOL><INDENT>level_str = self.level<EOL><DEDENT>return level_str<EOL>


return self.counting<EOL>


if len(param1) <= <NUM_LIT:3>:<EOL><INDENT>try:<EOL><INDENT>int(param1)<EOL><DEDENT>except BaseException:<EOL><INDENT>logger.error(<EOL>"<STR_LIT>", param1)<EOL><DEDENT>else:<EOL><INDENT>return int(param1)<EOL><DEDENT><DEDENT>exc = param1.split('<STR_LIT:U+0020>')[-<NUM_LIT:1>]<EOL>if exc in KNOWN_EXC.keys():<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>logger.warning("<STR_LIT>", param1)<EOL>return <NUM_LIT:0><EOL><DEDENT>


def __add_jmeter_components(self, jmx, jtl, variables):

logger.debug("<STR_LIT>", os.path.realpath(jmx))<EOL>with open(jmx, '<STR_LIT:r>') as src_jmx:<EOL><INDENT>source_lines = src_jmx.readlines()<EOL><DEDENT>try:<EOL><INDENT>closing = source_lines.pop(-<NUM_LIT:1>)<EOL>if "<STR_LIT>" in source_lines[-<NUM_LIT:5>]:<EOL><INDENT>logger.info("<STR_LIT>")<EOL>last_string_count = <NUM_LIT:6><EOL><DEDENT>else:<EOL><INDENT>last_string_count = <NUM_LIT:2><EOL><DEDENT>while last_string_count > <NUM_LIT:0>:<EOL><INDENT>closing = source_lines.pop(-<NUM_LIT:1>) + closing<EOL>last_string_count -= <NUM_LIT:1><EOL><DEDENT>logger.debug("<STR_LIT>", closing)<EOL><DEDENT>except Exception as exc:<EOL><INDENT>raise RuntimeError("<STR_LIT>" % exc)<EOL><DEDENT>udv_tpl = resource_string(__name__, '<STR_LIT>')<EOL>udv_set = []<EOL>for var_name, var_value in variables.iteritems():<EOL><INDENT>udv_set.append(udv_tpl % (var_name, var_name, var_value))<EOL><DEDENT>udv = "<STR_LIT:\n>".join(udv_set)<EOL>if self.jmeter_ver >= <NUM_LIT>:<EOL><INDENT>save_connect = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>save_connect = '<STR_LIT>'<EOL><DEDENT>if self.ext_log in ['<STR_LIT>', '<STR_LIT:all>']:<EOL><INDENT>level_map = {'<STR_LIT>': '<STR_LIT:true>', '<STR_LIT:all>': '<STR_LIT:false>'}<EOL>tpl_resource = '<STR_LIT>'<EOL>tpl_args = {<EOL>'<STR_LIT>': self.jtl_file,<EOL>'<STR_LIT>': udv,<EOL>'<STR_LIT>': self.ext_log_file,<EOL>'<STR_LIT>': level_map[self.ext_log],<EOL>'<STR_LIT>': save_connect<EOL>}<EOL><DEDENT>else:<EOL><INDENT>tpl_resource = '<STR_LIT>'<EOL>tpl_args = {<EOL>'<STR_LIT>': self.jtl_file,<EOL>'<STR_LIT>': udv,<EOL>'<STR_LIT>': save_connect<EOL>}<EOL><DEDENT>tpl = resource_string(__name__, '<STR_LIT>' + tpl_resource)<EOL>try:<EOL><INDENT>new_jmx = self.core.mkstemp(<EOL>'<STR_LIT>', '<STR_LIT>', os.path.dirname(os.path.realpath(jmx)))<EOL><DEDENT>except OSError as exc:<EOL><INDENT>logger.debug("<STR_LIT>", exc)<EOL>new_jmx = self.core.mkstemp('<STR_LIT>', '<STR_LIT>')<EOL><DEDENT>logger.debug("<STR_LIT>", new_jmx)<EOL>with open(new_jmx, "<STR_LIT:wb>") as fh:<EOL><INDENT>fh.write('<STR_LIT>'.join(source_lines))<EOL>fh.write(tpl % tpl_args)<EOL>fh.write(closing)<EOL><DEDENT>return new_jmx<EOL>


r = re.compile(self.DISCOVER_PORT_PATTERN)<EOL>with open(self.process_stderr.name, '<STR_LIT:r>') as f:<EOL><INDENT>cnt = <NUM_LIT:0><EOL>while self.process.pid and cnt < <NUM_LIT:10>:<EOL><INDENT>line = f.readline()<EOL>m = r.match(line)<EOL>if m is None:<EOL><INDENT>cnt += <NUM_LIT:1><EOL>time.sleep(<NUM_LIT:1>)<EOL><DEDENT>else:<EOL><INDENT>port = int(m.group('<STR_LIT:port>'))<EOL>return port<EOL><DEDENT><DEDENT>else:<EOL><INDENT>logger.warning('<STR_LIT>')<EOL>return None<EOL><DEDENT><DEDENT>

Searching for line in jmeter.log such as
        Waiting for possible shutdown message on port 4445


for date_str, statistics in chunk.iteritems():<EOL><INDENT>date_obj = datetime.datetime.strptime(<EOL>date_str.split("<STR_LIT:.>")[<NUM_LIT:0>], '<STR_LIT>')<EOL>chunk_date = int(time.mktime(date_obj.timetuple()))<EOL>instances = <NUM_LIT:0><EOL>for benchmark_name, benchmark in statistics.iteritems():<EOL><INDENT>if not benchmark_name.startswith("<STR_LIT>"):<EOL><INDENT>continue<EOL><DEDENT>for method, meth_obj in benchmark.iteritems():<EOL><INDENT>if "<STR_LIT>" in meth_obj:<EOL><INDENT>instances += meth_obj["<STR_LIT>"][<NUM_LIT:2>]<EOL><DEDENT><DEDENT><DEDENT>offset = chunk_date - <NUM_LIT:1> - self.start_time<EOL>reqps = <NUM_LIT:0><EOL>if <NUM_LIT:0> <= offset < len(self.phantom_info.steps):<EOL><INDENT>reqps = self.phantom_info.steps[offset][<NUM_LIT:0>]<EOL><DEDENT>yield self.stats_item(chunk_date - <NUM_LIT:1>, instances, reqps)<EOL><DEDENT>


streams_config = '<STR_LIT>'<EOL>stat_benchmarks = '<STR_LIT>'<EOL>for stream in self.streams:<EOL><INDENT>streams_config += stream.compose_config()<EOL>if not stream.is_main:<EOL><INDENT>stat_benchmarks += "<STR_LIT:U+0020>" + "<STR_LIT>" % stream.sequence_no<EOL><DEDENT><DEDENT>kwargs = {}<EOL>kwargs['<STR_LIT>'] = self.threads<EOL>kwargs['<STR_LIT>'] = self.phantom_log<EOL>kwargs['<STR_LIT>'] = self.stat_log<EOL>kwargs['<STR_LIT>'] = streams_config<EOL>kwargs['<STR_LIT>'] = stat_benchmarks<EOL>kwargs['<STR_LIT>'] = self.additional_libs<EOL>kwargs['<STR_LIT>'] = self.phantom_modules_path<EOL>filename = self.core.mkstemp("<STR_LIT>", "<STR_LIT>")<EOL>self.core.add_artifact_file(filename)<EOL>logger.debug("<STR_LIT>", filename)<EOL>template_str = resource_string(__name__, "<STR_LIT>")<EOL>tpl = string.Template(template_str)<EOL>config = tpl.substitute(kwargs)<EOL>with open(filename, '<STR_LIT:w>') as conffile:<EOL><INDENT>conffile.write(config)<EOL><DEDENT>return filename<EOL>


self.threads = self.cfg["<STR_LIT>"] or str(int(multiprocessing.cpu_count() / <NUM_LIT:2>) + <NUM_LIT:1>)<EOL>self.phantom_modules_path = self.cfg["<STR_LIT>"]<EOL>self.additional_libs = '<STR_LIT:U+0020>'.join(self.cfg["<STR_LIT>"])<EOL>self.answ_log_level = self.cfg["<STR_LIT>"]<EOL>if self.answ_log_level.lower() in ['<STR_LIT:0>', '<STR_LIT:false>']:<EOL><INDENT>self.answ_log_level = '<STR_LIT:none>'<EOL><DEDENT>elif self.answ_log_level.lower() in ['<STR_LIT:1>', '<STR_LIT:true>']:<EOL><INDENT>self.answ_log_level = '<STR_LIT:all>'<EOL><DEDENT>self.timeout = parse_duration(self.cfg["<STR_LIT>"])<EOL>if self.timeout > <NUM_LIT>:<EOL><INDENT>logger.warning(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>self.answ_log = self.core.mkstemp("<STR_LIT>", "<STR_LIT>")<EOL>self.core.add_artifact_file(self.answ_log)<EOL>self.core.add_artifact_file(self.phout_file)<EOL>self.core.add_artifact_file(self.stat_log)<EOL>self.phantom_log = self.core.mkstemp("<STR_LIT>", "<STR_LIT>")<EOL>self.core.add_artifact_file(self.phantom_log)<EOL>main_stream = StreamConfig(<EOL>self.core,<EOL>len(self.streams), self.phout_file, self.answ_log,<EOL>self.answ_log_level, self.timeout, self.cfg, True)<EOL>self.streams.append(main_stream)<EOL>for section in self.multi():<EOL><INDENT>self.streams.append(<EOL>StreamConfig(<EOL>self.core,<EOL>len(self.streams), self.phout_file, self.answ_log,<EOL>self.answ_log_level, self.timeout, section))<EOL><DEDENT>for stream in self.streams:<EOL><INDENT>stream.read_config()<EOL><DEDENT>if any(stream.ssl for stream in self.streams):<EOL><INDENT>self.additional_libs += '<STR_LIT>'<EOL><DEDENT>


if not self.cached_info:<EOL><INDENT>if not self.phantom:<EOL><INDENT>return None<EOL><DEDENT>self.cached_info = self.phantom.get_info()<EOL><DEDENT>return self.cached_info<EOL>


cfg_path = "<STR_LIT>".format(self.host)<EOL>if os.path.isfile(cfg_path):<EOL><INDENT>logger.info(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>',<EOL>self.host)<EOL>handle, cfg_path = tempfile.mkstemp('<STR_LIT>', '<STR_LIT>')<EOL>os.close(handle)<EOL><DEDENT>try:<EOL><INDENT>config = ConfigParser.RawConfigParser()<EOL>config.add_section('<STR_LIT>')<EOL>[<EOL>config.set('<STR_LIT>', "<STR_LIT>" % idx, cmd)<EOL>for idx, cmd in enumerate(self.startups)<EOL>]<EOL>config.add_section('<STR_LIT>')<EOL>[<EOL>config.set('<STR_LIT>', "<STR_LIT>" % idx, cmd)<EOL>for idx, cmd in enumerate(self.shutdowns)<EOL>]<EOL>config.add_section('<STR_LIT:source>')<EOL>[<EOL>config.set('<STR_LIT:source>', "<STR_LIT>" % idx, path)<EOL>for idx, path in enumerate(self.sources)<EOL>]<EOL>with open(cfg_path, '<STR_LIT:w>') as fds:<EOL><INDENT>config.write(fds)<EOL><DEDENT><DEDENT>except Exception as exc:<EOL><INDENT>logger.error(<EOL>'<STR_LIT>',<EOL>exc,<EOL>exc_info=True)<EOL><DEDENT>return cfg_path<EOL>

Startup and shutdown commands config
        Used by agent.py on the target


cfg_path = "<STR_LIT>".format(self.host)<EOL>if os.path.isfile(cfg_path):<EOL><INDENT>logger.info(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>',<EOL>self.host)<EOL>handle, cfg_path = tempfile.mkstemp('<STR_LIT>', '<STR_LIT>')<EOL>os.close(handle)<EOL><DEDENT>cmds = "<STR_LIT>"<EOL>for idx, cmd in enumerate(self.custom):<EOL><INDENT>cmds += "<STR_LIT>".format(idx=idx, cmd=cmd['<STR_LIT>'])<EOL><DEDENT>customs_script = """<STR_LIT>""".format(cmds=cmds)<EOL>with open(cfg_path, '<STR_LIT:w>') as fds:<EOL><INDENT>fds.write(customs_script)<EOL><DEDENT>return cfg_path<EOL>

bash script w/ custom commands inside
        inspired by half a night trying to avoid escaping bash special characters


<EOL>agent_configs = []<EOL>if self.config:<EOL><INDENT>agent_configs = self.config_manager.getconfig(<EOL>self.config, self.default_target)<EOL><DEDENT>for config in agent_configs:<EOL><INDENT>if config['<STR_LIT:host>'] in ['<STR_LIT:localhost>', '<STR_LIT:127.0.0.1>', '<STR_LIT>']:<EOL><INDENT>client = self.clients['<STR_LIT:localhost>'](<EOL>config, self.old_style_configs, kill_old=self.kill_old)<EOL><DEDENT>else:<EOL><INDENT>client = self.clients['<STR_LIT>'](<EOL>config, self.old_style_configs, timeout=<NUM_LIT:5>, kill_old=self.kill_old)<EOL><DEDENT>logger.debug('<STR_LIT>', client.host)<EOL>agent_config, startup_config, customs_script = client.install()<EOL>if agent_config:<EOL><INDENT>self.agents.append(client)<EOL>self.artifact_files.append(agent_config)<EOL><DEDENT>if startup_config:<EOL><INDENT>self.artifact_files.append(startup_config)<EOL><DEDENT>if customs_script:<EOL><INDENT>self.artifact_files.append(customs_script)<EOL><DEDENT><DEDENT>

Prepare for monitoring - install agents etc


logger.warning("<STR_LIT>", sig)<EOL>raise KeyboardInterrupt()<EOL>

required for non-tty python runs to interrupt


raise NotImplementedError()<EOL>


def __handle_data_items(self, host, data):

for metric, value in data.iteritems():<EOL><INDENT>if value == '<STR_LIT>':<EOL><INDENT>self.sign[host][metric] = -<NUM_LIT:1><EOL>self.data[host][metric] = value<EOL><DEDENT>else:<EOL><INDENT>if not self.data[host].get(metric, None):<EOL><INDENT>self.sign[host][metric] = <NUM_LIT:1><EOL><DEDENT>elif float(value) > float(self.data[host][metric]):<EOL><INDENT>self.sign[host][metric] = <NUM_LIT:1><EOL><DEDENT>elif float(value) < float(self.data[host][metric]):<EOL><INDENT>self.sign[host][metric] = -<NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>self.sign[host][metric] = <NUM_LIT:0><EOL><DEDENT>self.data[host][metric] = "<STR_LIT>" % float(value)<EOL><DEDENT><DEDENT>

store metric in data tree and calc offset signs

        sign < 0 is CYAN, means metric value is lower then previous,
        sign > 1 is YELLOW, means metric value is higher then prevoius,
        sign == 0 is WHITE, means initial or equal metric value