From 8fc366d790091cfb8fa9f6f03a773cce8a1d49b8 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 17 Oct 2020 16:33:56 -0500 Subject: [PATCH 01/13] TODO validar import --- lira/parsers/rst.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lira/parsers/rst.py b/lira/parsers/rst.py index a77a861..beea7eb 100644 --- a/lira/parsers/rst.py +++ b/lira/parsers/rst.py @@ -7,6 +7,7 @@ from lira.parsers import BaseParser from lira.parsers import nodes as booknodes +from importlib.util import find_spec class DirectiveNode(Element): @@ -14,16 +15,18 @@ class DirectiveNode(Element): tagname = "directive" -def importable(value): - # TODO: check if value can be imported - return value - +def is_importable(value): + try: + find_spec(value) + return value + except: + raise ValueError class TestDirective(Directive): option_spec = { "help": str, - "validator": importable, + "validator": is_importable, } has_content = True From 09da4ad9c8a691ea2d2f76df9fe1bb2ee35fe499 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 17 Oct 2020 22:22:04 -0500 Subject: [PATCH 02/13] sin pasar test --- lira/parsers/rst.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lira/parsers/rst.py b/lira/parsers/rst.py index 7f3f044..7c75eea 100644 --- a/lira/parsers/rst.py +++ b/lira/parsers/rst.py @@ -26,11 +26,11 @@ class DirectiveNode(Element): def is_importable(value): - try: - find_spec(value) - return value - except: + + if find_spec('lira', value) is None: raise ValueError + else: + return value class BaseDirective(Directive): def run(self): From 9be899748976354e2956ea37eb98a821ab9212c2 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 23 Oct 2020 21:12:22 -0500 Subject: [PATCH 03/13] commit --- lira/parsers/rst.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lira/parsers/rst.py b/lira/parsers/rst.py index 7c75eea..bc3b097 100644 --- a/lira/parsers/rst.py +++ b/lira/parsers/rst.py @@ -7,7 +7,7 @@ from lira.parsers import BaseParser from lira.parsers import nodes as booknodes -from importlib.util import find_spec +from importlib import import_module class DirectiveNode(Element): @@ -27,10 +27,9 @@ class DirectiveNode(Element): def is_importable(value): - if find_spec('lira', value) is None: - raise ValueError - else: - return value + module_name, class_name = value.rsplit(".",1) + MyClass = getattr(importlib.import_module(module_name), class_name, ValueError) + instance = MyClass() class BaseDirective(Directive): def run(self): From 8832e5aa7256a2bccb0267f3d5728bf8e8918ce7 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 23 Oct 2020 21:48:26 -0500 Subject: [PATCH 04/13] test pasado --- lira/parsers/rst.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lira/parsers/rst.py b/lira/parsers/rst.py index bc3b097..05730f3 100644 --- a/lira/parsers/rst.py +++ b/lira/parsers/rst.py @@ -7,7 +7,7 @@ from lira.parsers import BaseParser from lira.parsers import nodes as booknodes -from importlib import import_module +import importlib class DirectiveNode(Element): @@ -21,7 +21,6 @@ class DirectiveNode(Element): - content - options """ - tagname = "directive" @@ -29,7 +28,11 @@ def is_importable(value): module_name, class_name = value.rsplit(".",1) MyClass = getattr(importlib.import_module(module_name), class_name, ValueError) - instance = MyClass() + if MyClass is ValueError: + raise ValueError + else: + return value + class BaseDirective(Directive): def run(self): From 2a1cfe43c143e5bb88120395f121338b976494ce Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 24 Oct 2020 06:53:00 -0500 Subject: [PATCH 05/13] commit --- lira/parsers/rst.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lira/parsers/rst.py b/lira/parsers/rst.py index b325447..2f5ca6a 100644 --- a/lira/parsers/rst.py +++ b/lira/parsers/rst.py @@ -1,4 +1,5 @@ import logging +import importlib from docutils.frontend import OptionParser from docutils.nodes import Element @@ -7,7 +8,6 @@ from lira.parsers import BaseParser from lira.parsers import nodes as booknodes -import importlib # TODO: make a global logging config logger = logging.getLogger(__name__) @@ -28,7 +28,6 @@ class DirectiveNode(Element): def is_importable(value): - module_name, class_name = value.rsplit(".",1) MyClass = getattr(importlib.import_module(module_name), class_name, ValueError) if MyClass is ValueError: From 02b3929dea35968660a575d987f4c70ae8b6b44d Mon Sep 17 00:00:00 2001 From: Danielrick88 <70044225+Danielrick88@users.noreply.github.com> Date: Sat, 24 Oct 2020 15:13:30 -0500 Subject: [PATCH 06/13] Update lira/parsers/rst.py Co-authored-by: Santos Gallegos --- lira/parsers/rst.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lira/parsers/rst.py b/lira/parsers/rst.py index 2f5ca6a..16de233 100644 --- a/lira/parsers/rst.py +++ b/lira/parsers/rst.py @@ -29,7 +29,7 @@ class DirectiveNode(Element): def is_importable(value): module_name, class_name = value.rsplit(".",1) - MyClass = getattr(importlib.import_module(module_name), class_name, ValueError) + MyClass = getattr(importlib.import_module(module_name), class_name, None) if MyClass is ValueError: raise ValueError else: From 82dbd0399df9cc4e175430550fc50b9efd48a9ff Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 25 Oct 2020 21:25:51 -0500 Subject: [PATCH 07/13] Agregando try --- lira/parsers/rst.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lira/parsers/rst.py b/lira/parsers/rst.py index 16de233..cbb93b1 100644 --- a/lira/parsers/rst.py +++ b/lira/parsers/rst.py @@ -29,11 +29,14 @@ class DirectiveNode(Element): def is_importable(value): module_name, class_name = value.rsplit(".",1) - MyClass = getattr(importlib.import_module(module_name), class_name, None) - if MyClass is ValueError: + try: + MyClass = getattr(importlib.import_module(module_name), class_name, None) + instance = MyClass() + return value + + except ImportError: + raise ValueError - else: - return value class BaseDirective(Directive): From 885900e4e296eda88bb9b911dfa5053d244d3a3b Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 25 Oct 2020 23:05:52 -0500 Subject: [PATCH 08/13] colocando return dentro de try --- lira/parsers/rst.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lira/parsers/rst.py b/lira/parsers/rst.py index cbb93b1..7394a66 100644 --- a/lira/parsers/rst.py +++ b/lira/parsers/rst.py @@ -32,7 +32,7 @@ def is_importable(value): try: MyClass = getattr(importlib.import_module(module_name), class_name, None) instance = MyClass() - return value + return value except ImportError: From 420569ea4c5d1463189bf55bc5ba901808dbc37c Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 28 Oct 2020 12:56:31 -0500 Subject: [PATCH 09/13] condicional is None --- lira/parsers/rst.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lira/parsers/rst.py b/lira/parsers/rst.py index 7394a66..ebc0810 100644 --- a/lira/parsers/rst.py +++ b/lira/parsers/rst.py @@ -32,7 +32,10 @@ def is_importable(value): try: MyClass = getattr(importlib.import_module(module_name), class_name, None) instance = MyClass() - return value + if instance is None: + raise ValueError + else: + return value except ImportError: From 43e48b857239fcf8f55558c37b31c1e1a46efd42 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 29 Oct 2020 20:28:40 -0500 Subject: [PATCH 10/13] eliminada estancia test en verde --- lira/parsers/rst.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lira/parsers/rst.py b/lira/parsers/rst.py index 4d13f40..4b894e5 100644 --- a/lira/parsers/rst.py +++ b/lira/parsers/rst.py @@ -1,5 +1,5 @@ -import logging import importlib +import logging from docutils.frontend import OptionParser from docutils.nodes import Element @@ -23,15 +23,15 @@ class DirectiveNode(Element): - content - options """ + tagname = "directive" def is_importable(value): - module_name, class_name = value.rsplit(".",1) + module_name, class_name = value.rsplit(".", 1) try: MyClass = getattr(importlib.import_module(module_name), class_name, None) - instance = MyClass() - if instance is None: + if MyClass is None: raise ValueError else: return value From 80936cc472b50e43bac62127870cc07d312c650d Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 29 Oct 2020 22:53:02 -0500 Subject: [PATCH 11/13] Trato de verificar subclase --- lira/parsers/rst.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lira/parsers/rst.py b/lira/parsers/rst.py index 4b894e5..5400d85 100644 --- a/lira/parsers/rst.py +++ b/lira/parsers/rst.py @@ -8,6 +8,7 @@ from lira.parsers import BaseParser from lira.parsers import nodes as booknodes +from lira.validators import Validator logger = logging.getLogger(__name__) @@ -33,7 +34,7 @@ def is_importable(value): MyClass = getattr(importlib.import_module(module_name), class_name, None) if MyClass is None: raise ValueError - else: + elif issubclass(MyClass, Validator): return value except ImportError: From 02f49c28df600f6724b3fd6d1a712f9b28af07d5 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 30 Oct 2020 07:42:20 -0500 Subject: [PATCH 12/13] =?UTF-8?q?Modificaci=C3=B3n=20de=20if?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lira/parsers/rst.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lira/parsers/rst.py b/lira/parsers/rst.py index 5400d85..424a125 100644 --- a/lira/parsers/rst.py +++ b/lira/parsers/rst.py @@ -32,9 +32,9 @@ def is_importable(value): module_name, class_name = value.rsplit(".", 1) try: MyClass = getattr(importlib.import_module(module_name), class_name, None) - if MyClass is None: + if MyClass is None or not issubclass(MyClass, Validator): raise ValueError - elif issubclass(MyClass, Validator): + else: return value except ImportError: From c936c7437f8a885760a427c302904fc4c3a375e5 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 2 Nov 2020 20:22:24 -0500 Subject: [PATCH 13/13] Renombro MyClass por TargetClass --- lira/parsers/rst.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lira/parsers/rst.py b/lira/parsers/rst.py index 424a125..7084926 100644 --- a/lira/parsers/rst.py +++ b/lira/parsers/rst.py @@ -31,8 +31,8 @@ class DirectiveNode(Element): def is_importable(value): module_name, class_name = value.rsplit(".", 1) try: - MyClass = getattr(importlib.import_module(module_name), class_name, None) - if MyClass is None or not issubclass(MyClass, Validator): + TargetClass = getattr(importlib.import_module(module_name), class_name, None) + if TargetClass is None or not issubclass(TargetClass, Validator): raise ValueError else: return value