<commit_before># -*- coding: utf-8 -*-
#------------------------------------------------------------------------------
# file: $Id$
# auth: <NAME> <<EMAIL>>
# date: 2013/09/09
# copy: (C) Copyright 2013 Cadit Health Inc., All Rights Reserved.
#------------------------------------------------------------------------------

from pyramid.settings import aslist, asbool, truthy
from pyramid_controllers.util import adict, pick

from .isstr import isstr
from .resolve import resolve
from .reparse import reparse

falsy = frozenset(('f', 'false', 'n', 'no', 'off', '0'))
booly = frozenset(list(truthy) + list(falsy)) 

#------------------------------------------------------------------------------
def runFilters(filters, target, *args, **kw):
  if not target:
    return None
  if not filters:
    return target
  for filt in filters:
    target = filt(target, *args, **kw)
    if not target:
      break
  return target

#------------------------------------------------------------------------------
def tobool(val, force=True):
  if force or val.lower() in booly:
    return asbool(val)
  raise ValueError('invalid literal for tobool(): %r', (val,))

#------------------------------------------------------------------------------
def tolist(obj):
  if not obj:
    return []
  if isstr(obj):
    return aslist(obj)
  if isinstance(obj, (list, tuple)):
    return obj
  return [obj]

#------------------------------------------------------------------------------
# end of $Id$
#------------------------------------------------------------------------------<commit_msg>moved "tag" helper into utils<commit_after># -*- coding: utf-8 -*-
#------------------------------------------------------------------------------
# file: $Id$
# auth: <NAME> <<EMAIL>>
# date: 2013/09/09
# copy: (C) Copyright 2013 Cadit Health Inc., All Rights Reserved.
#------------------------------------------------------------------------------

import re, binascii
from pyramid.settings import aslist, asbool, truthy
from pyramid_controllers.util import adict, pick

from .isstr import isstr
from .resolve import resolve
from .reparse import reparse

falsy = frozenset(('f', 'false', 'n', 'no', 'off', '0'))
booly = frozenset(list(truthy) + list(falsy)) 

#------------------------------------------------------------------------------
def runFilters(filters, target, *args, **kw):
  if not target:
    return None
  if not filters:
    return target
  for filt in filters:
    target = filt(target, *args, **kw)
    if not target:
      break
  return target

#------------------------------------------------------------------------------
def tobool(val, force=True):
  if force or val.lower() in booly:
    return asbool(val)
  raise ValueError('invalid literal for tobool(): %r', (val,))

#------------------------------------------------------------------------------
def tolist(obj):
  if not obj:
    return []
  if isstr(obj):
    return aslist(obj)
  if isinstance(obj, (list, tuple)):
    return obj
  return [obj]

#------------------------------------------------------------------------------
tag_re = re.compile('[^a-zA-Z0-9]')
def tag_repl(match):
  return '_' + binascii.hexlify(match.group(0)).upper()
def tag(text):
  return tag_re.sub(tag_repl, text)

#------------------------------------------------------------------------------
# end of $Id$
#------------------------------------------------------------------------------
{'fraction_non_alphanumeric': 0.4390529085062847, 'fraction_numerical': 0.009061677871967261, 'mean_word_length': 1.0789793438639126, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '323355', 'n_tokens_mistral': 862, 'n_tokens_neox': 834, 'n_words': 260}