#!/usr/bin/env python3# -*- coding: utf-8 -*-r'''learning.pyA Python 3 tutorial from http://www.liaoxuefeng.comUsage:python3 learning.py'''import sysdef check_version(): v = sys.version_info if v.major == 3 and v.minor >= 4: return True print('Your current python is %d.%d. Please use Python 3.4.' % (v.major, v.minor)) return Falseif not check_version(): exit(1)import os, io, json, subprocess, tempfilefrom urllib import parsefrom wsgiref.simple_server import make_serverEXEC = sys.executablePORT = 39093HOST = 'local.liaoxuefeng.com:%d' % PORTTEMP = tempfile.mkdtemp(suffix='_py', prefix='learn_python_')INDEX = 0def main(): httpd = make_server('127.0.0.1', PORT, application) print('Ready for Python code on port %d...' % PORT) httpd.serve_forever()def get_name(): global INDEX INDEX = INDEX + 1 return 'test_%d' % INDEXdef write_py(name, code): fpath = os.path.join(TEMP, '%s.py' % name) with open(fpath, 'w', encoding='utf-8') as f: f.write(code) print('Code wrote to: %s' % fpath) return fpathdef decode(s): try: return s.decode('utf-8') except UnicodeDecodeError: return s.decode('gbk')def application(environ, start_response): host = environ.get('HTTP_HOST') method = environ.get('REQUEST_METHOD') path = environ.get('PATH_INFO') if method == 'GET' and path == '/': start_response('200 OK', [('Content-Type', 'text/html')]) return [b'Learning Python