home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1911 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  2.0 KB  |  59 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import re
  5. from IPython.hooks import CommandChainDispatcher
  6. import IPython.hooks as IPython
  7.  
  8. class StrDispatch(object):
  9.     
  10.     def __init__(self):
  11.         self.strs = { }
  12.         self.regexs = { }
  13.  
  14.     
  15.     def add_s(self, s, obj, priority = 0):
  16.         chain = self.strs.get(s, CommandChainDispatcher())
  17.         chain.add(obj, priority)
  18.         self.strs[s] = chain
  19.  
  20.     
  21.     def add_re(self, regex, obj, priority = 0):
  22.         chain = self.regexs.get(regex, CommandChainDispatcher())
  23.         chain.add(obj, priority)
  24.         self.regexs[regex] = chain
  25.  
  26.     
  27.     def dispatch(self, key):
  28.         if key in self.strs:
  29.             yield self.strs[key]
  30.         
  31.         for r, obj in self.regexs.items():
  32.             if re.match(r, key):
  33.                 yield obj
  34.                 continue
  35.         
  36.  
  37.     
  38.     def __repr__(self):
  39.         return '<Strdispatch %s, %s>' % (self.strs, self.regexs)
  40.  
  41.     
  42.     def s_matches(self, key):
  43.         if key not in self.strs:
  44.             return None
  45.         for el in self.strs[key]:
  46.             yield el[1]
  47.             key not in self.strs
  48.         
  49.  
  50.     
  51.     def flat_matches(self, key):
  52.         for val in self.dispatch(key):
  53.             for el in val:
  54.                 yield el[1]
  55.             
  56.         
  57.  
  58.  
  59.