regserver.py :  » Network » Twisted » Twisted-1.0.3 » Twisted-1.0.3 » doc » examples » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Network » Twisted 
Twisted » Twisted 1.0.3 » Twisted 1.0.3 » doc » examples » regserver.py
from twisted.web.widgets import Form,Gadget,FORGET_IT
from twisted.enterprise.row import RowObject,DBReflector
from twisted.cred.util import challenge
import md5

class License(RowObject):
    rowColumns = [
        'license_key',
  'license_secret',
  'license_type',
  'license_user',
  'license_email',
  'license_org',
  'license_dir',
  'license_host',
        ]
    def __init__(self,
                 license_key,
                 license_secret,
                 license_type,
                 license_user,
                 license_email,
                 license_org,
                 license_dir,
                 license_host):
        self.assignKeyAttr('license_key', license_key)
        self.license_secret = license_secret
        self.license_type = license_type
        self.license_user = license_user
        self.license_email = license_email
        self.license_org = license_org
        self.license_dir = license_dir
        self.license_host = license_host
        

licenseTypes = {"adamantium": "Adamantium License (Developer)",
                "mithril": "Mithril License (Personal)",
                "dilithium": "Dilithium License (Business)",
                "trilithium": "Trilithium License (Enterprise)"}

_ltypes = licenseTypes.items()
_ltypes.sort()

class RegServer(Form):
    formFields = [
        ['string', 'Administrator Name', 'license_user', '',
         'Your Name.'],
        ['string', 'Organization Name', 'license_org', '',
         'The name of the organization to create the license for.'],
        ['string', 'Email Address', 'license_email', '',
         'Enter an e-mail address here if you want us to contact you.'],
        ['menu', 'License Type', 'license_type', _ltypes,
         'Enter the type of license you desire.'],
        ['string', 'License Host', 'license_host', '',
         'The hostname that you will be using this server on.'],
        ['string', 'Working Directory', 'license_dir', '',
         'The directory on your host where Twisted will be run.',
        ]]
    title = "Twisted Daemon Registration Form"
    actionURI='twisted-registration'
    
    def __init__(self, dbpool):
        # Form.__init__(self)
        self.reflector = DBReflector(dbpool,
                                     [(License, "licenses",
                                       [("license_key", "varchar")])],
                                     self.populated)

    def populated(self, ignored):
        print 'regserver populated!!'
        
    keyfile = "KEYFILE"
    
    def process(self,
                write,
                request,
                submit,
                license_type,
                license_user,
                license_email,
                license_org,
                license_dir,
                license_host
                ):
        # Yay for single-threadedness.
        kf = open(self.keyfile).read()
        k = int(kf)
        f = open(self.keyfile, 'w')
        f.write(str(k + 1))
        f.close()
        license_key = kf
        license_secret = md5.md5(challenge()).hexdigest()
        self.reflector.insertRow(License(
            license_key,
            license_secret,
            license_type,
            license_user,
            license_email,
            license_org,
            license_dir,
            license_host
            ))
        request.setHeader("content-type", "text/x-twisted-license")
        request.write("""
# Twisted Registration File

# This is a site license file for a Twisted Server.  It contains a globally
# unique identifier and is intended to be used for one and only one persistent
# Twisted process at a time.  New license keys may be obtained at

#   http://twistedmatrix.com/license

# While this license file was originally designed for twistd, it can be used
# with other Twisted servers and clients that require a registration file as
# well.  Simply drop it into the directory where you will be running that
# application, with the name 'twisted-registration' (no extension).

# A unique identifier for this license key.
LICENSE_KEY = %r
# A secret key, associated with the license in a database.
LICENSE_SECRET = %r
# The type of license that you have registered for.
LICENSE_TYPE = %r
# A central point of contact for this license.
LICENSE_USER = %r
LICENSE_EMAIL = %r
# The organization that this server was licensed to.
LICENSE_ORG = %r
# The directory that this license applies to.
LICENSE_DIR = %r
# The host name that this license applies to.
LICENSE_HOST = %r

""" % (
    license_key,
    license_secret,
    licenseTypes.get(license_type) or license_type,
    license_user,
    license_email,
    license_org,
    license_dir,
    license_host
    ))
        request.finish()
        return [FORGET_IT]
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.