/usr/lib/python2.7/dist-packages/clint/utils.py is in python-clint 0.3.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | # -*- coding: utf-8 -*-
"""
clint.utils
~~~~~~~~~~~~
Various Python helpers used within clint.
"""
from __future__ import absolute_import
from __future__ import with_statement
import errno
import os.path
from os import makedirs
from glob import glob
try:
    basestring
except NameError:
    basestring = str
def expand_path(path):
    """Expands directories and globs in given path."""
    paths = []
    path = os.path.expanduser(path)
    path = os.path.expandvars(path)
    if os.path.isdir(path):
        for (dir, dirs, files) in os.walk(path):
            for file in files:
                paths.append(os.path.join(dir, file))
    else:
        paths.extend(glob(path))
    return paths
def is_collection(obj):
    """Tests if an object is a collection. Strings don't count."""
    if isinstance(obj, basestring):
        return False
    return hasattr(obj, '__getitem__')
def mkdir_p(path):
    """Emulates `mkdir -p` behavior."""
    try:
        makedirs(path)
    except OSError as exc: # Python >2.5
        if exc.errno == errno.EEXIST:
            pass
        else:
            raise
def tsplit(string, delimiters):
    """Behaves str.split but supports tuples of delimiters."""
    delimiters = tuple(delimiters)
    stack = [string,]
    for delimiter in delimiters:
        for i, substring in enumerate(stack):
            substack = substring.split(delimiter)
            stack.pop(i)
            for j, _substring in enumerate(substack):
                stack.insert(i+j, _substring)
    return stack
def schunk(string, size):
    """Splits string into n sized chunks."""
    stack = []
    substack = []
    current_count = 0
    for char in string:
        if not current_count < size:
            stack.append(''.join(substack))
            substack = []
            current_count = 0
        substack.append(char)
        current_count += 1
    if len(substack):
        stack.append(''.join(substack))
    return stack
 |