Author: ArcRiley
Date: 2009-01-09 18:04:06 -0500 (Fri, 09 Jan 2009)
New Revision: 1455

Added:
   trunk/concordance/examples/register.py
Log:
a partial example of in-band registration


Copied: trunk/concordance/examples/register.py (from rev 1448, 
trunk/concordance/examples/echo.py)
===================================================================
--- trunk/concordance/examples/register.py                              (rev 0)
+++ trunk/concordance/examples/register.py      2009-01-09 23:04:06 UTC (rev 
1455)
@@ -0,0 +1,73 @@
+#!/usr/bin/env python3.0
+
+''' Simple Concordance server that handles user registration using xml.etree'''
+
+__credits__ = '''Copyright (C) 2009 Copyleft Games Group
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU Affero General Public License as published
+    by the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU Affero General Public License for more details.
+
+    You should have received a copy of the GNU Affero General Public License
+    along with this program; if not, see http://www.gnu.org/licenses
+'''
+__author__  = 'Copyleft Games Group'
+__date__    = 'Last change on '+ \
+              '$Date$'[7:-20]+ \
+              'by '+'$Author$'[9:-2]
+__version__ = 'Trunk (r'+'$Rev$'[6:-2]+')'
+
+
+import concordance
+from xml.etree import ElementTree
+
+class regcore(concordance.Core) :
+  def getquery(self, query, out_root) :
+    if query.tag == '{jabber:iq:register}query' :
+      out_query = ElementTree.SubElement(out_root, 'query')
+      out_query.attrib['xmlns'] = 'jabber:iq:register'
+      ElementTree.SubElement(out_query, 'instructions')
+      out_query[0].text = '''Welcome to the example server!
+
+You'll just need to complete this registration form with your \
+chosen name, password, and an email address we can reach you at.
+
+There isn't much more to this server than this form, so enjoy!'''
+      for field in ['username', 'password', 'first', 'last', 'email'] :
+        ElementTree.SubElement(out_query, field)
+
+
+  def clientHandle(self, input) :
+    print('starthandle')
+    # get xml root of input
+    in_root = ElementTree.fromstring(input)
+
+    # this example only replies to <iq/> requests
+    if in_root.tag != '{jabber:client}iq' :
+      return ""
+
+    out_root = ElementTree.Element('iq')
+    out_root.attrib['id'] = in_root.attrib['id']
+
+    # if type="get"
+    if in_root.attrib['type'] == 'get' :
+      out_root.attrib['type'] = 'result'
+
+      for query in in_root :
+        self.getquery(query, out_root)
+      
+    else :
+      return ""
+
+    print("C: %s" % input)
+    print("S: %s" % ElementTree.tostring(out_root))
+    return ElementTree.tostring(out_root)
+
+rc = regcore()
+rc()


Property changes on: trunk/concordance/examples/register.py
___________________________________________________________________
Added: svn:executable
   + *
Added: svn:keywords
   + Author Date Rev
Added: svn:mergeinfo
   + 

_______________________________________________
PySoy-SVN mailing list
PySoy-SVN@pysoy.org
http://www.pysoy.org/mailman/listinfo/pysoy-svn

Reply via email to