From 8ac6b5cb7eb8d4bae5d19a9193480d75336fee44 Mon Sep 17 00:00:00 2001 From: fastpx2014 Date: Fri, 11 Mar 2022 21:44:06 +0800 Subject: [PATCH 1/5] =?UTF-8?q?:bug:=20html=5Ftag=E5=87=BD=E6=95=B0css?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E6=94=AF=E6=8C=81str=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- borax/htmls.py | 4 ++-- docs/changelog.md | 5 +++++ tests/test_htmls.py | 4 ++++ 3 files changed, 11 insertions(+), 2 deletions(-) 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/changelog.md b/docs/changelog.md index d3f7602..0065a41 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,5 +1,10 @@ # 更新日志 +## v3.5.4 + +- `borax.htmls` + - `html_tag` 函数css参数支持str类型(函数逻辑已支持,本次仅添加typing hints) + ## v3.5.3 (20220303) - `borax.serialize.cjson` diff --git a/tests/test_htmls.py b/tests/test_htmls.py index ea6a1b0..d6441f8 100644 --- a/tests/test_htmls.py +++ b/tests/test_htmls.py @@ -20,3 +20,7 @@ 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')) From 68a0af4831b193cf1d5583411ccf70942e80e5c8 Mon Sep 17 00:00:00 2001 From: fastpx2014 Date: Sat, 12 Mar 2022 15:13:13 +0800 Subject: [PATCH 2/5] =?UTF-8?q?:bug:=20=E4=BF=AE=E6=AD=A3fetch=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E9=94=99=E8=AF=AF=E7=9A=84bug=20#39?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- borax/datasets/fetch.py | 4 ++-- docs/changelog.md | 2 ++ tests/test_fetch.py | 18 +++++++++++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) 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/docs/changelog.md b/docs/changelog.md index 0065a41..d21594c 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -4,6 +4,8 @@ - `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) 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') From f8c507b9847a43ffb7ed2549c2b759a9508c0478 Mon Sep 17 00:00:00 2001 From: fastpx2014 Date: Sat, 12 Mar 2022 15:28:57 +0800 Subject: [PATCH 3/5] :pencil: Update document --- README.md | 4 ++-- docs/README.md | 6 +++--- docs/_sidebar.md | 3 +-- docs/develope/develope.md | 3 --- pyproject.toml | 32 -------------------------------- setup.py | 2 +- 6 files changed, 7 insertions(+), 43 deletions(-) delete mode 100644 docs/develope/develope.md delete mode 100644 pyproject.toml 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/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/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' ) From c936b866dd03fb2e3f6aa202489b8f1edc75d11a Mon Sep 17 00:00:00 2001 From: fastpx2014 Date: Sat, 12 Mar 2022 15:46:12 +0800 Subject: [PATCH 4/5] :sparkles: Add test cases --- tests/test_htmls.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_htmls.py b/tests/test_htmls.py index d6441f8..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') @@ -24,3 +31,7 @@ def test_fixed_html(self): 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)) From 578d8f2ac8dec005592c4e0505cae85d56dc0f0d Mon Sep 17 00:00:00 2001 From: kinegratii Date: Mon, 14 Mar 2022 09:35:52 +0800 Subject: [PATCH 5/5] :bookmark: Release v3.5.4 --- borax/__init__.py | 2 +- docs/changelog.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/docs/changelog.md b/docs/changelog.md index d21594c..b4d9435 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,6 +1,6 @@ # 更新日志 -## v3.5.4 +## v3.5.4 (20220314) - `borax.htmls` - `html_tag` 函数css参数支持str类型(函数逻辑已支持,本次仅添加typing hints)