You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					24 lines
				
				696 B
			
		
		
			
		
	
	
					24 lines
				
				696 B
			| 
											4 years ago
										 | import os
 | ||
|  | import errno
 | ||
|  | from typing import Dict, Tuple, Optional
 | ||
| 
											4 years ago
										 | 
 | ||
| 
											4 years ago
										 | _cached_attributes: Dict[Tuple, Optional[bytes]] = {}
 | ||
| 
											5 years ago
										 | 
 | ||
| 
											4 years ago
										 | def getxattr(path: str, attr_name: str) -> Optional[bytes]:
 | ||
|  |   key = (path, attr_name)
 | ||
|  |   if key not in _cached_attributes:
 | ||
|  |     try:
 | ||
|  |       response = os.getxattr(path, attr_name)
 | ||
|  |     except OSError as e:
 | ||
|  |       # ENODATA means attribute hasn't been set
 | ||
|  |       if e.errno == errno.ENODATA:
 | ||
|  |         response = None
 | ||
|  |       else:
 | ||
|  |         raise
 | ||
|  |     _cached_attributes[key] = response
 | ||
|  |   return _cached_attributes[key]
 | ||
| 
											5 years ago
										 | 
 | ||
| 
											4 years ago
										 | def setxattr(path: str, attr_name: str, attr_value: bytes) -> None:
 | ||
| 
											4 years ago
										 |   _cached_attributes.pop((path, attr_name), None)
 | ||
|  |   return os.setxattr(path, attr_name, attr_value)
 |