<s> '''<STR_LIT>''' <EOL> import sys <EOL> from kivy . support import install_twisted_reactor <EOL> from kivy . app import App <EOL> from kivy . uix . label import Label <EOL> from kivy . uix . textinput import TextInput <EOL> from kivy . uix . boxlayout import BoxLayout <EOL> install_twisted_reactor ( ) <EOL> from twisted . internet import defer <EOL> from twisted . internet import reactor <EOL> from twisted . python import log <EOL> import txthings . resource as resource <EOL> import txthings . coap as coap <EOL> class MOTDResource ( resource . CoAPResource ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , app , start = <NUM_LIT:0> ) : <EOL> resource . CoAPResource . __init__ ( self ) <EOL> self . app = app <EOL> self . counter = start <EOL> self . visible = True <EOL> self . addParam ( resource . LinkParam ( "<STR_LIT:title>" , "<STR_LIT>" ) ) <EOL> def render_GET ( self , request ) : <EOL> response = coap . Message ( code = coap . CONTENT , payload = '<STR_LIT:%s>' % str ( self . app . messagebox . text ) ) <EOL> self . counter += <NUM_LIT:1> <EOL> self . app . display_counter ( self . counter ) <EOL> return defer . succeed ( response ) <EOL> class CoreResource ( resource . CoAPResource ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , root ) : <EOL> resource . CoAPResource . __init__ ( self ) <EOL> self . root = root <EOL> def render_GET ( self , request ) : <EOL> data = [ ] <EOL> self . root . generateResourceList ( data , "<STR_LIT>" ) <EOL> payload = "<STR_LIT:U+002C>" . join ( data ) <EOL> log . msg ( "<STR_LIT:%s>" % payload ) <EOL> response = coap . Message ( code = coap . CONTENT , payload = payload ) <EOL> response . opt . content_format = <NUM_LIT> <EOL> return defer . succeed ( response ) <EOL> class TwistedServerApp ( App ) : <EOL> def build ( self ) : <EOL> root = resource . CoAPResource ( ) <EOL> well_known = resource . CoAPResource ( ) <EOL> root . putChild ( '<STR_LIT>' , well_known ) <EOL> core = CoreResource ( root ) <EOL> well_known . putChild ( '<STR_LIT>' , core ) <EOL> counter = MOTDResource ( self , <NUM_LIT:0> ) <EOL> root . putChild ( '<STR_LIT>' , counter ) <EOL> endpoint = resource . Endpoint ( root ) <EOL> reactor . listenUDP ( coap . COAP_PORT , coap . Coap ( endpoint ) ) <EOL> self . label = Label ( text = "<STR_LIT>" ) <EOL> self . display_counter ( <NUM_LIT:0> ) <EOL> self . messagebox = TextInput ( size_hint_y = <NUM_LIT> , multiline = False ) <EOL> self . messagebox . text = "<STR_LIT>" <EOL> self . layout = BoxLayout ( orientation = '<STR_LIT>' , padding = <NUM_LIT:10> ) <EOL> self . layout . add_widget ( self . label ) <EOL> self . layout . add_widget ( self . messagebox ) <EOL> return self . layout <EOL> def display_counter ( self , count ) : <EOL> self . label . text = "<STR_LIT>" % count <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> log . startLogging ( sys . stdout ) <EOL> TwistedServerApp ( ) . run ( ) </s>
