Sanitize special characters which could impact the import process
174745
private Object sanitize(final Object o) {
        if (!(o instanceof String)) {
            return o;
        } else {
            // Use Python3 way of escaping characters: https://docs.python.org/3.3/howto/unicode.html#the-string-type
            return ((String) o).replace("\n", "\\N{LINE FEED}")
                               .replace("|", "\\N{VERTICAL LINE}");
        }
    }
702341
def _clean_for_xml(data):
    

    # If data is None or an empty string, don't bother
    if data:
        # This turns a string like "Hello…" into "Hello&#8230;"
        data = data.encode("ascii", "xmlcharrefreplace").decode("ascii")
        # However it's still possible that there are invalid characters in the string,
        # so simply remove any of those characters
        return _illegal_xml_chars_re.sub("", data)
    return data
943239
private String
sanitize(String str) {
	if (wordcase == CASE_UPPER)
		return str.toUpperCase();
	else if (wordcase == CASE_LOWER)
		return str.toLowerCase();
	return str;
}
73112
function sanitizeFalsies(obj) {
	var key;
	if (!obj._) {
		delete obj._;
		for (key in obj) {
			if (obj[key] === false) delete obj[key];
		}
	}
	return obj;
}
445080
def sanitize_filename(filename):
    
    sanitized_filename = re.sub(r'[/\\:*?"<>|]', '-', filename)
    sanitized_filename = sanitized_filename.replace('&', 'and')
    sanitized_filename = sanitized_filename.replace('"', '')
    sanitized_filename = sanitized_filename.replace("'", '')
    sanitized_filename = sanitized_filename.replace("/", '')
    sanitized_filename = sanitized_filename.replace("\\", '')

    # Annoying.
    if sanitized_filename[0] == '.':
        sanitized_filename = u'dot' + sanitized_filename[1:]

    return sanitized_filename
338607
private String sanitizeFilename(final String filename) {
        return filename.replace('/', '_').replace('\\', '_').replace(':', '_').replace('?', '_').replace('&', '_')
                .replace('=', '_').replace(' ', '_');
    }
702335
def sanitize(string):
    
    replace_chars = [
        ['\\', '-'], [':', '-'], ['/', '-'],
        ['?', ''], ['<', ''], ['>', ''],
        ['`', '`'], ['|', '-'], ['*', '`'],
        ['"', '\''], ['.', ''], ['&', 'and']
    ]
    for ch in replace_chars:
        string = string.replace(ch[0], ch[1])
    return string
1076294
function sanitize (msg) {
  if (typeof msg !== 'object') return null
  if (typeof msg.value !== 'object') return null
  if (typeof msg.value.content !== 'object') return null
  if (typeof msg.value.timestamp !== 'number') return null
  if (typeof msg.value.type !== 'string') return null
  return msg
}
463712
function SanitizeCtx(ctx) {
  let r = {};
  for (const key in ctx) {
    if (!key.startsWith('_')) {
      r[key] = ctx[key];
    }
  }
  return r;
}
983435
def sanitize(meta, diagnostics=False):
    
    bad_encodings, bad_fields = set(), set()

    def sane_encoding(field, text):
        "Transcoding helper."
        for encoding in ('utf-8', meta.get('encoding', None), 'cp1252'):
            if encoding:
                try:
                    u8_text = text.decode(encoding).encode("utf-8")
                    if encoding != 'utf-8':
                        bad_encodings.add(encoding)
                        bad_fields.add(field)
                    return u8_text
                except UnicodeError:
                    continue
        else:
            # Broken beyond anything reasonable
            bad_encodings.add('UNKNOWN/EXOTIC')
            bad_fields.add(field)
            return str(text, 'utf-8', 'replace').replace('\ufffd', '_').encode("utf-8")

    # Go through all string fields and check them
    for field in ("comment", "created by"):
        if field in meta:
            meta[field] = sane_encoding(field, meta[field])

    meta["info"]["name"] = sane_encoding('info name', meta["info"]["name"])

    for entry in meta["info"].get("files", []):
        entry["path"] = [sane_encoding('file path', i) for i in entry["path"]]

    return (meta, bad_encodings, bad_fields) if diagnostics else meta
366519
def _sanitize_column_names(data):
    """"""
    new_names = {}
    for name in data.columns:
        new_names[name] = _ILLEGAL_CHARACTER_PAT.sub("_", name)
    return new_names
883387
def sanitize(text)
      text.gsub!(/[^a-z ]/i, '')
      text.gsub!(/((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/, '')
      text.gsub!(/(?=\w*h)(?=\w*t)(?=\w*t)(?=\w*p)\w*/, '')
      text.gsub!(/\s\s+/, ' ')

      text.downcase    
    end
452709
def sanitize_config
      {
        elements: %w(
          p br a span sub sup strong em div hr abbr s
          ul ol li
          blockquote cite pre code kbd
          h1 h2 h3 h4 h5 h6
          img object param del
          table tr td th thead tbody
          figure figcaption
          mark del ins
        ),
        attributes: {
          :all     => ['class', 'style', 'title', 'id', 'datetime'],
          'a'      => ['href', 'rel', 'name'],
          'li'     => ['id'],
          'sup'    => ['id'],
          'img'    => ['src', 'title', 'alt', 'width', 'height'],
          'object' => ['width', 'height'],
          'param'  => ['name', 'value'],
          'embed'  => ['allowscriptaccess', 'width', 'height', 'src'],
          'iframe' => ['width', 'height', 'src'],
          'td'     => ['colspan', 'rowspan'],
          'th'     => ['colspan', 'rowspan']
        },
        protocols: {
          'a' => { 'href' => ['ftp', 'http', 'https', 'mailto', '#fn', '#fnref', :relative] },
          'img' => {'src'  => ['http', 'https', :relative]},
          'iframe' => {'src'  => ['http', 'https']},
          'embed' => {'src'  => ['http', 'https']},
          'object' => {'src'  => ['http', 'https']},
          'li' => {'id' => ['fn']},
          'sup' => {'id' => ['fnref']}
        },
        transformers: transformers
      }
    end
911797
def remove_not_allowed_chars(savepath):
        
        split_savepath = os.path.splitdrive(savepath)
        # https://msdn.microsoft.com/en-us/library/aa365247.aspx
        savepath_without_invalid_chars = re.sub(r'<|>|:|\"|\||\?|\*', '_',
                                                split_savepath[1])
        return split_savepath[0] + savepath_without_invalid_chars
549546
def _sanitize_value(value):
    ''''''
    # dump dict into compated
    if isinstance(value, dict):
        new_value = []
        new_value.append('(')
        for k, v in value.items():
            new_value.append(k)
            new_value.append('=')
            new_value.append(v)
            new_value.append(',')
        new_value.append(')')
        return "".join(six.text_type(v) for v in new_value).replace(',)', ')')
    elif isinstance(value, list):
        new_value = []
        new_value.append('(')
        for item in value:
            if isinstance(item, OrderedDict):
                item = dict(item)
                for k, v in item.items():
                    new_value.append(k)
                    new_value.append('=')
                    new_value.append(v)
            else:
                new_value.append(item)
            new_value.append(',')
        new_value.append(')')
        return "".join(six.text_type(v) for v in new_value).replace(',)', ')')
    else:
        # note: we can't use shelx or pipes quote here because it makes zonecfg barf
        return '"{0}"'.format(value) if ' ' in value else value
937636
def sanitize_qualifiers(repos=None, followers=None, language=None):
    '''
    
    '''
    qualifiers = ''

    if repos:
        qualifiers += 'repos:{0} '.format(repos)
        qualifiers = re.sub(r"([+])([=a-zA-Z0-9]+)", r">\2", qualifiers)
        qualifiers = re.sub(r"([-])([=a-zA-Z0-9]+)", r"<\2", qualifiers)

    if followers:
        qualifiers += 'followers:{0} '.format(followers)
        qualifiers = re.sub(r"([+])([=a-zA-Z0-9]+)", r">\2", qualifiers)
        qualifiers = re.sub(r"([-])([=a-zA-Z0-9]+)", r"<\2", qualifiers)

    try:
        if language in ALLOWED_LANGUAGES and not language == '':
            qualifiers += 'language:{0} '.format(language)
        elif language == '':
            qualifiers += ''
        else:
            raise AllowedLanguagesException
    except AllowedLanguagesException as e:
        print(e)

    return qualifiers
1297720
def _sanitize_instance_name(name, max_length):
    
    name = str(name).lower()                # make all letters lowercase
    name = re.sub(r'[^-a-z0-9]', '', name)  # remove invalid characters
    # remove non-lowercase letters from the beginning
    name = re.sub(r'^[^a-z]+', '', name)
    name = name[:max_length]
    name = re.sub(r'-+$', '', name)         # remove hyphens from the end
    return name