Best Python code snippet using avocado_python
cachefile.py
Source:cachefile.py  
...71                "Default cache file does not exist "72                "'{}'!".format(default_list_path)73            )74        return default_list_path75    def _get_writable_cache_dir(self):76        """77        Get writable cache directory with fallback to user's cache directory78        and global temp directory79        :raises: CacheFileError when cached directory is not writable for user80        :return: path to cache directory81        :rtype: str82        """83        dir_path_data = self._get_default_cache_dir()84        if os.access(dir_path_data, os.W_OK):85            self._default_cache_file = True86            return dir_path_data87        dir_path_user = user_cache_dir(self._URLEXTRACT_NAME)88        if not os.path.exists(dir_path_user):89            try:90                os.makedirs(dir_path_user, exist_ok=True)91            except PermissionError:92                # if PermissionError exception is raised we should continue93                # and try to set the last fallback dir94                pass95        if os.access(dir_path_user, os.W_OK):96            return dir_path_user97        dir_path_temp = tempfile.gettempdir()98        if os.access(dir_path_temp, os.W_OK):99            return dir_path_temp100        raise CacheFileError("Cache directories are not writable.")101    def _get_cache_file_path(self, cache_dir=None):102        """103        Get path for cache file104        :param str cache_dir: base path for TLD cache, defaults to data dir105        :raises: CacheFileError when cached directory is not writable for user106        :return: Full path to cached file with TLDs107        :rtype: str108        """109        if cache_dir is None:110            # Tries to get writable cache dir with fallback to users data dir111            # and temp directory112            cache_dir = self._get_writable_cache_dir()113        else:114            if not os.access(cache_dir, os.W_OK):115                raise CacheFileError("None of cache directories is writable.")116        # get directory for cached file117        return os.path.join(cache_dir, self._CACHE_FILE_NAME)118    def _get_cache_lock_file_path(self, cache_dir=None):119        """120        Get path for cache file lock121        :param str cache_dir: base path for TLD cache lock, defaults to data dir122        :raises: CacheFileError when cached directory is not writable for user123        :return: Full path to cached file lock124        :rtype: str125        """126        return self._get_cache_file_path(cache_dir)+'.lock'...db.py
Source:db.py  
...21class MyURLExtractor(URLExtract):22    cache_dir = None 23    def set_cache_dir(self, dir):24        self.cache_dir = dir25    def _get_writable_cache_dir(self):26        if self.cache_dir:27            return self.cache_dir28        else:29            return "/tmp"30def put_db(text):31    extractor = MyURLExtractor(cache_dns=False, cache_dir='/tmp/')32    urls = extractor.find_urls(text)33    if len(urls) == 0:34        return "Give me 'url and memo` to record."35    36    # Remove URL from the text and make it to comment37    comment = text38    for url in urls:39        comment = comment.replace(url, "")...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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
