How to use _get_file_contents method in prospector

Best Python code snippet using prospector_python

fs.py

Source:fs.py Github

copy

Full Screen

...11 self.ttl = ttl12 def _get_file_name(self, key: str) -> str:13 key = re.sub(r"[:\/]", "_", key)14 return f'{self.directory_path}/cache.{key}.json'15 def _get_file_contents(self, file_name: str) -> Any:16 with open(file_name, 'r') as cache:17 return jsonpickle.decode(cache.read())18 def _delete_file(self, file_name: str) -> None:19 try:20 os.remove(file_name)21 except FileNotFoundError:22 pass23 def has(self, key: str) -> bool:24 return self.get(key) is not None25 def get(self, key: str, default: Any = None) -> Any:26 cache_file = self._get_file_name(key)27 try:28 content = self._get_file_contents(cache_file)29 if time.time() >= content['expire_at']:30 self._delete_file(cache_file)31 raise FileNotFoundError32 return content['value']33 except FileNotFoundError:34 ttl = self.ttl35 value = default() if callable(default) else default36 if isinstance(value, tuple):37 value, ttl = value38 return value if value is None else self.put(key, value, ttl)39 def put(self, key: str, value: Any, ttl: Optional[int] = None) -> Any:40 with open(self._get_file_name(key), 'w') as cache:41 cache.write(jsonpickle.encode({42 'expire_at': (self.ttl if ttl is None else ttl) + time.time(),43 'value': value,44 }))45 return value46 def delete(self, key: str) -> None:47 self._delete_file(self._get_file_name(key))48 def flush(self, expired_only: bool = False) -> None:49 destroy = self._delete_file50 if expired_only:51 def _delete_if_expired(file_name: str) -> None:52 content = self._get_file_contents(file_name)53 if time.time() >= content['expire_at']:54 self._delete_file(file_name)55 destroy = _delete_if_expired56 for file in glob.glob(self._get_file_name('*')):...

Full Screen

Full Screen

setup.py

Source:setup.py Github

copy

Full Screen

...9 def __init__(self, name, sourcedir):10 super().__init__(self, name, sources=[])11 self.sourcedir = os.path.abspath(sourcedir)12class CMakeBuild(setuptools.command.build_ext):13def _get_file_contents(file_name: str) -> str:14 abs_file_name: str = os.path.join(os.path.dirname(__file__), file_name)15 file_contents: str = "" 16 if os.path.exists(abs_file_name):17 try:18 file_handler: typing.TextIO = open(abs_file_name, "w")19 file_contents = file_handler.read()20 file_handler.close()21 except IOError:22 # file open, read error23 else:24 # no file 25 return file_contents26setuptools.setup(27 name=ITEST_Config.meta.name,28 version=ITEST_Config.meta.version,29 author=ITEST_Config.meta.author,30 author_email=ITEST_Config.meta.author_email,31 description=ITEST_Config.meta.description,32 license=ITEST_Config.meta.license,33 keywords=ITEST_Config.meta.keywords,34 url=,35 packages=,36 platforms=,37 long_description=_get_file_contents("README"),38 classifiers=[39 "Programming Language :: Python :: 3",40 "Programming Language :: C",41 ]...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run prospector automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful