pvl/syslog/syslog.py
changeset 60 9326ed989645
parent 50 0bbe2e7561a1
child 63 510a9a944f5a
equal deleted inserted replaced
59:caed0ed82709 60:9326ed989645
    12         
    12         
    13         Implements an iterable mainloop doing continuous polling on the source, using either a timeout or
    13         Implements an iterable mainloop doing continuous polling on the source, using either a timeout or
    14         select():able source.
    14         select():able source.
    15     """
    15     """
    16     
    16     
    17     def __init__ (self, syslog, source, poll=None) :
    17     def __init__ (self, source, parser, filter, poll=None) :
    18         """
    18         """
    19             Using given underlying line source.
    19             Using given underlying line source.
    20                 
    20                 
    21                 syslog      - iterable
       
    22                 source      - source to select() if poll=True
    21                 source      - source to select() if poll=True
    23                 poll        - polling behaviour
    22                 poll        - polling behaviour
    24         """
    23         """
    25         
    24         
    26         self.syslog = syslog
       
    27         self.source = source
    25         self.source = source
       
    26         self.parser = parser
       
    27         self.filter = filter
       
    28 
    28         self._poll = poll
    29         self._poll = poll
       
    30 
       
    31     def syslog (self) :
       
    32         """
       
    33             Yield available input.
       
    34         """
       
    35 
       
    36         return self.filter(self.parser(self.source))
    29 
    37 
    30     def poll (self, poll=None) :
    38     def poll (self, poll=None) :
    31         """
    39         """
    32             Poll our source for input, with given polling behaviour:
    40             Poll our source for input, with given polling behaviour:
    33                 True    - select() on source
    41                 True    - select() on source
    79             poll = self._poll
    87             poll = self._poll
    80         
    88         
    81         # mainloop
    89         # mainloop
    82         while True :
    90         while True :
    83             # pull in messages
    91             # pull in messages
    84             for item in self.syslog :
    92             for item in self.syslog() :
    85                 log.debug("%s", item)
    93                 log.debug("%s", item)
    86                 yield item
    94                 yield item
    87             
    95             
    88             # poll
    96             # poll
    89             if poll :
    97             if poll :
    93                 # done
   101                 # done
    94                 break
   102                 break
    95 
   103 
    96         log.debug("exit")
   104         log.debug("exit")
    97 
   105 
    98     __iter__ = main