Pyton Programming Please help me describe the following code: a) The structure b) The overall feature it might provide c) The mechanisms used to provide the feature. class Config(object): validKeys = [ 'CompanyName', 'ExternalName', 'Hostname', 'Domain', 'SambaDomain' ] def __init__(self): profileLocator = open(os.path.join(Settings.BaseDir, 'currentProfile')) profileName = profileLocator.read().replace(' ', '').strip() self.configFile = os.path.join(Settings.BaseDir, 'profiles', profileName) self.cache = {} self.cacheAge = 0 self.maxAge = 300 def __getattr__(self, name): if name in self.validKeys: configAge = os.stat(self.configFile).st_mtime now = time.time() #Setup conditions stillValid = self.cacheAge == configAge tooOld = (now self. cacheAge) > self.maxAge if self.cache and stillValid and not tooOld: return self.cache[name] # Read the file (full unbuffered) cfo = open(self.configFile, 'rt') self.cacheAge = os.stat(self.configFile).st_mtime data = cfo.read() cfo.close() d = {} exec data in d self.cache = d return self.cache[name] else: object.__getattr__(self, name, value)
- If you need clarification, ask it in the comment box above.
- Better answers use proper spelling and grammar.
- Provide details, support with references or personal experience.
Tell us some more! Your answer needs to include more details to help people.You can't post answers that contain an email address.Please enter a valid email address.The email address entered is already associated to an account.Login to postPlease use English characters only.
Tip: The max point reward for answering a question is 15.
×