fa5d78f7511bb5b78e74cb11db881062d8f42e93,lexos/helpers/general_functions.py,,decode_bytes,#Any#,202

Before Change


        // Grab the file contents, which were encoded/decoded automatically
        // into python"s format
        decoded_string = raw_bytes.decode(encoding_type)
    return decoded_string.replace("\x00", "")

After Change


    bom16_le = str(codecs.BOM_UTF16_LE)
    bom16_be = str(codecs.BOM_UTF16_BE)
    if str(raw_bytes).startswith(bom16_le):
        decoded_string = raw_bytes[len(bom16_le):-1]
        decoded_string = decoded_string.replace("b"", "")
        decoded_string = decoded_string.replace("\\x00", "")
    elif str(raw_bytes).startswith(bom16_be):
        decoded_string = raw_bytes[len(bom16_be):-1]
        decoded_string = decoded_string.replace("b"", "")
        decoded_string = decoded_string.replace("\\x00", "")
    else:
        try:
            // try to use utf-8 to decode first
            encoding_type = "utf-8"
            // Grab the file contents, which were encoded/decoded automatically
            // into python"s format
            decoded_string = raw_bytes.decode(encoding_type)
        except UnicodeDecodeError:
            encoding_detect = chardet.detect(
                raw_bytes[:constants.MIN_ENCODING_DETECT])  // Detect the encoding
            encoding_type = encoding_detect["encoding"]
            // Grab the file contents, which were encoded/decoded automatically
            // into python"s format
            decoded_string = raw_bytes.decode(encoding_type)
    return decoded_string
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 5

Non-data size: 6

Instances


Project Name: WheatonCS/Lexos
Commit Name: fa5d78f7511bb5b78e74cb11db881062d8f42e93
Time: 2017-08-04
Author: delandaluce_alvaro@wheatoncollege.edu
File Name: lexos/helpers/general_functions.py
Class Name:
Method Name: decode_bytes


Project Name: comic/grand-challenge.org
Commit Name: 10be620ec5a250bc7b7a3ec89b956eb5ca6f8147
Time: 2013-07-25
Author: w.s.kerkstra@gmail.com
File Name: django/ckeditor/views.py
Class Name:
Method Name: get_media_url_project


Project Name: comic/grand-challenge.org
Commit Name: ea037c194cb1f8a2957276f8a72a43f8db3d5476
Time: 2013-07-25
Author: w.s.kerkstra@gmail.com
File Name: django/ckeditor/views.py
Class Name:
Method Name: get_media_url_project


Project Name: SPFlow/SPFlow
Commit Name: 558f7ff3f0d5ffcba377647bdfba7dfdc0793abd
Time: 2018-06-20
Author: molina@cs.tu-darmstadt.de
File Name: src/spn/io/CPP.py
Class Name:
Method Name: to_cpp


Project Name: estnltk/estnltk
Commit Name: b6d02838c356943ba246b7603272f5c719259d6e
Time: 2015-09-10
Author: tpetmanson@gmail.com
File Name: estnltk/prettyprinter/prettyprinter.py
Class Name: PrettyPrinter
Method Name: render