Conforms to Spec v0.2 #11
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
尝试实现 v0.2 版本的 Spec,同时更新到了最新的数据。因为原有结构和测试与 Spec 要求差别太大,基本上就是重写了。
在 Spec 基础上:
Division保留了原来的is_provinceis_prefectureis_county属性32000000GB2260 的数据通过
generate.py生成到gb2260.data.<源>.revision_<日期>里。因为看到 Spec 后续有允许用户切换选择源的计划,所以目前是在生成时就把所有源的数据混合,按照「标准 > STATS > MCA」的优先级生成到假的「curated」源使用。这些模块在构造具体的GB2260对象时动态加载。与 GB/T 2260 数字码相关的逻辑都在
gb2260.code里,主要用正则表达式匹配、处理、变换。Spec 为
GB2260对象定义的大多数逻辑都在Revision对象中实现,GB2260主要作为其它对象的代理使用。关于
Division对象是否允许用户自行通过「代码、名字、版本」三个字符串构造,我选择了不允许,同时还不允许修改这三个字段(行为类似namedtuple)。因为有Division.province这种东西的缘故,它似乎就不再是 POD 而是有内部不变量的对象了。而且如果允许自行构建,Division.province之类的方法似乎也会很难办,搞临时或者全局性质的GB2260对象似乎也不大好。所以还是和 Spec 一样,仅推荐通过GB2260.get获取Division。另外因为 cn/GB2260#50 的问题,使用 MCA 源的数据可能会有一些问题(默认
GB2260()得到的最新版也是 MCA 源的),但GB2260('201412')得到的是和老版本一样的数据。可能改动大了一些。之前也尝试过一步步从原来的版本修改过来,但失败了,牵一发而动全身。仅供参考……
p.s. 在测试里加了
pytest-mock的依赖;pypy 没有接触过,所以也没有在它上面跑测试 :(