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()
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
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 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 read_properties(input_file_name): p = Properties() with open(input_file_name, 'rb') as f: p.load(f) return p
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 test_empty_len(): props = Properties() assert len(props) == 0 d = OrderedDict() props = Properties(d) assert len(props) == 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 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"}
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 __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()
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 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
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")]))
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")]))
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" }
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_setmeta_int(): p = Properties() p["a key"] = "the value", {"metakey": 42} out = BytesIO() p.store(out, strip_meta=False, timestamp=False) out.seek(0) assert out.read() == b"#: metakey=42\na\\ key=the value\n"
def test_newline_at_EOF(): """http://stackoverflow.com/a/729795""" f = NamedTemporaryFile(delete=False) prop = Properties(OrderedDict([("a", "b"), ("c", "d"), ("e", "f")])) prop.save(f.name) with open(f.name) as f: lastline = f.readlines()[-1] os.remove(f.name) assert lastline.endswith("\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_line_continuation_allowed(): p = Properties() p.load( StringIO(r""" multi\ line\ key = value """)) assert p.properties == {"multiline key": "value"}
def test_setmeta_bytes(): p = Properties() p["a key"] = "the value", {b"metakey": b"metaval", b"__internal": b"foo"} out = BytesIO() p.store(out, strip_meta=False, timestamp=False) out.seek(0) assert out.read() == b"#: metakey=metaval\na\\ key=the value\n"
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 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)
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 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 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)