Python函数应该返回CSS代码

时间:2013-11-26 13:58:59

标签: html css3 python-3.x

我修改了附录A中给出的简单服务器的\ to_html“函数,以便它返回这个CSS代码:这个css代码打印带有绿色边框的文本。

        <!DOCTYPE html>
        <html>
        <head>
        <style>
        div.ex
        {
        width:220px;
        padding:10px;
        border:5px solid green;
        margin:0px;
        background-color: #778899;
        }
        </style>
        </head>

        <body>

        <p><i><center><div class="ex">It was a bright cold day in April, and the clocks were stricking thirhteen.</div></center><i></p>

        </body>
        </html>. 

使用此modied \ to_html“函数,命令:

    telnet localhost 8888

应生成

形式的输出
    <html>...2013-10-29 15:57:00.343224...</html>

这是附录A:

#!/usr/bin/python
from datetime import *
from socket import *
HOST = "localhost"
PORT = 8888

def to_html(t) :
    result = t
    return result

def to_http(h) :
    result = h
    return result

def worker(sck) :
    t = str(datetime.now())
    # sck.send(to_http(to_html(t))) # Python 2.X
    sck.send(bytes(to_http(to_html(t)), "UTF-8")) # Python 3.X
    sck.close()

ssck = socket(AF_INET, SOCK_STREAM)
ssck.bind((HOST, PORT))
ssck.listen(1)
while True :
    sck, addr = ssck.accept()
    worker(sck)

现在我的问题是如何做到这一切?服务器提供当天的时间。

0 个答案:

没有答案