Example #1
0
def test_loads_u_space_eof():
    with pytest.raises(InvalidUEscapeError) as excinfo:
        loads('bad = \\u ')
    assert excinfo.value.escape == '\\u '
    assert str(excinfo.value) == 'Invalid \\u escape sequence: \\u '
    with pytest.raises(InvalidUEscapeError) as excinfo:
        loads('\\u  = bad')
    assert excinfo.value.escape == '\\u'
    assert str(excinfo.value) == 'Invalid \\u escape sequence: \\u'
Example #2
0
def test_loads_u_invalid_hex():
    with pytest.raises(InvalidUEscapeError) as excinfo:
        loads('bad = \\uxabc')
    assert excinfo.value.escape == '\\uxabc'
    assert str(excinfo.value) == 'Invalid \\u escape sequence: \\uxabc'
    with pytest.raises(InvalidUEscapeError) as excinfo:
        loads('\\uxabc = bad')
    assert excinfo.value.escape == '\\uxabc'
    assert str(excinfo.value) == 'Invalid \\u escape sequence: \\uxabc'
    def _read_single(self, lines):
        """
        Reads the spectra from the lines.

        :param lines: the list of strings to parse
        :type lines: list
        :return: the list of spectra
        :rtype: list
        """

        # split sample data and spectral data
        comments = True
        sample = []
        data = []
        for i in range(len(lines)):
            if comments and lines[i].startswith(COMMENT):
                sample.append(lines[i])
            elif lines[i].startswith(HEADER):
                comments = False
                continue
            elif not comments:
                data.append(lines[i])

        # sample data
        for i in range(len(sample)):
            sample[i] = sample[i][2:]
        props = loads("".join(sample))
        id = "noid"
        if FIELD_SAMPLE_ID in props:
            id = str(props[FIELD_SAMPLE_ID])
        sampledata = {}
        for k in props:
            if k.endswith(DATATYPE_SUFFIX):
                continue
            v = props[k]
            t = "U"
            if k + DATATYPE_SUFFIX in props:
                t = props[k + DATATYPE_SUFFIX]
            if t == "N":
                sampledata[k] = float(v)
            elif t == "B":
                sampledata[k] = bool(v)
            else:
                sampledata[k] = str(v)
        if FIELD_INSTRUMENT not in sampledata:
            sampledata[FIELD_INSTRUMENT] = self.instrument
        if not self.keep_format:
            sampledata[FIELD_FORMAT] = self.format

        # spectral data
        waves = []
        ampls = []
        for line in data:
            if "," in line:
                (wave, ampl) = line.split(",")
                waves.append(float(wave))
                ampls.append(float(ampl))

        return Spectrum(id, waves, ampls, sampledata)
Example #4
0
    def __get_environment(self):

        settings = None

        with open(self.__ENV_FILE, "r") as file:
            settings = file.read()
            file.close()

        return loads(settings)
Example #5
0
def test_loads_utf8_bytes():
    assert loads(b'key=value\n'
                 b'edh=\xC3\xB0\n'
                 b'snowman=\xE2\x98\x83\n'
                 b'goat=\xF0\x9F\x90\x90') == {
                     'key': 'value',
                     'edh': '\xC3\xB0',
                     'snowman': '\xE2\x98\x83',
                     'goat': '\xF0\x9F\x90\x90',
                 }
Example #6
0
def disable_tls13():
    security_file = "/usr/lib/jvm/default-jvm/jre/conf/security/java.security"

    with open(security_file) as f:
        data = javaproperties.loads(f.read())

        if "TLSv1.3" in data["jdk.tls.disabledAlgorithms"]:
            return

    with open(security_file, "w") as f:
        data["jdk.tls.disabledAlgorithms"] = "TLSv1.3, " + data[
            "jdk.tls.disabledAlgorithms"]
        f.write(javaproperties.dumps(data))
Example #7
0
def test_loads_u_hex_sep():
    with pytest.raises(InvalidUEscapeError) as excinfo:
        loads('\\uab=bad')
    assert excinfo.value.escape == '\\uab'
    assert str(excinfo.value) == 'Invalid \\u escape sequence: \\uab'
    with pytest.raises(InvalidUEscapeError) as excinfo:
        loads('\\uab:bad')
    assert excinfo.value.escape == '\\uab'
    assert str(excinfo.value) == 'Invalid \\u escape sequence: \\uab'
    with pytest.raises(InvalidUEscapeError) as excinfo:
        loads('\\uab bad')
    assert excinfo.value.escape == '\\uab'
    assert str(excinfo.value) == 'Invalid \\u escape sequence: \\uab'
Example #8
0
def loads(string, fmt):

    if fmt == constants.JSON:

        # we are using 'yaml' here instead of 'json' because json
        # parses the keys as unicode objects (instead of string,
        # see https://stackoverflow.com/questions/956867/how-to-get-string-objects-
        # instead-of-unicode-from-json),
        # which causes a problem with flatdict in identifying complex keys. (see flatdict.py#_
        # has_delimiter (json is a sub-set of yaml so it works)

        return yaml.safe_load(string)

    elif fmt == constants.YAML:

        return yaml.safe_load(string)

    elif fmt == constants.PROPERTIES:

        return javaproperties.loads(string)

    elif fmt == constants.INI:

        dictionary = {}
        ini_parser = configparser.ConfigParser()
        ini_parser.read_string(six.u(string))

        for section in ini_parser.sections():
            section = str(section)
            dictionary[section] = {}
            for key in ini_parser.options(section):
                key = str(key)
                dictionary[section][key] = ini_parser.get(section=section,
                                                          option=key)

        return dictionary

    else:

        raise exceptions.UnsupportedFormatException(fmt=fmt)
Example #9
0
def loads(string, fmt):

    if fmt == constants.JSON:

        # we are using 'yaml' here instead of 'json' because json
        # parses the keys as unicode objects (instead of string,
        # see https://stackoverflow.com/questions/956867/how-to-get-string-objects-
        # instead-of-unicode-from-json),
        # which causes a problem with flatdict in identifying complex keys. (see flatdict.py#_
        # has_delimiter (json is a sub-set of yaml so it works)

        return yaml.safe_load(string)

    elif fmt == constants.YAML:

        return yaml.safe_load(string)

    elif fmt == constants.PROPERTIES:

        return javaproperties.loads(string)

    elif fmt == constants.INI:

        dictionary = {}
        ini_parser = configparser.ConfigParser()
        ini_parser.read_string(six.u(string))

        for section in ini_parser.sections():
            section = str(section)
            dictionary[section] = {}
            for key in ini_parser.options(section):
                key = str(key)
                dictionary[section][key] = ini_parser.get(section=section, option=key)

        return dictionary

    else:

        raise exceptions.UnsupportedFormatException(fmt=fmt)
Example #10
0
def test_loads_escaped_u():
    assert loads('key=\\\\u2603') == {"key": "\\u2603"}
Example #11
0
def test_loads_nothing():
    assert loads('') == {}
Example #12
0
def test_loads_key_unicode_space_value():
    assert loads('key\\u0020value') == {"key value": ""}
Example #13
0
def test_loads_continued_value():
    assert loads('key = val\\\nue') == {"key": "value"}
Example #14
0
def test_loads_bang_comment_key_value():
    assert loads('!This is a comment.\nkey = value') == {"key": "value"}
Example #15
0
def test_loads_comment():
    assert loads('#This is a comment.') == {}
Example #16
0
def test_loads_crlf():
    assert loads('\r\n') == {}
Example #17
0
def test_loads_simple():
    assert loads('key=value') == {"key": "value"}
Example #18
0
def test_loads_escaped_u_invalid():
    assert loads('key=\\\\u260x') == {"key": "\\u260x"}
Example #19
0
def test_loads_space_equals_space():
    assert loads(' = ') == {"": ""}
Example #20
0
def test_loads_space():
    assert loads(' ') == {}
Example #21
0
def test_loads_equals_only():
    assert loads('=') == {"": ""}
Example #22
0
def test_loads_linefeed():
    assert loads('\n') == {}
Example #23
0
def test_loads_u_u_escape_escape():
    with pytest.raises(InvalidUEscapeError) as excinfo:
        loads('bad = \\uab\\u0063d')
    assert excinfo.value.escape == '\\uab\\u'
    assert str(excinfo.value) == 'Invalid \\u escape sequence: \\uab\\u'
Example #24
0
def test_loads_cr():
    assert loads('\r') == {}
Example #25
0
def test_loads_u_extra():
    assert loads('the = \\u00f0e') == {"the": "\xF0e"}
    assert loads('\\u00f0e = the') == {"\xF0e": "the"}
Example #26
0
def test_loads_bang_comment():
    assert loads('!This is a comment.') == {}
Example #27
0
def test_loads_big_U_escape():
    assert loads('goat = \\U0001F410') == {"goat": "U0001F410"}
Example #28
0
def test_loads_key_value_bang_comment():
    assert loads('key = value\n!This is a comment.') == {"key": "value"}
Example #29
0
def test_loads_key_unicode_eq_value():
    assert loads('key\\u003Dvalue') == {"key=value": ""}
Example #30
0
    "Opcional, informe se deseja que o connector aponte para outro Schema Registry, por exemplo de cloud"
)
args = parser.parse_args()

# pega o nome e pasta do arquivo .properties
nome_extensao = os.path.basename(args.arquivo)
folder = os.path.dirname(args.arquivo)
nome = os.path.splitext(nome_extensao)[0]

# converte arquivo .properties para .json para envio no REST
# Read file
with open(args.arquivo, 'r') as f:
    properties_file = f.read()

# Load properties do json
json_file = javaproperties.loads(properties_file)
json_file_original = json_file
json_connector = {}
json_connector['name'] = json_file['name']
del json_file['name']

if args.schema_registry_cloud != None:
    json_file[
        'key.converter.schema.registry.url'] = 'http://' + args.schema_registry_cloud
    json_file[
        'value.converter.schema.registry.url'] = 'http://' + args.schema_registry_cloud

json_connector['config'] = json_file
json_connector_file = json.dumps(json_connector, indent=4, sort_keys=True)
#print(json_connector_file)
Example #31
0
def test_loads_key_unicode_colon_value():
    assert loads('key\\u003Avalue') == {"key:value": ""}