def _load_category_file(self, category_file_path):
     category_input_stream = FileUtils.getResourceAsStream(
         category_file_path)
     self.assertNotEquals(category_input_stream, None)
     json_translator = JsonStreamTranslator(category_file_path,
                                            category_input_stream)
     return json_translator.parse()
 def testEscapeBackslash(self):
     # JSON "xy\\.z" should become String "xy\.z"
     text = "{ \"abc\": \"xy\\\\.z\" }"
     stream = ByteArrayInputStream(text.encode('utf-8'))
     json_translator = JsonStreamTranslator("String", stream)
     result = json_translator.parse()
     abc = result['abc']
     self.assertEquals("xy\\.z", abc, "Should be single slash")
def _initialize_password_field_names():
    """
    Initialize the password field names structure.
    :raises: EncryptionException: if an error occurs while loading and parsing the password field names file
    """
    global _password_field_names
    _method_name = '_initialize_password_field_names'

    if _password_field_names is None:
        password_field_names_stream = FileUtils.getResourceAsStream(_password_field_names_file)
        if password_field_names_stream is None:
            ex = exception_helper.create_encryption_exception('WLSDPLY-04100', _password_field_names_file)
            _logger.throwing(ex, class_name=_class_name, method_name=_method_name)
            raise ex

        try:
            password_field_names_dict = \
                JsonStreamTranslator(_password_field_names_file, password_field_names_stream).parse()
        except JsonException, je:
            ex = exception_helper.create_encryption_exception('WLSDPLY-04101', _password_field_names_file,
                                                              je.getLocalizedMessage(), error=je)
            _logger.throwing(ex, class_name=_class_name, method_name=_method_name)
            raise ex

        if password_field_names_dict is not None and 'passwordFieldNames' in password_field_names_dict:
            _password_field_names = password_field_names_dict['passwordFieldNames']
        else:
            ex = exception_helper.create_encryption_exception('WLSDPLY-04102', _password_field_names_file)
            _logger.throwing(ex, class_name=_class_name, method_name=_method_name)
            raise ex
Пример #4
0
def get_dictionary_from_json_file(json_file_name):
    """
    Load the dictionary with the generated folder and attribute information from the provided location.
    :param json_file_name: path and name of the generated file
    :return: loaded dictionary or None if unable to parse and load the file
    """
    _method_name = 'get_dictionary_from_json_file'
    __logger.entering(json_file_name,
                      class_name=CLASS_NAME,
                      method_name=_method_name)
    print 'THE FILE NAME IS ', json_file_name
    json_input_stream = FileInputStream(File(json_file_name))
    json_translator = JsonStreamTranslator(json_file_name, json_input_stream)
    dictionary = None
    try:
        dictionary = json_translator.parse()
    except JsonException, je:
        __logger.severe('WLSDPLYST-01317',
                        json_file_name,
                        je.getLocalizedMessage(),
                        class_name=CLASS_NAME,
                        method_name=_method_name)