Пример #1
0
def test_empty_len():
    props = Properties()
    assert len(props) == 0

    d = OrderedDict()
    props = Properties(d)
    assert len(props) == 0
Пример #2
0
def test_str():
    items = [("a", "b"), ("c", "d"), ("e", "f")]
    d = OrderedDict(items)
    props = Properties(d)
    props2 = Properties()
    props2.load(StringIO(str(props)))
    assert props == props2
def propsTranslator(separator, inputfile, languages):
    global CURR_LANGUAGE
    for curr in languages:
        CURR_LANGUAGE = curr
        props = Properties()
        with open(inputfile, 'rb') as f:
            props.load(f, encoding='utf-8')
            newProps = Properties()
            for k, v in props.items():
                print("translate: {} to language: {}".format(
                    v.data, CURR_LANGUAGE))
                response = client.translate_text(
                    parent=GOOGLE_PARENT_PROJECT,
                    mime_type="text/plain",
                    target_language_code=CURR_LANGUAGE,
                    contents=[v.data])
                trans = response.translations
                print("result: {} \n".format(trans[0].translated_text))
                newProps[k] = trans[0].translated_text

            base = os.path.basename(inputfile)
            filename = os.path.splitext(base)[0]
            with open(filename + separator + CURR_LANGUAGE + '.properties',
                      'wb') as newF:
                newProps.store(newF, encoding='utf-8')
Пример #4
0
def test_delete():
    items = [("a", "b"), ("c", "d"), ("e", "f")]
    d = OrderedDict(items)
    props = Properties(d)
    del props["a"]

    assert "a" not in props
    assert props == Properties(OrderedDict([("c", "d"), ("e", "f")]))
Пример #5
0
def test_update():
    """test MutableMapping derived method"""
    items = [("a", "b"), ("c", "d"), ("e", "f")]
    d = OrderedDict(items)
    props = Properties(d)
    props.update({"g": "h", "c": "i"})
    assert props == Properties(
        OrderedDict([("a", "b"), ("c", "i"), ("e", "f"), ("g", "h")]))
Пример #6
0
def test_save():
    properties = """
foo : bar
bar : baz
"""
    p = Properties()
    p2 = Properties()
    p.load(StringIO(properties))
    with NamedTemporaryFile(delete=False) as f:
        p.save(f.name)
    with open(f.name) as f:
        p2.load(f)
    os.remove(f.name)
    assert p == p2
def change_config(config_remote, config_file, fn):
    from jproperties import Properties
    read_props = Properties()
    write_props = Properties()

    if config_file is None:
        return
    with open(config_file, "r") as file:
        read_props.load(file)
    write_props = copy_exist(write_props, read_props)
    write_props = fn(write_props, read_props, config_remote)
    with open(config_file, "w") as wfile:
        write_props.reset()
        write_props.store(wfile)
def test_surrogate_roundtrip_utf8():
    p = Properties()
    p["surrogate"] = u"Muuusic \U0001D160"

    out = StringIO()
    p.store(out, encoding="utf-8", timestamp=None)

    out.seek(0)
    dumped = out.read()
    assert dumped == b"surrogate=Muuusic \xF0\x9D\x85\xA0\n"

    p2 = Properties()
    p2.load(dumped, "utf-8")

    assert p2["surrogate"] == (u"Muuusic \U0001D160", {})
def test_surrogate_roundtrip(out_encoding):
    p = Properties()
    p["surrogate"] = u"Muuusic \U0001D160"

    out = StringIO()
    p.store(out, encoding=out_encoding, timestamp=None)

    out.seek(0)
    dumped = out.read()
    assert dumped == b"surrogate=Muuusic \\ud834\\udd60\n"

    p2 = Properties()
    p2.load(dumped, out_encoding)

    assert p2["surrogate"] == (u"Muuusic \U0001D160", {})
Пример #10
0
    def __init__(self):
        self.driver=None
        self.chromeVersion=None
        self.config = Properties()

        self.dir = "driversEx"
        self.fileName="chromedriver_win32.zip"
        
        # path= {chromeVersion}
        self.driverDownloadUrl = None
        
        try:
            self.driver = webdriver.Chrome(self.dir+"/chromedriver")
            self.chromeVersion=self.driver.capabilities['browserVersion']
            self.driver.close()
        except SessionNotCreatedException as e:
            print("___________________________________________________")
            self.chromeVersion = e.args[0].split("Current browser version is ")[1].split(" ")[0]
            print("Compatible error")

        self.driverDownloadUrl = "https://chromedriver.storage.googleapis.com/"+self.chromeVersion+"/"+self.fileName
        
        f=open(self.dir+"/application.properties",'r+b')

        self.config.load(f)
        f.close()
        

        self.checkVersion()
Пример #11
0
 def __init__(self, folder='./annotation/', topic='endpoint', verbose=True):
     self.lookup = Properties()
     self.topic = topic
     self.folder = Path(folder)
     self.folder.mkdir(parents=True, exist_ok=True)
     self.verbose = verbose
     self.loadDictionary()
Пример #12
0
def get_endpoint_url(account_id):
    """returns the API endpoint by concatenating the base url and account_id
    
    Parameters:
    account_id (string)

    returns:
    string: endpoint url

    """
    request_url=''
    
    if account_id:
        configs = Properties() 
        with open('app-config.properties', 'rb') as config_file:
            configs.load(config_file)
            request_url = configs.get("REQUEST_URL").data.strip()
            
            # check for API url
            if request_url:
                return request_url + str(account_id).strip()
            else:
                raise ValueError ("Endpoint url cannot be None")
    else:
        raise ValueError ("account id cannot be None")
Пример #13
0
 def getChromeDriver(self):
     if WebDriver.__instance == None:
         print("creating new driver")
         options = webdriver.ChromeOptions()
         prop = Properties()
         with open('resources/properties/config.properties',
                   'rb') as config_file:
             prop.load(config_file)
         print(prop.get("ENV"))
         print(platform.system())
         if platform.system() == 'Linux':
             options.add_argument('--no-sandbox')
             options.add_argument('headless')
             options.add_argument('window-size=1200x600')
             options.add_argument('--disable-dev-shm-usage')
             self.driver = webdriver.Chrome(
                 executable_path='resources/drivers/chromedriver-linux',
                 chrome_options=options)
         elif platform.system() == 'Darwin':
             self.driver = webdriver.Chrome(
                 executable_path='resources/drivers/chromedriver-84',
                 chrome_options=options)
         else:
             self.driver = webdriver.Chrome(
                 executable_path='resources/drivers/chromedriver.exe',
                 chrome_options=options)
         self.driver.maximize_window()
         self.driver.implicitly_wait(5)
     else:
         print("using existing driver")
         return self.driver
Пример #14
0
def read_properties(input_file_name):

    p = Properties()
    with open(input_file_name, 'rb') as f:
        p.load(f)

    return p
Пример #15
0
def test_repeated():
    p = Properties()
    p.load(
        b"key:value\nkey=the value\nkey = value1\nkey : value2\nkey value3\nkey\tvalue4"
    )

    assert p.properties == {"key": "value4"}
Пример #16
0
    def execute(self, values):
        """Execution logic.

        Read LEMMA version from a Java properties file that specifies at least
        a "major", "minor", and "patch" entry.
        """

        filepath = values['filepath']
        if not os.path.isabs(filepath):
            filepath = os.path.join(self.get_target_directory(), filepath)

        p = Properties()
        with open(filepath, 'rb') as fd:
            p.load(fd)
        major = self._get_key(p, 'major')
        minor = self._get_key(p, 'minor')
        patch = self._get_key(p, 'patch')
        extra = self._get_key(p, 'extra')

        if not major or not minor or not patch:
            raise ValueError('Properties file "%s" must specify keys "major" \
                "minor" and "patch".')

        version = '%s.%s.%s' % (major, minor, patch)
        if extra:
            version += '.' + extra
        return {'version': version}
Пример #17
0
    def get_data_from_properties(self, file_path, key):
        self.prop = Properties()

        with open(file_path, 'rb') as config_file:
            self.prop.load(config_file, 'utf-8')

        return self.prop.get(key).data
Пример #18
0
def start_browser():
    configs = Properties()

    configs.load(open(os.path.join(PROJECT_ROOT, 'app.properties'), 'rb'))

    browser_name = configs.get("browser").data

    option = webdriver.ChromeOptions()
    option.add_argument('--no-sandbox')
    option.add_argument('--disable-gpu')
    option.add_argument('--window-size=1920,1080')
    option.add_argument('lang=ru')

    if browser_name == 'Chrome':
        driver = webdriver.Chrome(
            executable_path=CHROME_DRIVER_DICT[sys.platform], options=option)
    elif browser_name == 'Opera':
        driver = webdriver.Opera(
            executable_path=OPERA_DRIVER_DICT[sys.platform], options=option)
    elif browser_name == 'Yandex':
        driver = webdriver.Opera(
            executable_path=YANDEX_DRIVER_DICT[sys.platform], options=option)
    else:
        driver = webdriver.Chrome(
            executable_path=CHROME_DRIVER_DICT[sys.platform], options=option)

    yield driver

    if sys.exc_info():
        allure.attach(body=driver.get_screenshot_as_png(),
                      name='screenshot',
                      attachment_type=AttachmentType.PNG)

    driver.quit()
Пример #19
0
def properties_check(server, info, config_list):
    try:
        from jproperties import Properties
        p_list = Properties()
        with open(properties_path, "rb") as f:
            p_list.load(f)
        server.tell(
            info.player, system_return + "§eServer's §aport§r is §d[" +
            str(p_list.get('server-port').data) + ']§r')
        server.tell(
            info.player, system_return + "§eMCDR's§r §arcon port§r is §d[" +
            str(config_list['rcon_port']) + ']§r')
        server.tell(
            info.player, system_return + "§eServer's§r §arcon port§r is §d[" +
            str(p_list.get('rcon.port').data) + ']§r')
        if str(p_list.get('rcon.port').data) == str(config_list['rcon_port']):
            server.tell(info.player,
                        system_return + '§aRcon port§r are §bsame')
        else:
            error_msg(server, info.player, 1)
        if p_list.get('rcon.password').data == config_list['rcon_password']:
            server.tell(info.player,
                        system_return + '§aRcon password§r are §bsame')
        else:
            error_msg(server, info.player, 2)
    except ModuleNotFoundError:
        error_msg(server, info.player, 3)
Пример #20
0
def parse_and_store__artifact_display_name():
    for dir_path in software_directory_paths:
        language_path = SOFTWARES_PATH + dir_path + ARTIFACTS_LANG_PATH
        file_names = []
        for (dirpath, dirnames, filenames) in walk(language_path):
            file_names.extend(filenames)
            break
        for file_name in file_names:
            if (not file_name.endswith('_en_US.properties')) and (
                    not file_name.endswith('locale.properties')):
                continue

            configs = Properties()
            path = SOFTWARES_PATH + dir_path + ARTIFACTS_LANG_PATH + file_name
            # print("Artifact lang :path",path)
            with open(path, 'rb') as read_prop:
                configs.load(read_prop)
            prop_view = configs.items()
            for item in prop_view:
                if len(item[0].split('.')) > 1 and item[0].split(
                        '.')[1] == 'displayName':
                    display_name = configs.get(item[0]).data
                    artifact_id = item[0].split('.')[0].lower()
                    artifact_object[artifact_id] = Artifact(
                        artifact_id, display_name)
Пример #21
0
def parse_and_store__component_display_name():
    for dir_path in software_directory_paths:
        language_path = SOFTWARES_PATH + dir_path + COMPONENTS_LANG_PATH
        file_names = []
        for (dirpath, dirnames, filenames) in walk(language_path):
            file_names.extend(filenames)
            break
        for file_name in file_names:
            if (not file_name.endswith('_en_US.properties')) and (
                    not file_name.endswith('locale.properties')):
                continue
            configs = Properties()
            path = SOFTWARES_PATH + dir_path + COMPONENTS_LANG_PATH + file_name
            with open(path, 'rb') as read_prop:
                configs.load(read_prop)
            prop_view = configs.items()
            #print(type(prop_view))
            for item in prop_view:
                #print(item)
                if len(item[0].split('.')) > 1 and item[0].split(
                        '.')[1] == 'displayName' and item[0].split(
                            '.')[0] in component_object:
                    display_name = configs.get(item[0]).data
                    component_id = item[0].split('.')[0]
                    component_object[component_id].set_component_display_name(
                        display_name)
def load_properties():
    config = configparser.ConfigParser()
    properties = defaultdict()
    properties = Properties()
    with open(BASE_DIR + "\\webcrawler\\resources\\application_dev.properties", "rb") as f:
        properties.load(f, "iso-8859-1")

    return properties
Пример #23
0
def test_multiline_docstr_with_empty_comment_lines():
    p = Properties()
    p.load("K = V\n# A comment\n#   more comments\n#\n# trailer\n",
           metadoc=True)
    assert p.properties == {"K": "V"}
    assert p.getmeta("K") == {
        "_doc": "A comment\n  more comments\n\ntrailer\n"
    }
 def __init__(self, path):
     self.config = Properties()
     self.path = path
     self.destPath = path[0:len(path)-len('.template')]
     with open(path, 'rb') as f:
         self.config.load(f, 'utf-8')
     self.existingProps = {}
     self.__checkExistingProps(self.destPath)
def paymentProperties():
    configs = Properties()
    with open('payment.properties', 'rb') as config_file:
        configs.load(config_file)
    print('Service properties')
    print(configs.get("payment_service_type"))
    print(configs.get("payment_service_name"))
    print(configs.get("payment_service_description"))
    print(configs.get("payment_service_port"))
Пример #26
0
class ConfigMessage:

    configs = Properties()

    def __init__(self):

        with open('config/message-config.properties', 'rb') as config_file:

            self.configs.load(config_file)
Пример #27
0
class ConfigsDatabase:

    configs = Properties()

    def __init__(self):

        with open('config/upload-config.properties', 'rb') as config_file:
            
            self.configs.load(config_file)
Пример #28
0
def test_surrogate_high_followed_by_non_low_surrogate_uniescape():
    p = Properties()

    with pytest.raises(ParseError) as excinfo:
        p.load(BytesIO(b"surrogate=Muuusic \\ud834\\u000a\n"))

    # Caused by short read (read 1 byte, wanted 6) after the first unicode escape
    assert "Low surrogate unicode escape sequence expected after high surrogate escape sequence, but got " \
           "a non-low-surrogate unicode escape sequence" in str(excinfo.value)
Пример #29
0
def test_line_continuation_allowed():
    p = Properties()
    p.load(
        StringIO(r"""
            multi\
            line\ key = value
        """))

    assert p.properties == {"multiline key": "value"}
Пример #30
0
def getProp():
    configs = Properties()
    with open('fire.properties', 'rb') as config_file:
        configs.load(config_file)
    print('Service properties')
    print(configs.get("service_type"))
    print(configs.get("service_name"))
    print(configs.get("service_description"))
    print(configs.get("service_port"))