记录下,感谢大神,原地址https://www.cnblogs.com/yunmenzhe/p/6293428.html,侵删

1.修改xxx/python3.5/pyh.py权限

sudo chmod 777 pyh.py

2.修改源码

 # @file: pyh.py
# @purpose: a HTML tag generator
# @author: Emmanuel Turlay <turlay@cern.ch> __doc__ = """The pyh.py module is the core of the PyH package. PyH lets you
generate HTML tags from within your python code.
See http://code.google.com/p/pyh/ for documentation.
"""
__author__ = "Emmanuel Turlay <turlay@cern.ch>"
__version__ = '$Revision: 43 $'
__date__ = '$Date$' from sys import _getframe, stdout, modules, version
nOpen={} nl = '\n'
doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n'
charset = '<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />\n' tags = ['html', 'body', 'head', 'link', 'meta', 'div', 'p', 'form', 'legend',
'input', 'select', 'span', 'b', 'i', 'option', 'img', 'script',
'table', 'tr', 'td', 'th', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
'fieldset', 'a', 'title', 'body', 'head', 'title', 'script', 'br', 'table'] selfClose = ['input', 'img', 'link', 'br'] class Tag(list):
tagname = '' def __init__(self, *arg, **kw):
self.attributes = kw
if self.tagname :
name = self.tagname
self.isSeq = False
else:
name = 'sequence'
self.isSeq = True
self.id = kw.get('id', name)
#self.extend(arg)
for a in arg: self.addObj(a) def __iadd__(self, obj):
if isinstance(obj, Tag) and obj.isSeq:
for o in obj: self.addObj(o)
else: self.addObj(obj)
return self def addObj(self, obj):
if not isinstance(obj, Tag): obj = str(obj)
id=self.setID(obj)
setattr(self, id, obj)
self.append(obj) def setID(self, obj):
if isinstance(obj, Tag):
id = obj.id
n = len([t for t in self if isinstance(t, Tag) and t.id.startswith(id)])
else:
id = 'content'
n = len([t for t in self if not isinstance(t, Tag)])
if n: id = '%s_%03i' % (id, n)
if isinstance(obj, Tag): obj.id = id
return id def __add__(self, obj):
if self.tagname: return Tag(self, obj)
self.addObj(obj)
return self def __lshift__(self, obj):
self += obj
return obj def render(self):
result = ''
if self.tagname:
result = '<%s%s%s>' % (self.tagname, self.renderAtt(), self.selfClose()*' /')
if not self.selfClose():
for c in self:
if isinstance(c, Tag):
result += c.render()
else: result += c
if self.tagname:
result += '</%s>' % self.tagname
result += '\n'
return result def renderAtt(self):
result = ''
for n, v in self.attributes.items():
if n != 'txt' and n != 'open':
if n == 'cl': n = 'class'
result += ' %s="%s"' % (n, v)
return result def selfClose(self):
return self.tagname in selfClose def TagFactory(name):
class f(Tag):
tagname = name
f.__name__ = name
return f thisModule = modules[__name__] for t in tags: setattr(thisModule, t, TagFactory(t)) def ValidW3C():
out = a(img(src='http://www.w3.org/Icons/valid-xhtml10', alt='Valid XHTML 1.0 Strict'), href='http://validator.w3.org/check?uri=referer')
return out class PyH(Tag):
tagname = 'html' def __init__(self, name='MyPyHPage'):
self += head()
self += body()
self.attributes = dict(xmlns='http://www.w3.org/1999/xhtml', lang='en')
self.head += title(name) def __iadd__(self, obj):
if isinstance(obj, head) or isinstance(obj, body): self.addObj(obj)
elif isinstance(obj, meta) or isinstance(obj, link): self.head += obj
else:
self.body += obj
id=self.setID(obj)
setattr(self, id, obj)
return self def addJS(self, *arg):
for f in arg: self.head += script(type='text/javascript', src=f) def addCSS(self, *arg):
for f in arg: self.head += link(rel='stylesheet', type='text/css', href=f) def printOut(self,file=''):
if file: f = open(file, 'w')
else: f = stdout
f.write(doctype)
f.write(self.render())
f.flush()
if file: f.close() class TagCounter:
_count = {}
_lastOpen = []
for t in tags: _count[t] = 0
def __init__(self, name):
self._name = name
def open(self, tag):
if isLegal(tag):
self._count[tag] += 1
self._lastOpen += [tag]
def close(self, tag):
if isLegal(tag) and self._lastOpen[-1] == tag:
self._count[tag] -= 1
self._lastOpen.pop()
else:
print('Cross tagging is wrong')
def isAllowed(self, tag, open):
if not open and self.isClosed(tag):
print('TRYING TO CLOSE NON-OPEN TAG: %s' % tag)
return False
return True
def isOpen(self, tag):
if isLegal(tag): return self._count[tag]
def isClosed(self, tag):
if isLegal(tag): return not self._count[tag] def isLegal(tag):
if tag in tags: return True
else:
print('ILLEGAL TAG: %s' % tag)
return False

3.避免文件被修改导致其他问题,权限改回

sudo chmod 644 pyh.py

pyH支持python3的更多相关文章

  1. 阅读DSSS.py 并修改成支持python3.6

    项目地址:https://github.com/stamparm/DSSS 功能:一款小型注入工具 代码如下URL:https://github.com/stamparm/DSSS/blob/mast ...

  2. robotframework-ride支持python3

    最近发现robotframework的RIDE工具终于支持python3了,赶紧就安装了一下. 最新版本1.7.3.1基于wxPython4.0.4,此时的wxPython也是支持Python3.x的 ...

  3. TensorFlow 1.2.0新版本完美支持Python3.6,windows在cmd中输入pip install tensorflow就能下载应用最新tensorflow

    TensorFlow 1.2.0新版本完美支持Python3.6,windows在cmd中输入pip install tensorflow就能下载应用最新tensorflow 只需在cmd中输入pip ...

  4. 学以致用八---centos7.2 安装vim8+支持python3

    目的:打造基于python的vim环境 也是在地铁上突然产生的一个想法,平时都是在pycharm上练习python,但有时候会提示激活码过期,又得上网找激活码,够折腾的.那何不在linux环境下来搭建 ...

  5. 阿里云 rds python sdk不支持python3处理

    阿里云文档中心的python版本aliyun-python-sdk-rds不支持python3处理 问题:默认情况下文档中心的python版本只支持python2,不兼容python3版本 需要稍微修 ...

  6. ubuntu将python3设为默认后再安装支持python3.x的包

    简介: ubuntu默认python2.7版本,如果想要装python3.x版本,请记住python2.7版本一定不能卸载!!!但是即使我 python3.x版本安装成功,当运行python脚本时,系 ...

  7. 使用supervisor支持Python3程序 (解决找不到Module的问题)

    Supervisor是python2写就的一款强大的运维工具(其实现在已经支持Python3了 https://github.com/Supervisor/supervisor)那么怎么利用Super ...

  8. 【解决方案】M2Crypto不支持python3

    问题现象:python3的环境下,导入M2Crypto模块报错 "ModuleNotFoundError: No module named 'M2Crypto",通过pip ins ...

  9. Win10 安装 Anaconda3 用 Anaconda3 安装TensorFlow 1.2 (只支持python3.5)

    Win10 安装 Anaconda3 1.安装Anaconda3 选择相应的Anaconda进行安装,下载地址点击这里,下载对应系统版本的Anaconda,官网现在的版本是Anaconda 4.3.1 ...

随机推荐

  1. css 和 UI 框架 ---------- vue 待续

    vue 框架组件集合 radon-UI: 他人评价 --  一个帮助你快速开发产品的Vue组件库,简洁好用,效率高,让你摆脱各种定制化的烦恼. 个人感觉 --   组件简洁,  功能全面,  文档清晰 ...

  2. About RFC

    RFC说明 Request For Comments (RFC),是一系列以编号排定的文件,几乎所有的因特网标准都收录在RFC文件之中,如果你想成为网络方面的专家,那么RFC无疑是最重要也是最经常需要 ...

  3. CSS3之border-image

    先上效果图,类似于IPHONE手机左上角的返回按钮样式,如果是在CSS2那么就要做一张背景图片扩展就没那么灵活了,CSS3内就不需要了,CSS3样式挺强大方便的. 源图片: 样式: .banner { ...

  4. JavaScript学习(二)——深入学习js对象的原型与继承

    了解对象  什么是对象?   …… 这个就不说了 对象的声明的两种方式 var person = new Object(); person.name="linchen"; pers ...

  5. JavaWeb中监听器+过滤器+拦截器区别、配置和实际应用

    JavaWeb中监听器+过滤器+拦截器区别.配置和实际应用 1.前沿上一篇文章提到在web.xml中各个元素的执行顺序是这样的,context-param-->listener-->fil ...

  6. https页面证书验证、加密过程简介

    1.服务器向CA机构获取证书(假设这个证书伪造不了),当浏览器首次请求服务器的时候,服务器返回证书给浏览器.(证书包含:公钥+申请者与颁发者的相关信息+签名) 2.浏览器得到证书后,开始验证证书的相关 ...

  7. 20155225 2016-2017-2 《Java程序设计》第五周学习总结

    20155225 2006-2007-2 <Java程序设计>第五周学习总结 教材学习内容总结 使用try.catch异常处理,异常处理继承架构等 使用Collection收集对象,了解C ...

  8. 微信小程序开发过程中出现问题及解答

    1.wx.uploadFile上传图片,控制台抛出错误"uploadFile:fail Error:Hostname/IP doesn't match certificate's altna ...

  9. 使用Visual Studio Code开发Asp.Net Core WebApi学习笔记(三)-- Logger

    本篇是在上一篇的基础上添加日志功能,并记录NLog在Asp.Net Core里的使用方法. 第一部分:默认Logger支持 一.project.json添加日志包引用,并在cmd窗口使用 dotnet ...

  10. exec函数簇

    转自:http://www.cppblog.com/prayer/archive/2009/04/15/80077.html 也许有不少读者从本系列文章一推出就开始读,一直到这里还有一个很大的疑惑:既 ...