diff --git a/README.md b/README.md index 36ec3fa..913e654 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,8 @@ ![Python package](https://github.com/kinegratii/borax/workflows/Python%20package/badge.svg) ![Codecov](https://codecov.io/github/kinegratii/borax/coverage.svg) ![GitHub license](https://img.shields.io/github/license/kinegratii/borax) -![Document](https://img.shields.io/badge/%E6%96%87%E6%A1%A3-docsify%20%7C%20%E8%AF%AD%E9%9B%80-brightgreen) - +![Document](https://img.shields.io/badge/%E6%96%87%E6%A1%A3-docsify-brightgreen) +[![borax](https://snyk.io/advisor/python/borax/badge.svg)](https://snyk.io/advisor/python/borax) ## 概述 (Overview) diff --git a/borax/__init__.py b/borax/__init__.py index 5d1f521..8bc59e0 100644 --- a/borax/__init__.py +++ b/borax/__init__.py @@ -1,4 +1,4 @@ # coding=utf8 -__version__ = '3.5.3' +__version__ = '3.5.4' __author__ = 'kinegratii' diff --git a/borax/datasets/fetch.py b/borax/datasets/fetch.py index a7e9911..67f436e 100644 --- a/borax/datasets/fetch.py +++ b/borax/datasets/fetch.py @@ -5,7 +5,7 @@ from functools import partial from itertools import tee -__all__ = ['Empty', 'fetch', 'ifetch', 'fetch_single', 'ifetch_multiple', 'ifetch_single', 'fetch_as_dict'] +__all__ = ['Empty', 'bget', 'fetch', 'ifetch', 'fetch_single', 'ifetch_multiple', 'ifetch_single', 'fetch_as_dict'] class Empty: @@ -18,7 +18,7 @@ class Empty: def bget(obj, key, default=Empty): try: return obj[key] - except KeyError: + except (TypeError, KeyError): pass try: return getattr(obj, key) diff --git a/borax/htmls.py b/borax/htmls.py index 502f6f8..cb4b870 100644 --- a/borax/htmls.py +++ b/borax/htmls.py @@ -1,7 +1,7 @@ # coding=utf8 import html -from typing import Dict, List, Optional +from typing import Dict, List, Optional, Union def _escape(s): @@ -58,7 +58,7 @@ def html_params(**kwargs) -> str: def html_tag(tag_name: str, content: str = None, - *, id_: str = None, style: Dict = None, class_: Optional[List] = None, **kwargs) -> HTMLString: + *, id_: str = None, style: Dict = None, class_: Union[List, str, None] = None, **kwargs) -> HTMLString: """生成元素的html字符串""" kw = {} if id_: diff --git a/docs/README.md b/docs/README.md index 1c9dbb5..e273d10 100644 --- a/docs/README.md +++ b/docs/README.md @@ -6,8 +6,8 @@ ![Python package](https://github.com/kinegratii/borax/workflows/Python%20package/badge.svg) ![Codecov](https://codecov.io/github/kinegratii/borax/coverage.svg) ![GitHub license](https://img.shields.io/github/license/kinegratii/borax) -![Document](https://img.shields.io/badge/%E6%96%87%E6%A1%A3-docsify%20%7C%20%E8%AF%AD%E9%9B%80-brightgreen) - +![Document](https://img.shields.io/badge/%E6%96%87%E6%A1%A3-docsify-brightgreen) +[![borax](https://snyk.io/advisor/python/borax/badge.svg)](https://snyk.io/advisor/python/borax) @@ -38,4 +38,4 @@ Borax 是一个Python3工具集合库。 ## 开发(Development) - **代码仓库**:[Github](https://github.com/kinegratii/borax/) | [Gitee (镜像)](https://gitee.com/kinegratii/borax) -- **项目开发**: [版本日志](changelog) | [技术文档](develope/develope) \ No newline at end of file +- **项目开发**: [版本日志](changelog) | [技术文档(外链)](http://fd8cc08f.wiz06.com/wapp/pages/view/share/s/3Zzc2f0LJQ3w2TWIQb0ZMSna1zg4gs1vPQmb2vlh9M2zhqK8) \ No newline at end of file diff --git a/docs/_sidebar.md b/docs/_sidebar.md index 64371b0..97328fe 100644 --- a/docs/_sidebar.md +++ b/docs/_sidebar.md @@ -28,5 +28,4 @@ - **● 发布日志** - [v3.5](release-note/v350) - **● 项目开发** - - [版本日志](changelog) - - [技术文档](develope/develope) \ No newline at end of file + - [版本日志](changelog) \ No newline at end of file diff --git a/docs/changelog.md b/docs/changelog.md index d3f7602..b4d9435 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,5 +1,12 @@ # 更新日志 +## v3.5.4 (20220314) + +- `borax.htmls` + - `html_tag` 函数css参数支持str类型(函数逻辑已支持,本次仅添加typing hints) +- `borax.datasets.fetch` 模块 + - 修正 `fetch` 解析错误的bug ([#39](https://github.com/kinegratii/borax/issues/39)) + ## v3.5.3 (20220303) - `borax.serialize.cjson` diff --git a/docs/develope/develope.md b/docs/develope/develope.md deleted file mode 100644 index a4066e5..0000000 --- a/docs/develope/develope.md +++ /dev/null @@ -1,3 +0,0 @@ -# 技术文档 - -参见 [Borax项目开发技术文档](http://fd8cc08f.wiz06.com/wapp/pages/view/share/s/3Zzc2f0LJQ3w2TWIQb0ZMSna1zg4gs1vPQmb2vlh9M2zhqK8) ,该文档不定时更新。 \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml deleted file mode 100644 index 2569864..0000000 --- a/pyproject.toml +++ /dev/null @@ -1,32 +0,0 @@ -[tool.poetry] -name = "borax" -version = "3.5.1" -description = "A util collections for Python3." -readme = "README.md" -authors = ["kinegratii "] -homepage = "https://github.com/kinegratii/borax" -documentation = "https://kinegratii.github.io/borax" -license = "MIT" -keywords = ["python3", "utils", "lunar-calendar"] -classifiers=[ - "Development Status :: 5 - Production/Stable", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3 :: Only", - "Intended Audience :: Developers", - "License :: OSI Approved :: MIT License", - "Topic :: Software Development :: Libraries", - "Topic :: Utilities", - 'Operating System :: OS Independent' -] - -[tool.poetry.dev-dependencies] -nose = "^0.10" -coverage = "^5.5" -flake8 = "^3.9" -mccabe = "^0.6" -wheel = "^0.36" \ No newline at end of file diff --git a/setup.py b/setup.py index 7d73a5a..7816c0e 100644 --- a/setup.py +++ b/setup.py @@ -39,7 +39,7 @@ author='kinegratii', author_email='zhenwei.yan@hotmail.com', classifiers=lib_classifiers, - description='A tool collections for Python3.', + description='A tool collections.(Chinese-Lunar-Calendars/Python-Patterns)', long_description=long_description, long_description_content_type='text/markdown' ) diff --git a/tests/test_fetch.py b/tests/test_fetch.py index 579848b..60896d1 100644 --- a/tests/test_fetch.py +++ b/tests/test_fetch.py @@ -3,7 +3,7 @@ import unittest -from borax.datasets.fetch import fetch, fetch_single, ifetch_multiple, fetch_as_dict +from borax.datasets.fetch import fetch, fetch_single, ifetch_multiple, fetch_as_dict, bget DICT_LIST_DATA = [ {'id': 282, 'name': 'Alice', 'age': 30, 'sex': 'female'}, @@ -12,6 +12,22 @@ ] +class Point: + def __init__(self, x, y): + self.x = x + self.y = y + + +class GetterTestCase(unittest.TestCase): + def test_default_getter(self): + p = Point(1, 2) + self.assertEqual(1, bget(p, 'x')) + p2 = [2, 4] + self.assertEqual(4, bget(p2, 1)) + p3 = {'x': 5, 'y': 10} + self.assertEqual(5, bget(p3, 'x')) + + class FetchTestCase(unittest.TestCase): def test_fetch_single(self): names = fetch_single(DICT_LIST_DATA, 'name') diff --git a/tests/test_htmls.py b/tests/test_htmls.py index ea6a1b0..5814d82 100644 --- a/tests/test_htmls.py +++ b/tests/test_htmls.py @@ -5,6 +5,13 @@ from borax.htmls import HTMLString, html_tag +class HtmlStringTestCase(unittest.TestCase): + def test_html_string(self): + s = HTMLString('
Hello
') + s2 = HTMLString(s) + self.assertEqual(s.__html__(), s2.__html__()) + + class HtmlTagTest(unittest.TestCase): def test_html_tags(self): html = html_tag('img', id_='idDemoImg', src='/demo.png') @@ -20,3 +27,11 @@ def test_fixed_html(self): self.assertEqual('
', html_tag('div', id_='demo', style={'width': '2px'})) self.assertEqual('
', html_tag('div', id_='demo', class_=['a1', 'a2'])) + + def test_css_attr(self): + self.assertEqual('
', html_tag('div', class_=['one', 'two'])) + self.assertEqual('
', html_tag('div', class_='one two')) + + def test_bool_attr(self): + self.assertEqual('
Demo
', html_tag('div', id_='sk', content='Demo', checked=True)) + self.assertEqual('
Demo
', html_tag('div', id_='sk', content='Demo', checked=False))