Coder Social home page Coder Social logo

musical-octo-journey's Introduction

musical-octo-journey

给定一小短文本,它将调用图标服务器来生成二维码(QR码)这是一种编码文本的点格矩阵。 以下为完整的程序: import OS #Python的标准库中的OS模块包含普遍的操作系统功能 import re #引入正则表达式对象 import urllib #用于对URL进行编解码 from BaseHTTPServer import HTTPServer,BaseHTTPRequestHandler #导入HTTP处理相关模块

#自定义处理程序,用于处理HTTP请求 class TestHTTPHandler(BaseHTTPHandler): #处理GET请求 def do_GET(self): #页面输出模板字符串 templateStr = '''''

<title>QR Link Generator</title> %s

#将正则表达式编译成Pattern对象
Pattern = re.cpmpile(r'/qr\?=([^\&]+)\&qr=Show\+QR')
#使用Pattern匹配文本,获得匹配结果,无法匹配时将返回None
match = pattern.match(self.path)
qrImg = ''

if match:
   #使用Match获得分组信息
   qrImg = '<img src="http://chart.apis.google.com/chart?chr=300x300&cht=qr&choe=UTF-8&chl
   =' + match.group(1) + '" /><br />' +urllib.unquote(match.group(1))
   
self.protocal_version = 'HTTP/1.1'   #设置协议版本
self.send_response(200)  #设置响应状态码
self.send_header(:Welcome", "Connect")  #设置响应头
self.end_headers()
self.wfile.write(templateStr  % qrImg)   #输出相应内容

#启动服务函数 def start_server(port): http_server = HTTPServer(('',int(port)),TestHTTPHandler) http_server.serve_forever() #设置一直监听并接受请求

OS.chdir('static')   #改变工作目录到  static  目录
start_server(8000)   #启动服务,监听8000端口

musical-octo-journey's People

Contributors

myingkoko avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.