Package pyfics :: Package parser :: Module dummyparser
[hide private]

Source Code for Module pyfics.parser.dummyparser

 1  #!/usr/bin/env python 
 2  # -*- coding: utf-8 -*- 
 3  # vim: set sw=4 ts=4 sts=4 et tw=79 : 
 4  # Copyright 2006-2007 Ali Polatel <polatel@gmail.com> 
 5  # Distributed under the terms of the GNU General Public License v3 
 6   
 7  """pyfics dummy parser 
 8   
 9  This module is provided as an example and for test usage. 
10  """ 
11   
12  from pyfics.parser import * 
13  from pyparsing import Literal, Regex 
14   
15 -def on_login():
16 """Callback function for login""" 17 protocol.transport.write(conn.username)
18 -def on_password():
19 """Callback function for password""" 20 protocol.transport.write(conn.password) 21 mainparser = parser
22 23 login = Literal("login: ") 24 """login parser 25 @type: pyparsing.Literal""" 26 password = Literal("password: ") 27 """password parser 28 @type: pyparsing.Literal""" 29 unknown = Regex('.*') 30 """parser to match the rest 31 @type: pyparsing.Literal""" 32 auth = login | password | unknown 33 """parser used while authentication 34 @type: pyparsing.Literal""" 35 parser = unknown 36 """parser used after authentication 37 @type: pyparsing.Literal""" 38 39 mainparser = auth 40
41 -def parse(line):
42 """parse function for L{IcsParsingProtocol}""" 43 return mainparser.parseString(line)
44