def __init__(self): config_file_name = 'backtesting_the_dow.properties' try: # Read properties properties = Properties() with open(config_file_name, "rb") as f: properties.load(f, "utf-8") # MySQL self.mysql_user = properties.properties['mysql.user'] self.mysql_password = properties.properties['mysql.password'] self.mysql_host = properties.properties['mysql.host'] self.mysql_port = properties.properties['mysql.port'] self.mysql_database = properties.properties['mysql.database'] except: logging.error("Error reading config file {0}: {1}".format(config_file_name, str(sys.exc_info()))) sys.exit(1) try: self.mysql_connection = mysql.connector.connect(user=self.mysql_user, password=self.mysql_password, host=self.mysql_host, database=self.mysql_database, port=self.mysql_port) logging.info("Connected to MySQL host: {0}, port: {1}, database: {2}".format(self.mysql_host, self.mysql_port, self.mysql_database)) except: logging.error("Error connecting to MySQL: {0}".format(str(sys.exc_info()))) sys.exit(1)
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 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)
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)
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")
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()
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}
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
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')
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 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"}
def read_properties(input_file_name): p = Properties() with open(input_file_name, 'rb') as f: p.load(f) return p
class Dictionary: def __init__(self,folder = './annotation/', topic='endpoint'): self.lookup = Properties() self.topic=topic self.folder = folder self.loadDictionary() def loadDictionary(self): prop_file= self.folder + self.topic + ".properties" try: with open(prop_file, "rb") as f: self.lookup.load(f, "utf-8") except Exception as err: self.lookup = None print(err) def annotate(self,x): if self.lookup is None: return None x_=x.replace(" ","_").replace("\t","").upper().strip() if x in self.lookup: value, meta = self.lookup[x_] return value else: return x def getLink(self,ontouri): if ontouri.startswith("http"): return "http://bioportal.bioontology.org/ontologies/ENM/?p=classes&conceptid=" + ontouri else: return None
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
class FileReader: def __init__(self, pathFile): self.configs = Properties() with open(pathFile, 'rb') as config_file: self.configs.load(config_file) def getProp(self, key): return (f'{self.configs.get(key).data}')
def test_basic_whitespace(): p = Properties() p.load('''fruits apple, banana, pear, \\ cantaloupe, watermelon, \\ kiwi, mango''') assert p.properties == {'fruits': 'apple, banana, pear, cantaloupe, ' 'watermelon, kiwi, mango'}
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, *args, **kwargs): p = Properties() with open( os.path.dirname(os.path.realpath(__file__)) + "/mongodb.properties", "rb") as f: p.load(f, "utf-8") self.username, metadata = p["username"] self.password, metadata = p["password"]
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)
def test_surrogate_high_without_low__garbage(): p = Properties() with pytest.raises(ParseError) as excinfo: p.load(BytesIO(b"surrogate=Muuusic \\ud834 foobar\n")) # Caused by garbage after the first unicode escape assert "High surrogate unicode escape sequence not followed by" in str( excinfo.value)
def test_surrogate_high_without_low__eof(): p = Properties() with pytest.raises(ParseError) as excinfo: p.load(BytesIO(b"surrogate=Muuusic \\ud834\n")) # Caused by short read (read 1 byte, wanted 6) after the first unicode escape assert "High surrogate unicode escape sequence not followed by" in str( excinfo.value)
def load_graphs(props_dir): pd = Path(props_dir) props = Properties() for this_file in pd.iterdir(): if (this_file.is_file()): with open(this_file, "rb") as f: props.load(f, "utf-8") props.reset() return props
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"))
class PropertyTemplate: CHANGEME_VALUE_PREFIX = 'CHANGEME' 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 __checkExistingProps(self, extPropsPath): try: existConfig = Properties() with open(extPropsPath, 'rb') as f: existConfig.load(f, 'utf-8') self.existingProps.update(existConfig.properties) except FileNotFoundError: for key, val in self.config.properties.items(): if val.startswith(PropertyTemplate.CHANGEME_VALUE_PREFIX) == False: self.existingProps[key] = val def getParametersNotSet(self): params = {} for key, val in self.config.properties.items(): if val.startswith(PropertyTemplate.CHANGEME_VALUE_PREFIX): changemeArray = val.split('_') if len(changemeArray) == 1: params[key] = '' if key not in self.existingProps else self.existingProps[key] elif key in self.existingProps and len(self.existingProps[key]) > 0: params[key] = self.existingProps[key] else: cmd = changemeArray[1] if cmd.startswith('RAND'): try: length = int(cmd[len('RAND'): len(cmd)]) params[key] = base64.b64encode(secrets.token_bytes(length)).decode('utf-8') except ValueError: params[key] = '' return params def getOutputPropertiesFileName(self): return self.destPath def updateExistingProperty(self, key, value): self.existingProps[key] = value def updateExistingProperties(self, props): self.existingProps.update(props) def generatePropertiesFile(self): p = Properties() p.properties.update(self.existingProps) with open(self.destPath, 'wb') as f: p.store(f, encoding='utf-8')
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"))
def test_line_continuation_allowed(): p = Properties() p.load( StringIO(r""" multi\ line\ key = value """)) assert p.properties == {"multiline key": "value"}
def get_map_for_lang(lang): path = "AppConstants_%s.properties" % lang p = Properties() res = {} with open(path, "rb") as f: p.load(f, "utf-8") for key in p: val, meta = p[key] res[key] = val return res
def get_connection(): properties = Properties() with open("environment.properties", "rb") as f: properties.load(f, "utf-8") return psycopg2.connect(host=properties.get('HOST').data, port=int(properties.get('PORT').data), database=properties.get('DATABASE').data, user=properties.get('USER').data, password=properties.get('PASSWORD').data)
def test_basic_whitespace(): p = Properties() p.load('''fruits apple, banana, pear, \\ cantaloupe, watermelon, \\ kiwi, mango''') assert p.properties == { 'fruits': 'apple, banana, pear, cantaloupe, ' 'watermelon, kiwi, mango' }
def getconfigdata(propertyname): log = Logger.getlogger() try: configs = Properties() with open(path, 'rb') as config_file: configs.load(config_file) return configs.get(propertyname).data except Exception as e: log.exception("Exception Occurred", exc_info=True)
def test_surrogate_high_without_low__eof(): p = Properties() with pytest.raises(ParseError) as excinfo: p.load( StringIO(b"surrogate=Muuusic \\ud834\n") ) # Caused by short read (read 1 byte, wanted 6) after the first unicode escape assert "High surrogate unicode escape sequence not followed by" in str(excinfo.value)
def test_surrogate_high_without_low__garbage(): p = Properties() with pytest.raises(ParseError) as excinfo: p.load( StringIO(b"surrogate=Muuusic \\ud834 foobar\n") ) # Caused by garbage after the first unicode escape assert "High surrogate unicode escape sequence not followed by" in str(excinfo.value)
class __ConfParams: configs = None def __init__(self): self.configs = Properties() with open('app-config.properties', 'rb') as config_file: self.configs.load(config_file) def getParam(self, name): return self.configs.get(name).data
def read_config(): global HOST, PORT config = Properties() with open('config.env', 'rb') as config_file: config.load(config_file) HOST = config.get("SOCKET_HOST").data PORT = int(config.get("SOCKET_PORT").data) ENCODING = config.get("ENCODING").data
def test_simple_escape_parsing(): p = Properties() p.load( StringIO("key value with a\\ttab\n" "foo ba\\r\n" "new li\\ne\n" "form \\feed seen!") ) assert p.properties == {"key": "value with a\ttab", "foo": "ba\r", "new": "li\ne", "form": "\feed seen!"}
def test_load_write_file(datadir, tmpdir): p = Properties() with datadir["simple.utf8.prop"].open("rb") as fh: p.load(fh, "utf-8") with tmpdir.join("dump.prop").open("w+b") as out: p.store(out, encoding="utf-8", timestamp=False) out.seek(0) assert out.read() == b"tästkey=This is the value\nanotherkey=Not mäny välues in this file\n"
def test_surrogate_high_followed_by_non_low_surrogate_uniescape(): p = Properties() with pytest.raises(ParseError) as excinfo: p.load( StringIO(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)
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 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 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", {})
def test_repeated_with_meta(): p = Properties() p.load(b""" key = value1 #: metakey = metaval1 #: metakey2 = metaval22 key = value2 # Expected: Metadata should ONLY contain the following # 'metakey' key. #: metakey = metaval2 key = value3 """) assert p.properties == {"key": "value3"} assert p["key"] == ("value3", {"metakey": "metaval2"})
def load_session(): if request.method == 'POST': # check if the post request has component_id in data if 'session_name' in request.form: session_name = request.form['session_name'] p = Properties() session_path = os.path.join(car_sessions_dir, session_name) _log_info("load session: " + session_path) with open(session_path, 'r') as f: p.load(f, "utf-8") session = p.properties fig_dir_ = session['figures.directory'] if fig_dir_: session['figures.directory'] = os.path.split(fig_dir_)[1] session = json.dumps(session) return session
def test_euro(out_encoding): p = Properties() # The euro symbol is not present in ASCII/ISO-8859-1, # so it should be encoded as "\u20ac". p["test"] = u"Euro: €" out = StringIO() p.store(out, encoding=out_encoding, timestamp=None) out.seek(0) assert out.read() == b"test=Euro\\: \\u20ac\n" # Read it back again: out.seek(0) p2 = Properties() p2.load(out) assert p2.properties == {u"test": u"Euro: €"}
def __init__(self): config_file_name = 'backtesting_the_dow.properties' try: # Read properties properties = Properties() with open(config_file_name, "rb") as f: properties.load(f, "utf-8") logging.debug("Read properties from " + config_file_name + ".") # MySQL self.mysql_user = properties.properties['mysql.user'] self.mysql_password = properties.properties['mysql.password'] self.mysql_host = properties.properties['mysql.host'] self.mysql_port = properties.properties['mysql.port'] self.mysql_database = properties.properties['mysql.database'] except: logging.error("Error reading config file {0}: {1}".format(config_file_name, str(sys.exc_info()))) sys.exit(1)
def __init__(self): # Read properties config_file_name = 'backtesting_the_dow.properties' properties = Properties() with open(config_file_name, "rb") as f: properties.load(f, "utf-8") self.base_url = "https://www.predictit.org/api/marketdata/ticker/" # MySQL self.mysql_user = properties.properties['mysql.user'] self.mysql_password = properties.properties['mysql.password'] self.mysql_host = properties.properties['mysql.host'] self.mysql_port = properties.properties['mysql.port'] self.mysql_database = properties.properties['mysql.database'] self.mysql_connection = mysql.connector.connect(user=self.mysql_user, password=self.mysql_password, host=self.mysql_host, database=self.mysql_database, port=self.mysql_port)
def get_document_keys(): if request.method == 'POST': if 'default_table_path' in request.form: keys = {} default_table_path_ = request.form['default_table_path'] if len(default_table_path_.strip(' /\\')) == 0: _log_info("No default table selected: Return empty key set.") return json.dumps(keys) _log_info("Get document keys from " + default_table_path_) keys['figure_keys'] = {} keys['default_keys'] = {} p = Properties() abs_default_table_path = os.path.join(car_default_tables_dir, default_table_path_) if os.path.isfile(abs_default_table_path): with open(abs_default_table_path, 'r') as f: p.load(f, "utf-8") else: _log_warning('The default table file ' + abs_default_table_path + ' does not exist.') props = p.properties return json.dumps(props)
def _test_deserialize(*data): for s, items in data: props = Properties() props.load(StringIO(s)) assert list(props.items()) == items
def test_property_node_update(): s = "key = value" props = Properties() props.load(StringIO(s)) props["key"] = "another_value" assert str(props) == "key = another_value"
def test_nokey_repeated(): p = Properties() p.load(b"= no key!\n: still no key!") assert p.properties == {"": "still no key!"} assert p[""] == ("still no key!", {})
def test_basic_key_trailing_space(): p = Properties() p.load("Truth :Beauty") assert p.properties == {"Truth": "Beauty"}
def test_basic_equals_sign(): p = Properties() p.load("Truth = Beauty\n") assert p.properties == {"Truth": "Beauty"}
def test_basic_key_only(): p = Properties() p.load('cheese\n') assert p.properties == {'cheese': ''}
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"}
def test_basic_colon_and_leading_whitespace(): p = Properties() p.load(" Truth:Beauty") assert p.properties == {"Truth": "Beauty"}
def test_nokey(): p = Properties() p.load(b"= no key!") assert p.properties == {"": "no key!"} assert p[""] == ("no key!", {})
def test_novalue(): p = Properties() p.load(br"no\ value!") assert p.properties == {"no value!": ""}