Rough confidence based on string length and file extension
493267
def _confidence(matches, ext=None):
    
    results = []
    for match in matches:
        con = (0.8 if len(match.extension) > 9 else
               float("0.{0}".format(len(match.extension))))
        if ext == match.extension:
            con = 0.9
        results.append(
            PureMagicWithConfidence(confidence=con, **match._asdict()))
    return sorted(results, key=lambda x: x.confidence, reverse=True)
825634
function(str) {
        var p;
        p = str.indexOf('.');
        if (p==-1) {
            return libbcmath.bc_str2num(str, 0);
        } else {
            return libbcmath.bc_str2num(str, (str.length-p));
        }

    }
597093
def ensure_fixed_length_bytes(var):
    """"""
    dims, data, attrs, encoding = unpack_for_encoding(var)
    if check_vlen_dtype(data.dtype) == bytes:
        # TODO: figure out how to handle this with dask
        data = np.asarray(data, dtype=np.string_)
    return Variable(dims, data, attrs, encoding)
1189123
function _getExtension(file) {
        var ret;
        if (file) {
            var fileTypes = file.split(".");
            var len = fileTypes.length;
            if (0 === len) {
                return ret;
            }
            ret = fileTypes[len - 1];
            return ret;
        }
    }
917118
def CheckLineLength(filename, linenumber, clean_lines, errors):
    
    line = clean_lines.raw_lines[linenumber]
    if len(line) > _lint_state.linelength:
        return errors(
                filename,
                linenumber,
                'linelength',
                'Lines should be <= %d characters long' %
                    (_lint_state.linelength))
692492
def guess_file_encoding(fh, default=DEFAULT_ENCODING):
    """"""
    start = fh.tell()
    detector = chardet.UniversalDetector()
    while True:
        data = fh.read(1024 * 10)
        if not data:
            detector.close()
            break
        detector.feed(data)
        if detector.done:
            break

    fh.seek(start)
    return normalize_result(detector.result, default=default)
211031
def tail(filename, number_of_bytes):
    """"""
    with open(filename, "rb") as f:
        if os.stat(filename).st_size > number_of_bytes:
            f.seek(-number_of_bytes, 2)
        return f.read()
777657
function report(file, node, threshold, target, results) {
  var length = results.length
  var index = -1
  var failCount = 0
  var confidence
  var message

  while (++index < length) {
    if (results[index] > target) {
      failCount++
    }
  }

  if (failCount / length >= threshold) {
    confidence = failCount + '/' + length

    message = file.warn(
      'Hard to read sentence (confidence: ' + confidence + ')',
      node,
      source
    )
    message.confidence = confidence
    message.source = source
    message.actual = toString(node)
    message.expected = null
  }
}
213457
def ansi_len(string):
    """"""
    return len(string) - wcswidth(re.compile(r'\x1b[^m]*m').sub('', string))
1160498
def _validate_filenames(self):
        
        if not self.dirname:
            return

        def _is_truthy_and_not_str(f):
            return f and not isinstance(f, str)

        if (
                _is_truthy_and_not_str(self.f_optimizer) or
                _is_truthy_and_not_str(self.f_params) or
                _is_truthy_and_not_str(self.f_history) or
                _is_truthy_and_not_str(self.f_pickle)
        ):
            raise SkorchException(
                'dirname can only be used when f_* are strings')
697378
def verify_directory(verbose=True, max_size_mb=50):
    
    # Check required files
    ok = True
    mb_to_bytes = 1000 * 1000
    expected_files = ["config.txt", "experiment.py"]

    for f in expected_files:
        if os.path.exists(f):
            log("✓ {} is PRESENT".format(f), chevrons=False, verbose=verbose)
        else:
            log("✗ {} is MISSING".format(f), chevrons=False, verbose=verbose)
            ok = False

    # Check size
    max_size = max_size_mb * mb_to_bytes
    size = size_on_copy()
    if size > max_size:
        size_in_mb = round(size / mb_to_bytes)
        log(
            "✗ {}MB is TOO BIG (greater than {}MB)".format(size_in_mb, max_size_mb),
            chevrons=False,
            verbose=verbose,
        )
        ok = False

    return ok
599622
def description_of(file, name='stdin'):
    """"""
    u = UniversalDetector()
    for line in file:
        u.feed(line)
    u.close()
    result = u.result
    if result['encoding']:
        return '%s: %s with confidence %s' % (name,
                                              result['encoding'],
                                              result['confidence'])
    else:
        return '%s: no result' % name
1166048
def guess_format(path):
    """"""
    for fmt in formats:
        if fmt.verify(path):
            return fmt.__name__
    else:
        msg = "Undefined file format: '{}'".format(path)
        raise UnknownFileFormatError(msg)
540859
def roughsize(size, above=20, mod=10):
    """"""
    if size < above:
        return str(size)

    return "{:d}+".format(size - size % mod)
1204522
def randomString(length, chrs=None):
    """"""
    if chrs is None:
        return getBytes(length)
    else:
        n = len(chrs)
        return ''.join([chrs[randrange(n)] for _ in xrange(length)])
90783
def guess_infer_extent(gtf_file):
    
    _, ext = os.path.splitext(gtf_file)
    tmp_out = tempfile.NamedTemporaryFile(suffix=".gtf", delete=False).name
    with open(tmp_out, "w") as out_handle:
        count = 0
        in_handle = utils.open_gzipsafe(gtf_file)
        for line in in_handle:
            if count > 1000:
                break
            out_handle.write(line)
            count += 1
        in_handle.close()
    db = gffutils.create_db(tmp_out, dbfn=":memory:", infer_gene_extent=False)
    os.remove(tmp_out)
    features = [x for x in db.featuretypes()]
    if "gene" in features and "transcript" in features:
        return False
    else:
        return True
157254
def _file_type(file):
    
    # %%%%%%%%%%%%%%%%%%%%%%%%%%%%% Verification of file type %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    if "." in file:  # File with known extension.
        file_type = file.split(".")[-1]
    else:  # File without known extension.
        file_type = magic.from_file(file, mime=True).split("/")[-1]

    return file_type