Example #1
0
    def getGroup(self, name):
        group = self.groups.get(name)
        if not group:
            group = Group(name)
            self.groups[name] = group
        return group

    def createParticipant(self, name):
        if not self.participants.has_key(name):
            log.msg("Created New Participant: %s" % name)
            p = Participant(name)
            p.setService(self)
            self.participants[name] = p
            return p

    def getPerspectiveNamed(self, name):
        try:
            p = self.participants[name]
        except KeyError:
            raise UserNonexistantError(name)
        else:
            return p

    def __str__(self):
        s = "<%s in app '%s' at %x>" % (self.serviceName,
                                        self.application.name,
                                        id(self))
        return s

coil.registerClass(Service)
Example #2
0
                    "bytes %s-%s/%s " % (str(start), str(end), str(size)))
            else:
                request.setHeader('content-length', size)
        except:
            traceback.print_exc(file=log.logfile)

        if request.method == 'HEAD':
            return ''

        # return data
        FileTransfer(f, size, request)
        # and make sure the connection doesn't get closed
        return server.NOT_DONE_YET


coil.registerClass(File)


class FileTransfer(pb.Viewable):
    """
    A class to represent the transfer of a file over the network.
    """
    request = None

    def __init__(self, file, size, request):
        self.file = file
        self.size = size
        self.request = request
        request.registerProducer(self, 0)

    def resumeProducing(self):
Example #3
0
        ]
    submitNames = [
        'Get Funky', 'Get *VERY* Funky'
        ]


class Test(widgets.Gadget, widgets.Presentation, coil.Configurable):
    """I am a trivial example of a 'web application'.
    """
    template = '''
    Congratulations, twisted.web appears to work!
    <ul>
    <li>Funky Form:
    %%%%self.funkyForm()%%%%
    </ul>
    '''

    configName = 'Twisted Web Test Page'

    def __init__(self):
        """Initialize.
        """
        coil.Configurable.__init__(self)
        widgets.Gadget.__init__(self)
        widgets.Presentation.__init__(self)

    funkyForm = FunkyForm


coil.registerClass(Test)
Example #4
0
        [Optional]
        """
        pass

    def irc_ISON(self, prefix, params):
        """Ison message

        Parameters: <nickname> *( SPACE <nickname> )

        [Optional]
        """
        pass


class IRCGateway(protocol.Factory, coil.Configurable):
    configCreatable = 0

    def __init__(self, service):
        self.service = service

    def buildProtocol(self, connection):
        """Build an IRC protocol to talk to my chat service.
        """
        i = IRCChatter()
        i.service = self.service
        return i


coil.registerClass(IRCGateway)
Example #5
0
    def getResourceFor(self, request):
        """Get a resource for a request.

        This iterates through the resource heirarchy, calling
        getChildWithDefault on each resource it finds for a path element,
        stopping when it hits an element where isLeaf is true.
        """
        request.site = self
        # Sitepath is used to determine cookie names between distributed
        # servers and disconnected sites.
        request.sitepath = copy.copy(request.prepath)
        return self.resource.getChildForRequest(request)


coil.registerClass(Site)


class HTTPClient(tcp.Client):
    """A client for HTTP connections.

    My implementation is deprecated, since it doesn't use Protocols, but
    my interface should not be.  Consider me to be a class in flux.
    """
    # initial state
    handling_header = 1
    buf = ''
    bytes_received = 0
    statusCode = -1

    default_headers = {"user-agent": "twisted", "connection": "close"}
Example #6
0
        Parameters: <nickname> *( SPACE <nickname> )

        [Optional]
        """
        pass


    def irc_ISON(self, prefix, params):
        """Ison message

        Parameters: <nickname> *( SPACE <nickname> )

        [Optional]
        """
        pass


class IRCGateway(protocol.Factory, coil.Configurable):
    configCreatable = 0
    def __init__(self, service):
        self.service = service
    def buildProtocol(self, connection):
        """Build an IRC protocol to talk to my chat service.
        """
        i = IRCChatter()
        i.service = self.service
        return i

coil.registerClass(IRCGateway)
Example #7
0
                request.setHeader('content-range',"bytes %s-%s/%s " % (
                    str(start), str(end), str(size)))
            else:
                request.setHeader('content-length',size)
        except:
            traceback.print_exc(file=log.logfile)

        if request.method == 'HEAD':
            return ''

        # return data
        FileTransfer(f, size, request)
        # and make sure the connection doesn't get closed
        return server.NOT_DONE_YET

coil.registerClass(File)

class FileTransfer(pb.Viewable):
    """
    A class to represent the transfer of a file over the network.
    """
    request = None
    def __init__(self, file, size, request):
        self.file = file
        self.size = size
        self.request = request
        request.registerProducer(self, 0)

    def resumeProducing(self):
        if not self.request:
            return
Example #8
0
            nvh.addHost('twistedmatrix.com', twistedMatrixDirectory)
            nvh.addHost('www.twistedmatrix.com', twistedMatrixDirectory)
        """
        self.hosts[name] = resrc

    def _getResourceForRequest(self, request):
        """(Internal) Get the appropriate resource for the given host.
        """
        hostHeader = request.getHeader('host')
        if hostHeader == None:
            return self.default or error.NoResource()
        else:
            host = string.split(string.lower(hostHeader), ':')[0]
        return self.hosts.get(
            host, error.NoResource("host %s not in vhost map" % repr(host)))

    def render(self, request):
        """Implementation of resource.Resource's render method.
        """
        resrc = self._getResourceForRequest(request)
        return resrc.render(request)

    def getChild(self, path, request):
        """Implementation of resource.Resource's getChild method.
        """
        resrc = self._getResourceForRequest(request)
        return resrc.getChildWithDefault(path, request)


coil.registerClass(NameVirtualHost)
Example #9
0
        self.section = ""
        self.putWidget("create", AccountCreationWidget(svc))
        self.putWidget("users", ParticipantListWidget(svc))

    def upgradeToVersion1(self):
        #This object should get garbage collected...
        pass

    def upgradeToVersion2(self):
        del self.page

    def display(self, request):
        return [html.linkList([["create",
                                "Create an Account"],
                               ["users",
                                "View the list of Participants"]])]

coil.registerClass(WordsGadget)

class WebWordsAdminSite(styles.Versioned):
    persistenceVersion = 2
    def upgradeToVersion2(self):
        self.__class__ = server.Site
        if hasattr(self, 'service'):
            self.__init__(WordsGadget(self.service))
            del self.service

AccountCreation = AccountCreationWidget
ParticipantsDirectory = ParticipantListWidget
AdminDir = WordsGadget
Example #10
0
            nvh.addHost('divunal.com', divunalDirectory)
            nvh.addHost('www.divunal.com', divunalDirectory)
            nvh.addHost('twistedmatrix.com', twistedMatrixDirectory)
            nvh.addHost('www.twistedmatrix.com', twistedMatrixDirectory)
        """
        self.hosts[name] = resrc

    def _getResourceForRequest(self, request):
        """(Internal) Get the appropriate resource for the given host.
        """
        hostHeader = request.getHeader('host')
        if hostHeader == None:
            return self.default or error.NoResource()
        else:
            host = string.split(string.lower(hostHeader),':')[0]
        return self.hosts.get(host, error.NoResource("host %s not in vhost map" % repr(host)))

    def render(self, request):
        """Implementation of resource.Resource's render method.
        """
        resrc = self._getResourceForRequest(request)
        return resrc.render(request)

    def getChild(self, path, request):
        """Implementation of resource.Resource's getChild method.
        """
        resrc = self._getResourceForRequest(request)
        return resrc.getChildWithDefault(path, request)

coil.registerClass(NameVirtualHost)
Example #11
0
        return self.resource.getChildWithDefault(pathEl, request)

    def getResourceFor(self, request):
        """Get a resource for a request.

        This iterates through the resource heirarchy, calling
        getChildWithDefault on each resource it finds for a path element,
        stopping when it hits an element where isLeaf is true.
        """
        request.site = self
        # Sitepath is used to determine cookie names between distributed
        # servers and disconnected sites.
        request.sitepath = copy.copy(request.prepath)
        return self.resource.getChildForRequest(request)

coil.registerClass(Site)

class HTTPClient(tcp.Client):
    """A client for HTTP connections.

    My implementation is deprecated, since it doesn't use Protocols, but
    my interface should not be.  Consider me to be a class in flux.
    """
    # initial state
    handling_header = 1
    buf = ''
    bytes_received = 0
    statusCode = -1

    default_headers = {
        "user-agent": "twisted",
Example #12
0
    def getGroup(self, name):
        group = self.groups.get(name)
        if not group:
            group = Group(name)
            self.groups[name] = group
        return group

    def createParticipant(self, name):
        if not self.participants.has_key(name):
            log.msg("Created New Participant: %s" % name)
            p = Participant(name)
            p.setService(self)
            self.participants[name] = p
            return p

    def getPerspectiveNamed(self, name):
        try:
            p = self.participants[name]
        except KeyError:
            raise UserNonexistantError(name)
        else:
            return p

    def __str__(self):
        s = "<%s in app '%s' at %x>" % (self.serviceName,
                                        self.application.name, id(self))
        return s


coil.registerClass(Service)