kognitos-bdk-api 1.12.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kognitos_bdk_api-1.12.4/LICENSE +45 -0
- kognitos_bdk_api-1.12.4/PKG-INFO +23 -0
- kognitos_bdk_api-1.12.4/README.md +3 -0
- kognitos_bdk_api-1.12.4/pyproject.toml +77 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/__version__.py +1 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/api/__init__.py +7 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/api/errors.py +21 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/api/filter.py +86 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/api/noun_phrase.py +99 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/api/table.py +2 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/blueprints/__init__.py +5 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/blueprints/file_storage_blueprint.py +146 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/decorators/__init__.py +8 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/decorators/blueprint_decorator.py +32 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/decorators/book_decorator.py +135 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/decorators/concept_decorator.py +52 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/decorators/config_decorator.py +48 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/decorators/connect_decorator.py +78 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/decorators/oauth_decorator.py +59 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/decorators/oauthtoken_decorator.py +10 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/decorators/procedure_decorator.py +46 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/docstring/__init__.py +4 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/docstring/docstring.py +224 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/docstring/error.py +11 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/docstring/example.py +35 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/docstring/parser.py +16 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/docstring/sections.py +25 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/errors.py +8 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/reflection/__init__.py +13 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/reflection/authentication/__init__.py +6 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/reflection/authentication/book_authentication_descriptor.py +9 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/reflection/authentication/book_custom_authentication_descriptor.py +12 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/reflection/authentication/book_oauth_authentication_descriptor.py +25 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/reflection/authentication/credential_descriptor.py +12 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/reflection/book_config_descriptor.py +11 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/reflection/book_descriptor.py +119 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/reflection/book_procedure_descriptor.py +86 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/reflection/book_procedure_signature.py +36 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/reflection/concept_descriptor.py +17 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/reflection/example.py +15 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/reflection/factory/__init__.py +7 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/reflection/factory/attrs_utils.py +54 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/reflection/factory/book.py +45 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/reflection/factory/concept.py +30 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/reflection/factory/config.py +18 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/reflection/factory/custom_authentication.py +23 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/reflection/factory/parameter_concept.py +17 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/reflection/factory/procedure.py +188 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/reflection/factory/types.py +242 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/reflection/parameter_concept_bind.py +12 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/reflection/types/__init__.py +11 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/reflection/types/any.py +30 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/reflection/types/base.py +56 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/reflection/types/credential.py +15 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/reflection/types/dict.py +96 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/reflection/types/list.py +41 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/reflection/types/opaque.py +49 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/reflection/types/optional.py +35 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/reflection/types/scalar.py +75 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/reflection/types/self.py +30 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/reflection/types/table.py +79 -0
- kognitos_bdk_api-1.12.4/src/kognitos/bdk/reflection/types/union.py +57 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
Copyright © 2024 Kognitos, Inc. (“Licensor”)
|
|
2
|
+
|
|
3
|
+
ACCEPTANCE
|
|
4
|
+
By using or accessing the Software, you (including any legal entity, sole proprietorship, or organization that you
|
|
5
|
+
work for, as well as any affiliates under common control therewith, collectively “Licensee”) agree to be bound by the
|
|
6
|
+
terms of this License and assume full responsibility for all direct or indirect use of the Software.
|
|
7
|
+
|
|
8
|
+
COPYRIGHT LICENSE
|
|
9
|
+
Subject to Licensee’s full compliance with this License, including the limitations and conditions set forth herein or
|
|
10
|
+
in any other applicable documentation provided by Licensor, Licensor grants Licensee a non-exclusive, royalty-free,
|
|
11
|
+
worldwide, non-sublicensable, and non-transferable license to access, use, copy, distribute, make available, and
|
|
12
|
+
prepare derivative works of the Software. No rights or licenses are granted beyond those expressly stated in this
|
|
13
|
+
License.
|
|
14
|
+
|
|
15
|
+
LIMITATIONS
|
|
16
|
+
Licensee agrees not to use the Software beyond the scope explicitly authorized under this License. By accessing the
|
|
17
|
+
Software, either directly or on behalf of your organization, Licensee further agrees not to: (i) use the Software for
|
|
18
|
+
purposes that are directly competitive with Licensor’s business activities; (ii) provide the Software to third parties
|
|
19
|
+
as a hosted or managed service that enables access to substantial features or functionality of the Software;
|
|
20
|
+
(iii) rent, lease, lend, sell, sublicense, assign, distribute, publish, transfer, or otherwise make the Software
|
|
21
|
+
available to any third party, or disable or circumvent any technological measures included with the Software;
|
|
22
|
+
(iv) alter, remove, obscure, or fail to display any copyright, licensing, or other proprietary notices included
|
|
23
|
+
with the Software; or (v) use the Software in any manner that infringes, misappropriates, or otherwise violates
|
|
24
|
+
any intellectual property rights or other rights of any person, or that violates any applicable laws or regulations.
|
|
25
|
+
All copies of the original Software, modified Software, and derivative works are subject to this License or other
|
|
26
|
+
applicable documentation provided by Licensor. Licensee must ensure that any party receiving a copy of any part
|
|
27
|
+
of the Software from Licensee also receives a copy of these terms. Any violation of the terms of this Licensee will
|
|
28
|
+
result in the immediate and permanent termination of all rights under this License.
|
|
29
|
+
|
|
30
|
+
INFRINGEMENT CLAIMS
|
|
31
|
+
This License does not extend to intellectual property claims caused by modifications or additions made by Licensee
|
|
32
|
+
to the Software. If Licensee or their organization asserts in writing that the Software infringes or contributes
|
|
33
|
+
to the infringement of any patent, all rights granted under this License will terminate immediately. In the event
|
|
34
|
+
that the assertion is made by an organization, termination will extend to all uses of the Software on behalf of
|
|
35
|
+
the organization.
|
|
36
|
+
|
|
37
|
+
NO LIABILITY
|
|
38
|
+
Except as expressly stated in this License, no other rights are granted. To the maximum extent permitted by applicable
|
|
39
|
+
law, the Software is provided “as is,” without warranties or conditions of any kind, express or implied, including
|
|
40
|
+
but not limited to warranties of merchantability, fitness for a particular purpose, or non-infringement. Licensor
|
|
41
|
+
shall not be liable for any damages arising from these terms or from the use of the Software under any legal theory.
|
|
42
|
+
To the maximum extent permitted by applicable law, the Software is provided “as is,” without warranties of any kind.
|
|
43
|
+
Licensor shall not be liable for any damages, including but not limited to direct, indirect, incidental, special,
|
|
44
|
+
consequential, or exemplary damages, arising from these terms or the use of the Software, regardless of the legal
|
|
45
|
+
theory invoked.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: kognitos-bdk-api
|
|
3
|
+
Version: 1.12.4
|
|
4
|
+
Summary: Kognitos Book Development Kit
|
|
5
|
+
License: Proprietary
|
|
6
|
+
Author: Emiliano Lesende
|
|
7
|
+
Author-email: emiliano@kognitos.com
|
|
8
|
+
Requires-Python: >=3.11,<4.0
|
|
9
|
+
Classifier: License :: Other/Proprietary License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Provides-Extra: attrs
|
|
15
|
+
Requires-Dist: attrs (>=24.2.0,<25.0.0) ; extra == "attrs"
|
|
16
|
+
Requires-Dist: docstring-parser (>=0.15,<0.16)
|
|
17
|
+
Requires-Dist: kognitos-bdk-klang (>=2.0.0,<3.0.0)
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
# Python API for Book Development Kit
|
|
21
|
+
|
|
22
|
+
This package serves as a Python API tailored for the creation of books.
|
|
23
|
+
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "kognitos-bdk-api"
|
|
3
|
+
version = "1.12.4"
|
|
4
|
+
description = "Kognitos Book Development Kit"
|
|
5
|
+
authors = ["Emiliano Lesende <emiliano@kognitos.com>"]
|
|
6
|
+
readme = "README.md"
|
|
7
|
+
license = "Proprietary"
|
|
8
|
+
packages = [{include = "kognitos", from="src"}]
|
|
9
|
+
|
|
10
|
+
[tool.pytest.ini_options]
|
|
11
|
+
pythonpath = ["src"]
|
|
12
|
+
|
|
13
|
+
[tool.poetry.dependencies]
|
|
14
|
+
python = ">=3.11,<4.0"
|
|
15
|
+
docstring-parser = "^0.15"
|
|
16
|
+
kognitos-bdk-klang = "^2.0.0"
|
|
17
|
+
attrs = {version="^24.2.0", optional=true}
|
|
18
|
+
|
|
19
|
+
[tool.poetry.group.dev.dependencies]
|
|
20
|
+
pytest = "^7.4.4"
|
|
21
|
+
mypy = "^1.8.0"
|
|
22
|
+
isort = "^5.13.2"
|
|
23
|
+
black = "^24.2.0"
|
|
24
|
+
pre-commit = "^3.6.2"
|
|
25
|
+
pylint = "^3.1.0"
|
|
26
|
+
pyright = "^1.1.360"
|
|
27
|
+
pytest-cov = "^5.0.0"
|
|
28
|
+
attrs = "^24.2.0"
|
|
29
|
+
pyarrow = "^17.0.0"
|
|
30
|
+
arro3-core = "^0.4.2"
|
|
31
|
+
nanoarrow = "^0.6.0"
|
|
32
|
+
|
|
33
|
+
[tool.poetry.extras]
|
|
34
|
+
attrs = ["attrs"]
|
|
35
|
+
|
|
36
|
+
[tool.poetry.scripts]
|
|
37
|
+
tests = 'poetry_scripts:run_tests'
|
|
38
|
+
format = 'poetry_scripts:run_format'
|
|
39
|
+
lint = 'poetry_scripts:run_lint'
|
|
40
|
+
type-check = 'poetry_scripts:run_type_check'
|
|
41
|
+
|
|
42
|
+
[build-system]
|
|
43
|
+
requires = ["poetry-core"]
|
|
44
|
+
build-backend = "poetry.core.masonry.api"
|
|
45
|
+
|
|
46
|
+
[tool.pylint.messages_control]
|
|
47
|
+
disable = [
|
|
48
|
+
"missing-final-newline",
|
|
49
|
+
"missing-module-docstring",
|
|
50
|
+
"missing-function-docstring",
|
|
51
|
+
"missing-class-docstring",
|
|
52
|
+
"too-few-public-methods",
|
|
53
|
+
"too-many-branches",
|
|
54
|
+
"too-many-return-statements",
|
|
55
|
+
"too-many-statements",
|
|
56
|
+
"too-many-locals",
|
|
57
|
+
"too-many-lines",
|
|
58
|
+
"too-many-arguments",
|
|
59
|
+
"too-many-instance-attributes",
|
|
60
|
+
"too-many-boolean-expressions",
|
|
61
|
+
"too-many-positional-arguments",
|
|
62
|
+
"protected-access",
|
|
63
|
+
"duplicate-code",
|
|
64
|
+
"too-many-nested-blocks",
|
|
65
|
+
"line-too-long",
|
|
66
|
+
"import-outside-toplevel",
|
|
67
|
+
"invalid-name"
|
|
68
|
+
]
|
|
69
|
+
|
|
70
|
+
[tool.black]
|
|
71
|
+
line-length = 180
|
|
72
|
+
|
|
73
|
+
[tool.pyright]
|
|
74
|
+
include = ["src"]
|
|
75
|
+
pythonVersion = "3.11"
|
|
76
|
+
pythonPlatform = "Linux"
|
|
77
|
+
reportAttributeAccessIssue = "none"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "3.0.0"
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
from .errors import NotFoundError, TypeMismatchError
|
|
2
|
+
from .filter import (FilterBinaryExpression, FilterBinaryOperator,
|
|
3
|
+
FilterExpression, FilterExpressionVisitor,
|
|
4
|
+
FilterUnaryExpression, FilterUnaryOperator,
|
|
5
|
+
NounPhrasesExpression, ValueExpression)
|
|
6
|
+
from .noun_phrase import NounPhrase
|
|
7
|
+
from .table import Table
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
from ..reflection.types import ConceptType
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class TypeMismatchError(Exception):
|
|
7
|
+
where: str
|
|
8
|
+
expected: Optional[ConceptType]
|
|
9
|
+
|
|
10
|
+
def __init__(self, where: str, expected: ConceptType):
|
|
11
|
+
self.where = where
|
|
12
|
+
self.expected = expected
|
|
13
|
+
super().__init__(f"type mismatch on {where} expected {expected}")
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class NotFoundError(Exception):
|
|
17
|
+
message: str
|
|
18
|
+
|
|
19
|
+
def __init__(self, message: str):
|
|
20
|
+
self.message = message
|
|
21
|
+
super().__init__(message)
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from abc import ABC, abstractmethod
|
|
4
|
+
from datetime import date, datetime, time
|
|
5
|
+
from enum import Enum
|
|
6
|
+
from typing import Generic, List, TypeVar
|
|
7
|
+
|
|
8
|
+
from kognitos.bdk.api.noun_phrase import NounPhrase
|
|
9
|
+
|
|
10
|
+
T = TypeVar("T")
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class FilterExpressionVisitor(ABC, Generic[T]):
|
|
14
|
+
@abstractmethod
|
|
15
|
+
def visit_binary_expression(self, expression: FilterBinaryExpression) -> T:
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
@abstractmethod
|
|
19
|
+
def visit_unary_expression(self, expression: FilterUnaryExpression) -> T:
|
|
20
|
+
pass
|
|
21
|
+
|
|
22
|
+
@abstractmethod
|
|
23
|
+
def visit_value(self, expression: ValueExpression) -> T:
|
|
24
|
+
pass
|
|
25
|
+
|
|
26
|
+
@abstractmethod
|
|
27
|
+
def visit_noun_phrases(self, expression: NounPhrasesExpression) -> T:
|
|
28
|
+
pass
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class FilterExpression(ABC):
|
|
32
|
+
@abstractmethod
|
|
33
|
+
def accept(self, visitor: FilterExpressionVisitor[T]) -> T:
|
|
34
|
+
pass
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class FilterBinaryOperator(Enum):
|
|
38
|
+
AND = 0
|
|
39
|
+
OR = 1
|
|
40
|
+
EQUALS = 2
|
|
41
|
+
NOT_EQUALS = 3
|
|
42
|
+
IN = 4
|
|
43
|
+
HAS = 5
|
|
44
|
+
LESS_THAN = 6
|
|
45
|
+
GREATER_THAN = 7
|
|
46
|
+
LESS_THAN_OR_EQUAL = 8
|
|
47
|
+
GREATER_THAN_OR_EQUAL = 9
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class FilterUnaryOperator(Enum):
|
|
51
|
+
NOT = 0
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class FilterBinaryExpression(FilterExpression):
|
|
55
|
+
def __init__(self, left: FilterExpression, operator: FilterBinaryOperator, right: FilterExpression):
|
|
56
|
+
self.operator = operator
|
|
57
|
+
self.left = left
|
|
58
|
+
self.right = right
|
|
59
|
+
|
|
60
|
+
def accept(self, visitor: FilterExpressionVisitor[T]) -> T:
|
|
61
|
+
return visitor.visit_binary_expression(self)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class FilterUnaryExpression(FilterExpression):
|
|
65
|
+
def __init__(self, operator: FilterUnaryOperator, inner: FilterExpression):
|
|
66
|
+
self.operator = operator
|
|
67
|
+
self.inner = inner
|
|
68
|
+
|
|
69
|
+
def accept(self, visitor: FilterExpressionVisitor[T]) -> T:
|
|
70
|
+
return visitor.visit_unary_expression(self)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class ValueExpression(FilterExpression):
|
|
74
|
+
def __init__(self, value: str | int | bool | float | date | datetime | time):
|
|
75
|
+
self.value = value
|
|
76
|
+
|
|
77
|
+
def accept(self, visitor: FilterExpressionVisitor[T]) -> T:
|
|
78
|
+
return visitor.visit_value(self)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class NounPhrasesExpression(FilterExpression):
|
|
82
|
+
def __init__(self, noun_phrases: List[NounPhrase]):
|
|
83
|
+
self.noun_phrases = noun_phrases
|
|
84
|
+
|
|
85
|
+
def accept(self, visitor: FilterExpressionVisitor[T]) -> T:
|
|
86
|
+
return visitor.visit_noun_phrases(self)
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import re
|
|
2
|
+
from dataclasses import dataclass
|
|
3
|
+
from typing import List, Optional, Tuple
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@dataclass
|
|
7
|
+
class NounPhrase:
|
|
8
|
+
"""Represents a noun phrase.
|
|
9
|
+
|
|
10
|
+
Args:
|
|
11
|
+
head (str): The head of the noun phrase.
|
|
12
|
+
modifiers (List[str], optional): The modifiers of the noun phrase. Defaults to None.
|
|
13
|
+
|
|
14
|
+
Methods:
|
|
15
|
+
__str__(): Returns a string representation of the noun phrase.
|
|
16
|
+
to_string(): Returns a string representation of the noun phrase.
|
|
17
|
+
|
|
18
|
+
Examples:
|
|
19
|
+
# Create a noun phrase with the head "cat"
|
|
20
|
+
>>> np = NounPhrase("cat")
|
|
21
|
+
>>> print(np)
|
|
22
|
+
cat
|
|
23
|
+
|
|
24
|
+
# Create a noun phrase with the head "dog" and modifiers ["big", "white"]
|
|
25
|
+
>>> np = NounPhrase("dog", ["big", "white"])
|
|
26
|
+
>>> print(np)
|
|
27
|
+
big white dog
|
|
28
|
+
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
head: str
|
|
32
|
+
modifiers: Optional[List[str]] = None
|
|
33
|
+
|
|
34
|
+
def __eq__(self, other):
|
|
35
|
+
if self.head != other.head:
|
|
36
|
+
return False
|
|
37
|
+
|
|
38
|
+
self_modifiers = self.modifiers if self.modifiers else []
|
|
39
|
+
other_modifiers = other.modifiers if other.modifiers else []
|
|
40
|
+
|
|
41
|
+
return self_modifiers == other_modifiers
|
|
42
|
+
|
|
43
|
+
def __str__(self):
|
|
44
|
+
return self.to_string()
|
|
45
|
+
|
|
46
|
+
def to_string(self):
|
|
47
|
+
return " ".join((self.modifiers if self.modifiers else []) + [self.head])
|
|
48
|
+
|
|
49
|
+
@classmethod
|
|
50
|
+
def from_snake_case(cls, snake_str: str) -> "NounPhrase":
|
|
51
|
+
# replace underscores with spaces
|
|
52
|
+
words = snake_str.replace("_", " ")
|
|
53
|
+
return NounPhrase(head=words, modifiers=[])
|
|
54
|
+
|
|
55
|
+
@classmethod
|
|
56
|
+
def from_pascal_case(cls, pascal_str: str) -> "NounPhrase":
|
|
57
|
+
# remove existing spaces
|
|
58
|
+
pascal_str = pascal_str.replace(" ", "")
|
|
59
|
+
# insert space before each capital letter (except the first one)
|
|
60
|
+
words = re.sub(r"(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])", " ", pascal_str).lower()
|
|
61
|
+
return NounPhrase(head=words, modifiers=[])
|
|
62
|
+
|
|
63
|
+
@classmethod
|
|
64
|
+
def from_head(cls, head: str) -> "NounPhrase":
|
|
65
|
+
return NounPhrase(head=head, modifiers=[])
|
|
66
|
+
|
|
67
|
+
@classmethod
|
|
68
|
+
def from_str(cls, string: str) -> "NounPhrase":
|
|
69
|
+
return NounPhrase.from_word_list(string.split(" "))
|
|
70
|
+
|
|
71
|
+
@classmethod
|
|
72
|
+
def from_word_list(cls, word_list: List[str]) -> "NounPhrase":
|
|
73
|
+
return NounPhrase(head=word_list[-1], modifiers=word_list[0:-1])
|
|
74
|
+
|
|
75
|
+
@classmethod
|
|
76
|
+
def from_tuple(cls, noun_phrase_tuple: Tuple[str, Optional[List[str]]]) -> "NounPhrase":
|
|
77
|
+
return NounPhrase(noun_phrase_tuple[0], noun_phrase_tuple[1])
|
|
78
|
+
|
|
79
|
+
def to_camel_case(self) -> str:
|
|
80
|
+
snake_str = self.to_snake_case()
|
|
81
|
+
components = snake_str.split("_")
|
|
82
|
+
return components[0] + "".join(x.title() for x in components[1:])
|
|
83
|
+
|
|
84
|
+
def to_snake_case(self) -> str:
|
|
85
|
+
text = self.to_string()
|
|
86
|
+
return text.lower().replace(" ", "_")
|
|
87
|
+
|
|
88
|
+
def to_kebab_case(self) -> str:
|
|
89
|
+
snake_str = self.to_snake_case()
|
|
90
|
+
return snake_str.replace("_", "-")
|
|
91
|
+
|
|
92
|
+
def to_field_names(self) -> List[str]:
|
|
93
|
+
snake_case = self.to_snake_case()
|
|
94
|
+
camel_case = self.to_camel_case()
|
|
95
|
+
kebab_case = self.to_kebab_case()
|
|
96
|
+
return [snake_case, camel_case, kebab_case]
|
|
97
|
+
|
|
98
|
+
def __hash__(self):
|
|
99
|
+
return hash((self.head, tuple(self.modifiers) if self.modifiers else ()))
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# type: ignore [reportReturnType]
|
|
2
|
+
from dataclasses import dataclass
|
|
3
|
+
from typing import IO, List, Optional, Union
|
|
4
|
+
|
|
5
|
+
from kognitos.bdk.api import FilterExpression
|
|
6
|
+
from kognitos.bdk.decorators import blueprint, blueprint_procedure, concept
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@dataclass
|
|
10
|
+
@concept(is_a="file reference")
|
|
11
|
+
class FileReference:
|
|
12
|
+
"""
|
|
13
|
+
Contains all information required to identify a file within a storage system
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass
|
|
18
|
+
@concept(is_a="folder reference")
|
|
19
|
+
class FolderReference:
|
|
20
|
+
"""
|
|
21
|
+
Contains all information required to identify a folder within a storage system
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@blueprint
|
|
26
|
+
class FileStorageBlueprint:
|
|
27
|
+
"""
|
|
28
|
+
A blueprint for files.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
@blueprint_procedure("to get a (root folder)")
|
|
32
|
+
def get_root_folder(self) -> FolderReference:
|
|
33
|
+
"""
|
|
34
|
+
Gets a reference to the root folder.
|
|
35
|
+
|
|
36
|
+
Returns:
|
|
37
|
+
a folder reference
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
@blueprint_procedure("to get a (folder) at a path")
|
|
41
|
+
def get_folder(self, path: str) -> FolderReference:
|
|
42
|
+
"""
|
|
43
|
+
Gets a reference to a folder.
|
|
44
|
+
|
|
45
|
+
Input Concepts:
|
|
46
|
+
the path: The path to the folder
|
|
47
|
+
|
|
48
|
+
Returns:
|
|
49
|
+
a folder reference
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
@blueprint_procedure("to get some (folder's items)")
|
|
53
|
+
def list_items(self, folder: FolderReference, filter_expression: Optional[FilterExpression] = None) -> List[Union[FileReference, FolderReference]]:
|
|
54
|
+
"""
|
|
55
|
+
Lists items from a folder reference
|
|
56
|
+
|
|
57
|
+
Input Concepts:
|
|
58
|
+
the folder: The folder reference from which to list the items
|
|
59
|
+
the filter expression: A filter expression to filter the items in the folder
|
|
60
|
+
|
|
61
|
+
Returns:
|
|
62
|
+
a list of Items (file or folder) containing the items in the folder
|
|
63
|
+
"""
|
|
64
|
+
|
|
65
|
+
@blueprint_procedure("to rename an item to a name")
|
|
66
|
+
def rename_item(self, item: Union[FileReference, FolderReference], name: str, conflict_behavior: Optional[str] = "fail") -> None:
|
|
67
|
+
"""
|
|
68
|
+
Rename an item (file or folder) to a given name
|
|
69
|
+
|
|
70
|
+
Input Concepts:
|
|
71
|
+
the item: The item (file or folder) to rename
|
|
72
|
+
the name: The new name of the item
|
|
73
|
+
the conflict behavior: The behavior to use on conflict scenarios. It should be one of the following values: ('fail', 'replace', 'rename')
|
|
74
|
+
"""
|
|
75
|
+
|
|
76
|
+
@blueprint_procedure("to delete an item")
|
|
77
|
+
def delete_an_item(self, item: Union[FileReference, FolderReference]) -> None:
|
|
78
|
+
"""
|
|
79
|
+
Delete an item (file or folder)
|
|
80
|
+
|
|
81
|
+
Input Concepts:
|
|
82
|
+
the item: The item (file or folder) to delete
|
|
83
|
+
"""
|
|
84
|
+
|
|
85
|
+
@blueprint_procedure("to download a file")
|
|
86
|
+
def download_item(self, file: FileReference) -> IO:
|
|
87
|
+
"""
|
|
88
|
+
Download a file
|
|
89
|
+
|
|
90
|
+
Input Concepts:
|
|
91
|
+
the file: The file reference to the file to download
|
|
92
|
+
|
|
93
|
+
Returns:
|
|
94
|
+
the file as an IO object
|
|
95
|
+
"""
|
|
96
|
+
|
|
97
|
+
@blueprint_procedure("to create a (folder) in another folder")
|
|
98
|
+
def create_folder(self, another_folder: FolderReference, folder_name: str, conflict_behavior: Optional[str] = "fail") -> FolderReference:
|
|
99
|
+
"""
|
|
100
|
+
Create a (folder) in another folder
|
|
101
|
+
|
|
102
|
+
Input Concepts:
|
|
103
|
+
the another folder: The folder to create the (folder) in
|
|
104
|
+
the folder name: The name of the (folder) to create
|
|
105
|
+
the conflict behavior: The behavior to use on conflict scenarios. It should be one of the following values: ('fail', 'replace', 'rename')
|
|
106
|
+
|
|
107
|
+
Returns:
|
|
108
|
+
a folder reference to the created folder
|
|
109
|
+
"""
|
|
110
|
+
|
|
111
|
+
@blueprint_procedure("to upload a (file) to a folder")
|
|
112
|
+
def upload_file_to_folder(self, file: IO, folder: FolderReference, file_name: str, conflict_behavior: Optional[str] = "fail") -> FileReference:
|
|
113
|
+
"""
|
|
114
|
+
Upload a file to a folder
|
|
115
|
+
|
|
116
|
+
Input Concepts:
|
|
117
|
+
the file: The file to upload
|
|
118
|
+
the folder: The folder to upload the file to
|
|
119
|
+
the file name: The name of the file to upload
|
|
120
|
+
the conflict behavior: The behavior to use on conflict scenarios. It should be one of the following values: ('fail', 'replace', 'rename')
|
|
121
|
+
|
|
122
|
+
Returns:
|
|
123
|
+
a file reference to the uploaded file
|
|
124
|
+
"""
|
|
125
|
+
|
|
126
|
+
@blueprint_procedure("to copy an item to a folder")
|
|
127
|
+
def copy_item(self, item: Union[FileReference, FolderReference], folder: FolderReference, conflict_behavior: Optional[str] = "fail") -> None:
|
|
128
|
+
"""
|
|
129
|
+
Copy an item to a folder
|
|
130
|
+
|
|
131
|
+
Input Concepts:
|
|
132
|
+
the item: The item (file or folder) to copy
|
|
133
|
+
the folder: The folder to copy the item to
|
|
134
|
+
the conflict behavior: The behavior to use on conflict scenarios. It should be one of the following values: ('fail', 'replace', 'rename')
|
|
135
|
+
"""
|
|
136
|
+
|
|
137
|
+
@blueprint_procedure("to move an item to a folder")
|
|
138
|
+
def move_item(self, item: Union[FileReference, FolderReference], folder: FolderReference, conflict_behavior: Optional[str] = "fail") -> None:
|
|
139
|
+
"""
|
|
140
|
+
Move an item to a folder
|
|
141
|
+
|
|
142
|
+
Input Concepts:
|
|
143
|
+
the item: The item (file or folder) to move
|
|
144
|
+
the folder: The folder to move the item to
|
|
145
|
+
the conflict behavior: The behavior to use on conflict scenarios. It should be one of the following values: ('fail', 'replace', 'rename')
|
|
146
|
+
"""
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
from .blueprint_decorator import blueprint, blueprint_procedure
|
|
2
|
+
from .book_decorator import book
|
|
3
|
+
from .concept_decorator import concept
|
|
4
|
+
from .config_decorator import config
|
|
5
|
+
from .connect_decorator import connect
|
|
6
|
+
from .oauth_decorator import OAuthFlow, OAuthProvider, oauth
|
|
7
|
+
from .oauthtoken_decorator import oauthtoken
|
|
8
|
+
from .procedure_decorator import procedure
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import inspect
|
|
2
|
+
from functools import wraps
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
from ..reflection import BookProcedureSignature
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def blueprint(*args):
|
|
9
|
+
cls = Optional[type]
|
|
10
|
+
|
|
11
|
+
# NOTE: We only care about the first argument, the rest of args and all kwargs are ignored.
|
|
12
|
+
if len(args) >= 1 and inspect.isclass(args[0]):
|
|
13
|
+
cls = args[0]
|
|
14
|
+
|
|
15
|
+
def decorator(cls):
|
|
16
|
+
if not hasattr(cls.__dict__, "__is_blueprint"):
|
|
17
|
+
cls.__is_blueprint = True
|
|
18
|
+
return cls
|
|
19
|
+
|
|
20
|
+
return decorator(cls)
|
|
21
|
+
|
|
22
|
+
raise ValueError("@blueprint decorator must be applied to a class.")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def blueprint_procedure(name: str):
|
|
26
|
+
# This is here to verify that the english is valid
|
|
27
|
+
BookProcedureSignature.from_english(name)
|
|
28
|
+
|
|
29
|
+
def wrapper(fn):
|
|
30
|
+
return wraps(fn)(fn)
|
|
31
|
+
|
|
32
|
+
return wrapper
|