str.isalnum
str.isalnum(...)Description
Documentation for str.isalnum.
Real-World Examples
Practical code examples showing how str.isalnum is used in real projects.
return headers
def _get_cache_path(self, cache_key):
"""Get the path for a cached item"""
# Create a safe filename from the cache key
safe_key = "".join(c if c.isalnum() else "_" for c in cache_key)
return self.cache_dir / f"{safe_key}.json"
def _get_from_cache(self, cache_key):
"""
Get an item from the cache
Args:
cache_key (str): Cache key
Returns:
dict: Cached data or None if not found or expired
"""
cache_path = self._get_cache_path(cache_key)
if not cache_path.exists():
return None
try:
with open(cache_path, "r") as f:
Example 2
From NaveenRagunathan/ai-hiting-agent (src/connectors/github_agent/search_query_generator.py)
class SearchQueryGenerator:
@staticmethod
def _clean_query_term(term: str) -> str:
"""Clean and encode query terms."""
# Remove special characters that might break the query
term = ''.join(c for c in term if c.isalnum() or c in ['-', '_', '.', ' '])
# Replace spaces with hyphens for topics and encode the rest
return urllib.parse.quote_plus(term.strip())
@staticmethod
def _build_search_terms(terms: Union[str, List[str]], field: str = None) -> List[str]:
"""Build search terms with optional field prefix."""
if not terms:
return []
if isinstance(terms, str):
terms = [terms]
search_terms = []
for term in terms:
if not term or term.lower() == 'unspecified':
continue
cleaned = SearchQueryGenerator._clean_query_term(term)
if not cleaned: