Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +1 -0
- llava_next/lib/python3.10/site-packages/torch/include/ATen/ops/_upsample_nearest_exact3d_backward_ops.h +39 -0
- llava_next/lib/python3.10/site-packages/torch/include/ATen/ops/bitwise_left_shift_compositeexplicitautograd_dispatch.h +29 -0
- llava_next/lib/python3.10/site-packages/torch/include/ATen/ops/special_chebyshev_polynomial_u_cpu_dispatch.h +25 -0
- parrot/lib/python3.10/site-packages/openpyxl/cell/__init__.py +4 -0
- parrot/lib/python3.10/site-packages/openpyxl/cell/__pycache__/cell.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/openpyxl/cell/__pycache__/read_only.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/openpyxl/cell/__pycache__/rich_text.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/openpyxl/cell/cell.py +332 -0
- parrot/lib/python3.10/site-packages/openpyxl/cell/rich_text.py +202 -0
- parrot/lib/python3.10/site-packages/openpyxl/descriptors/__init__.py +58 -0
- parrot/lib/python3.10/site-packages/openpyxl/descriptors/__pycache__/excel.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/openpyxl/descriptors/__pycache__/serialisable.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/openpyxl/descriptors/__pycache__/slots.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/openpyxl/descriptors/base.py +272 -0
- parrot/lib/python3.10/site-packages/openpyxl/descriptors/container.py +41 -0
- parrot/lib/python3.10/site-packages/openpyxl/descriptors/sequence.py +136 -0
- parrot/lib/python3.10/site-packages/openpyxl/descriptors/slots.py +18 -0
- parrot/lib/python3.10/site-packages/openpyxl/drawing/__init__.py +4 -0
- parrot/lib/python3.10/site-packages/openpyxl/drawing/drawing.py +92 -0
- parrot/lib/python3.10/site-packages/openpyxl/drawing/graphic.py +177 -0
- parrot/lib/python3.10/site-packages/openpyxl/drawing/image.py +65 -0
- parrot/lib/python3.10/site-packages/openpyxl/pivot/__pycache__/record.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/openpyxl/reader/__init__.py +1 -0
- parrot/lib/python3.10/site-packages/openpyxl/reader/__pycache__/drawings.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/openpyxl/reader/excel.py +349 -0
- parrot/lib/python3.10/site-packages/openpyxl/reader/strings.py +44 -0
- parrot/lib/python3.10/site-packages/openpyxl/worksheet/__pycache__/_read_only.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/openpyxl/worksheet/__pycache__/_reader.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/openpyxl/worksheet/__pycache__/datavalidation.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/openpyxl/worksheet/__pycache__/dimensions.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/openpyxl/worksheet/__pycache__/header_footer.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/openpyxl/worksheet/__pycache__/hyperlink.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/openpyxl/worksheet/__pycache__/ole.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/openpyxl/worksheet/__pycache__/page.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/openpyxl/worksheet/__pycache__/properties.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/openpyxl/worksheet/__pycache__/smart_tag.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/openpyxl/worksheet/picture.py +8 -0
- parrot/lib/python3.10/site-packages/openpyxl/xml/__pycache__/__init__.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/openpyxl/xml/__pycache__/functions.cpython-310.pyc +0 -0
- vlmpy310/lib/python3.10/site-packages/Pympler-1.1.dist-info/INSTALLER +1 -0
- vlmpy310/lib/python3.10/site-packages/Pympler-1.1.dist-info/RECORD +63 -0
- vlmpy310/lib/python3.10/site-packages/Pympler-1.1.dist-info/WHEEL +5 -0
- vlmpy310/lib/python3.10/site-packages/Pympler-1.1.dist-info/top_level.txt +1 -0
- vlmpy310/lib/python3.10/site-packages/antlr4/BufferedTokenStream.py +302 -0
- vlmpy310/lib/python3.10/site-packages/antlr4/CommonTokenFactory.py +61 -0
- vlmpy310/lib/python3.10/site-packages/antlr4/CommonTokenStream.py +87 -0
- vlmpy310/lib/python3.10/site-packages/antlr4/FileStream.py +27 -0
- vlmpy310/lib/python3.10/site-packages/antlr4/InputStream.py +87 -0
- vlmpy310/lib/python3.10/site-packages/antlr4/IntervalSet.py +180 -0
.gitattributes
CHANGED
|
@@ -1247,3 +1247,4 @@ parrot/lib/python3.10/site-packages/nvidia/nccl/lib/libnccl.so.2 filter=lfs diff
|
|
| 1247 |
openflamingo/lib/python3.10/site-packages/scipy/sparse/_sparsetools.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 1248 |
vlmpy310/lib/python3.10/site-packages/pandas/_libs/tslibs/np_datetime.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 1249 |
vlmpy310/lib/python3.10/site-packages/pandas/io/__pycache__/stata.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 1247 |
openflamingo/lib/python3.10/site-packages/scipy/sparse/_sparsetools.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 1248 |
vlmpy310/lib/python3.10/site-packages/pandas/_libs/tslibs/np_datetime.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 1249 |
vlmpy310/lib/python3.10/site-packages/pandas/io/__pycache__/stata.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 1250 |
+
vlmpy310/lib/python3.10/site-packages/pyparsing/__pycache__/core.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
llava_next/lib/python3.10/site-packages/torch/include/ATen/ops/_upsample_nearest_exact3d_backward_ops.h
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
// @generated by torchgen/gen.py from Operator.h
|
| 4 |
+
|
| 5 |
+
#include <tuple>
|
| 6 |
+
#include <vector>
|
| 7 |
+
|
| 8 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 9 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 10 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 11 |
+
#include <ATen/core/ATen_fwd.h>
|
| 12 |
+
|
| 13 |
+
namespace at {
|
| 14 |
+
namespace _ops {
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
struct TORCH_API _upsample_nearest_exact3d_backward_grad_input {
|
| 18 |
+
using schema = at::Tensor & (const at::Tensor &, c10::SymIntArrayRef, c10::SymIntArrayRef, c10::optional<double>, c10::optional<double>, c10::optional<double>, at::Tensor &);
|
| 19 |
+
using ptr_schema = schema*;
|
| 20 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 21 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::_upsample_nearest_exact3d_backward")
|
| 22 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "grad_input")
|
| 23 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "_upsample_nearest_exact3d_backward.grad_input(Tensor grad_output, SymInt[3] output_size, SymInt[5] input_size, float? scales_d=None, float? scales_h=None, float? scales_w=None, *, Tensor(a!) grad_input) -> Tensor(a!)")
|
| 24 |
+
static at::Tensor & call(const at::Tensor & grad_output, c10::SymIntArrayRef output_size, c10::SymIntArrayRef input_size, c10::optional<double> scales_d, c10::optional<double> scales_h, c10::optional<double> scales_w, at::Tensor & grad_input);
|
| 25 |
+
static at::Tensor & redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & grad_output, c10::SymIntArrayRef output_size, c10::SymIntArrayRef input_size, c10::optional<double> scales_d, c10::optional<double> scales_h, c10::optional<double> scales_w, at::Tensor & grad_input);
|
| 26 |
+
};
|
| 27 |
+
|
| 28 |
+
struct TORCH_API _upsample_nearest_exact3d_backward {
|
| 29 |
+
using schema = at::Tensor (const at::Tensor &, c10::SymIntArrayRef, c10::SymIntArrayRef, c10::optional<double>, c10::optional<double>, c10::optional<double>);
|
| 30 |
+
using ptr_schema = schema*;
|
| 31 |
+
// See Note [static constexpr char* members for windows NVCC]
|
| 32 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::_upsample_nearest_exact3d_backward")
|
| 33 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "")
|
| 34 |
+
STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "_upsample_nearest_exact3d_backward(Tensor grad_output, SymInt[3] output_size, SymInt[5] input_size, float? scales_d=None, float? scales_h=None, float? scales_w=None) -> Tensor")
|
| 35 |
+
static at::Tensor call(const at::Tensor & grad_output, c10::SymIntArrayRef output_size, c10::SymIntArrayRef input_size, c10::optional<double> scales_d, c10::optional<double> scales_h, c10::optional<double> scales_w);
|
| 36 |
+
static at::Tensor redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & grad_output, c10::SymIntArrayRef output_size, c10::SymIntArrayRef input_size, c10::optional<double> scales_d, c10::optional<double> scales_h, c10::optional<double> scales_w);
|
| 37 |
+
};
|
| 38 |
+
|
| 39 |
+
}} // namespace at::_ops
|
llava_next/lib/python3.10/site-packages/torch/include/ATen/ops/bitwise_left_shift_compositeexplicitautograd_dispatch.h
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace compositeexplicitautograd {
|
| 19 |
+
|
| 20 |
+
TORCH_API at::Tensor bitwise_left_shift(const at::Tensor & self, const at::Scalar & other);
|
| 21 |
+
TORCH_API at::Tensor & bitwise_left_shift_out(at::Tensor & out, const at::Tensor & self, const at::Scalar & other);
|
| 22 |
+
TORCH_API at::Tensor & bitwise_left_shift_outf(const at::Tensor & self, const at::Scalar & other, at::Tensor & out);
|
| 23 |
+
TORCH_API at::Tensor & bitwise_left_shift_(at::Tensor & self, const at::Scalar & other);
|
| 24 |
+
TORCH_API at::Tensor bitwise_left_shift(const at::Scalar & self, const at::Tensor & other);
|
| 25 |
+
TORCH_API at::Tensor & bitwise_left_shift_out(at::Tensor & out, const at::Scalar & self, const at::Tensor & other);
|
| 26 |
+
TORCH_API at::Tensor & bitwise_left_shift_outf(const at::Scalar & self, const at::Tensor & other, at::Tensor & out);
|
| 27 |
+
|
| 28 |
+
} // namespace compositeexplicitautograd
|
| 29 |
+
} // namespace at
|
llava_next/lib/python3.10/site-packages/torch/include/ATen/ops/special_chebyshev_polynomial_u_cpu_dispatch.h
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
// @generated by torchgen/gen.py from DispatchKeyFunction.h
|
| 3 |
+
|
| 4 |
+
// NB: The implementing C++ file is RegisterDispatchKey.cpp
|
| 5 |
+
|
| 6 |
+
// The only #includes we need are for custom classes that have defaults in the C++ API
|
| 7 |
+
#include <c10/core/MemoryFormat.h>
|
| 8 |
+
#include <c10/core/Scalar.h>
|
| 9 |
+
#include <ATen/core/Reduction.h>
|
| 10 |
+
|
| 11 |
+
// Forward declarations of any types needed in the operator signatures.
|
| 12 |
+
// We can't directly include these classes because it will cause circular include dependencies.
|
| 13 |
+
// This file is included by TensorBody.h, which defines the Tensor class.
|
| 14 |
+
#include <ATen/core/ATen_fwd.h>
|
| 15 |
+
|
| 16 |
+
namespace at {
|
| 17 |
+
|
| 18 |
+
namespace cpu {
|
| 19 |
+
|
| 20 |
+
TORCH_API at::Tensor special_chebyshev_polynomial_u(const at::Tensor & x, const at::Tensor & n);
|
| 21 |
+
TORCH_API at::Tensor & special_chebyshev_polynomial_u_out(at::Tensor & out, const at::Tensor & x, const at::Tensor & n);
|
| 22 |
+
TORCH_API at::Tensor & special_chebyshev_polynomial_u_outf(const at::Tensor & x, const at::Tensor & n, at::Tensor & out);
|
| 23 |
+
|
| 24 |
+
} // namespace cpu
|
| 25 |
+
} // namespace at
|
parrot/lib/python3.10/site-packages/openpyxl/cell/__init__.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2010-2024 openpyxl
|
| 2 |
+
|
| 3 |
+
from .cell import Cell, WriteOnlyCell, MergedCell
|
| 4 |
+
from .read_only import ReadOnlyCell
|
parrot/lib/python3.10/site-packages/openpyxl/cell/__pycache__/cell.cpython-310.pyc
ADDED
|
Binary file (8.56 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/openpyxl/cell/__pycache__/read_only.cpython-310.pyc
ADDED
|
Binary file (4.23 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/openpyxl/cell/__pycache__/rich_text.cpython-310.pyc
ADDED
|
Binary file (6.42 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/openpyxl/cell/cell.py
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2010-2024 openpyxl
|
| 2 |
+
|
| 3 |
+
"""Manage individual cells in a spreadsheet.
|
| 4 |
+
|
| 5 |
+
The Cell class is required to know its value and type, display options,
|
| 6 |
+
and any other features of an Excel cell. Utilities for referencing
|
| 7 |
+
cells using Excel's 'A1' column/row nomenclature are also provided.
|
| 8 |
+
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
__docformat__ = "restructuredtext en"
|
| 12 |
+
|
| 13 |
+
# Python stdlib imports
|
| 14 |
+
from copy import copy
|
| 15 |
+
import datetime
|
| 16 |
+
import re
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
from openpyxl.compat import (
|
| 20 |
+
NUMERIC_TYPES,
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
from openpyxl.utils.exceptions import IllegalCharacterError
|
| 24 |
+
|
| 25 |
+
from openpyxl.utils import get_column_letter
|
| 26 |
+
from openpyxl.styles import numbers, is_date_format
|
| 27 |
+
from openpyxl.styles.styleable import StyleableObject
|
| 28 |
+
from openpyxl.worksheet.hyperlink import Hyperlink
|
| 29 |
+
from openpyxl.worksheet.formula import DataTableFormula, ArrayFormula
|
| 30 |
+
from openpyxl.cell.rich_text import CellRichText
|
| 31 |
+
|
| 32 |
+
# constants
|
| 33 |
+
|
| 34 |
+
TIME_TYPES = (datetime.datetime, datetime.date, datetime.time, datetime.timedelta)
|
| 35 |
+
TIME_FORMATS = {
|
| 36 |
+
datetime.datetime:numbers.FORMAT_DATE_DATETIME,
|
| 37 |
+
datetime.date:numbers.FORMAT_DATE_YYYYMMDD2,
|
| 38 |
+
datetime.time:numbers.FORMAT_DATE_TIME6,
|
| 39 |
+
datetime.timedelta:numbers.FORMAT_DATE_TIMEDELTA,
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
STRING_TYPES = (str, bytes, CellRichText)
|
| 43 |
+
KNOWN_TYPES = NUMERIC_TYPES + TIME_TYPES + STRING_TYPES + (bool, type(None))
|
| 44 |
+
|
| 45 |
+
ILLEGAL_CHARACTERS_RE = re.compile(r'[\000-\010]|[\013-\014]|[\016-\037]')
|
| 46 |
+
ERROR_CODES = ('#NULL!', '#DIV/0!', '#VALUE!', '#REF!', '#NAME?', '#NUM!',
|
| 47 |
+
'#N/A')
|
| 48 |
+
|
| 49 |
+
TYPE_STRING = 's'
|
| 50 |
+
TYPE_FORMULA = 'f'
|
| 51 |
+
TYPE_NUMERIC = 'n'
|
| 52 |
+
TYPE_BOOL = 'b'
|
| 53 |
+
TYPE_NULL = 'n'
|
| 54 |
+
TYPE_INLINE = 'inlineStr'
|
| 55 |
+
TYPE_ERROR = 'e'
|
| 56 |
+
TYPE_FORMULA_CACHE_STRING = 'str'
|
| 57 |
+
|
| 58 |
+
VALID_TYPES = (TYPE_STRING, TYPE_FORMULA, TYPE_NUMERIC, TYPE_BOOL,
|
| 59 |
+
TYPE_NULL, TYPE_INLINE, TYPE_ERROR, TYPE_FORMULA_CACHE_STRING)
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
_TYPES = {int:'n', float:'n', str:'s', bool:'b'}
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def get_type(t, value):
|
| 66 |
+
if isinstance(value, NUMERIC_TYPES):
|
| 67 |
+
dt = 'n'
|
| 68 |
+
elif isinstance(value, STRING_TYPES):
|
| 69 |
+
dt = 's'
|
| 70 |
+
elif isinstance(value, TIME_TYPES):
|
| 71 |
+
dt = 'd'
|
| 72 |
+
elif isinstance(value, (DataTableFormula, ArrayFormula)):
|
| 73 |
+
dt = 'f'
|
| 74 |
+
else:
|
| 75 |
+
return
|
| 76 |
+
_TYPES[t] = dt
|
| 77 |
+
return dt
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def get_time_format(t):
|
| 81 |
+
value = TIME_FORMATS.get(t)
|
| 82 |
+
if value:
|
| 83 |
+
return value
|
| 84 |
+
for base in t.mro()[1:]:
|
| 85 |
+
value = TIME_FORMATS.get(base)
|
| 86 |
+
if value:
|
| 87 |
+
TIME_FORMATS[t] = value
|
| 88 |
+
return value
|
| 89 |
+
raise ValueError("Could not get time format for {0!r}".format(value))
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
class Cell(StyleableObject):
|
| 93 |
+
"""Describes cell associated properties.
|
| 94 |
+
|
| 95 |
+
Properties of interest include style, type, value, and address.
|
| 96 |
+
|
| 97 |
+
"""
|
| 98 |
+
__slots__ = (
|
| 99 |
+
'row',
|
| 100 |
+
'column',
|
| 101 |
+
'_value',
|
| 102 |
+
'data_type',
|
| 103 |
+
'parent',
|
| 104 |
+
'_hyperlink',
|
| 105 |
+
'_comment',
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
def __init__(self, worksheet, row=None, column=None, value=None, style_array=None):
|
| 109 |
+
super().__init__(worksheet, style_array)
|
| 110 |
+
self.row = row
|
| 111 |
+
"""Row number of this cell (1-based)"""
|
| 112 |
+
self.column = column
|
| 113 |
+
"""Column number of this cell (1-based)"""
|
| 114 |
+
# _value is the stored value, while value is the displayed value
|
| 115 |
+
self._value = None
|
| 116 |
+
self._hyperlink = None
|
| 117 |
+
self.data_type = 'n'
|
| 118 |
+
if value is not None:
|
| 119 |
+
self.value = value
|
| 120 |
+
self._comment = None
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
@property
|
| 124 |
+
def coordinate(self):
|
| 125 |
+
"""This cell's coordinate (ex. 'A5')"""
|
| 126 |
+
col = get_column_letter(self.column)
|
| 127 |
+
return f"{col}{self.row}"
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
@property
|
| 131 |
+
def col_idx(self):
|
| 132 |
+
"""The numerical index of the column"""
|
| 133 |
+
return self.column
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
@property
|
| 137 |
+
def column_letter(self):
|
| 138 |
+
return get_column_letter(self.column)
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
@property
|
| 142 |
+
def encoding(self):
|
| 143 |
+
return self.parent.encoding
|
| 144 |
+
|
| 145 |
+
@property
|
| 146 |
+
def base_date(self):
|
| 147 |
+
return self.parent.parent.epoch
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
def __repr__(self):
|
| 151 |
+
return "<Cell {0!r}.{1}>".format(self.parent.title, self.coordinate)
|
| 152 |
+
|
| 153 |
+
def check_string(self, value):
|
| 154 |
+
"""Check string coding, length, and line break character"""
|
| 155 |
+
if value is None:
|
| 156 |
+
return
|
| 157 |
+
# convert to str string
|
| 158 |
+
if not isinstance(value, str):
|
| 159 |
+
value = str(value, self.encoding)
|
| 160 |
+
value = str(value)
|
| 161 |
+
# string must never be longer than 32,767 characters
|
| 162 |
+
# truncate if necessary
|
| 163 |
+
value = value[:32767]
|
| 164 |
+
if next(ILLEGAL_CHARACTERS_RE.finditer(value), None):
|
| 165 |
+
raise IllegalCharacterError(f"{value} cannot be used in worksheets.")
|
| 166 |
+
return value
|
| 167 |
+
|
| 168 |
+
def check_error(self, value):
|
| 169 |
+
"""Tries to convert Error" else N/A"""
|
| 170 |
+
try:
|
| 171 |
+
return str(value)
|
| 172 |
+
except UnicodeDecodeError:
|
| 173 |
+
return u'#N/A'
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
def _bind_value(self, value):
|
| 177 |
+
"""Given a value, infer the correct data type"""
|
| 178 |
+
|
| 179 |
+
self.data_type = "n"
|
| 180 |
+
t = type(value)
|
| 181 |
+
try:
|
| 182 |
+
dt = _TYPES[t]
|
| 183 |
+
except KeyError:
|
| 184 |
+
dt = get_type(t, value)
|
| 185 |
+
|
| 186 |
+
if dt is None and value is not None:
|
| 187 |
+
raise ValueError("Cannot convert {0!r} to Excel".format(value))
|
| 188 |
+
|
| 189 |
+
if dt:
|
| 190 |
+
self.data_type = dt
|
| 191 |
+
|
| 192 |
+
if dt == 'd':
|
| 193 |
+
if not is_date_format(self.number_format):
|
| 194 |
+
self.number_format = get_time_format(t)
|
| 195 |
+
|
| 196 |
+
elif dt == "s" and not isinstance(value, CellRichText):
|
| 197 |
+
value = self.check_string(value)
|
| 198 |
+
if len(value) > 1 and value.startswith("="):
|
| 199 |
+
self.data_type = 'f'
|
| 200 |
+
elif value in ERROR_CODES:
|
| 201 |
+
self.data_type = 'e'
|
| 202 |
+
|
| 203 |
+
self._value = value
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
@property
|
| 207 |
+
def value(self):
|
| 208 |
+
"""Get or set the value held in the cell.
|
| 209 |
+
|
| 210 |
+
:type: depends on the value (string, float, int or
|
| 211 |
+
:class:`datetime.datetime`)
|
| 212 |
+
"""
|
| 213 |
+
return self._value
|
| 214 |
+
|
| 215 |
+
@value.setter
|
| 216 |
+
def value(self, value):
|
| 217 |
+
"""Set the value and infer type and display options."""
|
| 218 |
+
self._bind_value(value)
|
| 219 |
+
|
| 220 |
+
@property
|
| 221 |
+
def internal_value(self):
|
| 222 |
+
"""Always returns the value for excel."""
|
| 223 |
+
return self._value
|
| 224 |
+
|
| 225 |
+
@property
|
| 226 |
+
def hyperlink(self):
|
| 227 |
+
"""Return the hyperlink target or an empty string"""
|
| 228 |
+
return self._hyperlink
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
@hyperlink.setter
|
| 232 |
+
def hyperlink(self, val):
|
| 233 |
+
"""Set value and display for hyperlinks in a cell.
|
| 234 |
+
Automatically sets the `value` of the cell with link text,
|
| 235 |
+
but you can modify it afterwards by setting the `value`
|
| 236 |
+
property, and the hyperlink will remain.
|
| 237 |
+
Hyperlink is removed if set to ``None``."""
|
| 238 |
+
if val is None:
|
| 239 |
+
self._hyperlink = None
|
| 240 |
+
else:
|
| 241 |
+
if not isinstance(val, Hyperlink):
|
| 242 |
+
val = Hyperlink(ref="", target=val)
|
| 243 |
+
val.ref = self.coordinate
|
| 244 |
+
self._hyperlink = val
|
| 245 |
+
if self._value is None:
|
| 246 |
+
self.value = val.target or val.location
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
@property
|
| 250 |
+
def is_date(self):
|
| 251 |
+
"""True if the value is formatted as a date
|
| 252 |
+
|
| 253 |
+
:type: bool
|
| 254 |
+
"""
|
| 255 |
+
return self.data_type == 'd' or (
|
| 256 |
+
self.data_type == 'n' and is_date_format(self.number_format)
|
| 257 |
+
)
|
| 258 |
+
|
| 259 |
+
|
| 260 |
+
def offset(self, row=0, column=0):
|
| 261 |
+
"""Returns a cell location relative to this cell.
|
| 262 |
+
|
| 263 |
+
:param row: number of rows to offset
|
| 264 |
+
:type row: int
|
| 265 |
+
|
| 266 |
+
:param column: number of columns to offset
|
| 267 |
+
:type column: int
|
| 268 |
+
|
| 269 |
+
:rtype: :class:`openpyxl.cell.Cell`
|
| 270 |
+
"""
|
| 271 |
+
offset_column = self.col_idx + column
|
| 272 |
+
offset_row = self.row + row
|
| 273 |
+
return self.parent.cell(column=offset_column, row=offset_row)
|
| 274 |
+
|
| 275 |
+
|
| 276 |
+
@property
|
| 277 |
+
def comment(self):
|
| 278 |
+
""" Returns the comment associated with this cell
|
| 279 |
+
|
| 280 |
+
:type: :class:`openpyxl.comments.Comment`
|
| 281 |
+
"""
|
| 282 |
+
return self._comment
|
| 283 |
+
|
| 284 |
+
|
| 285 |
+
@comment.setter
|
| 286 |
+
def comment(self, value):
|
| 287 |
+
"""
|
| 288 |
+
Assign a comment to a cell
|
| 289 |
+
"""
|
| 290 |
+
|
| 291 |
+
if value is not None:
|
| 292 |
+
if value.parent:
|
| 293 |
+
value = copy(value)
|
| 294 |
+
value.bind(self)
|
| 295 |
+
elif value is None and self._comment:
|
| 296 |
+
self._comment.unbind()
|
| 297 |
+
self._comment = value
|
| 298 |
+
|
| 299 |
+
|
| 300 |
+
class MergedCell(StyleableObject):
|
| 301 |
+
|
| 302 |
+
"""
|
| 303 |
+
Describes the properties of a cell in a merged cell and helps to
|
| 304 |
+
display the borders of the merged cell.
|
| 305 |
+
|
| 306 |
+
The value of a MergedCell is always None.
|
| 307 |
+
"""
|
| 308 |
+
|
| 309 |
+
__slots__ = ('row', 'column')
|
| 310 |
+
|
| 311 |
+
_value = None
|
| 312 |
+
data_type = "n"
|
| 313 |
+
comment = None
|
| 314 |
+
hyperlink = None
|
| 315 |
+
|
| 316 |
+
|
| 317 |
+
def __init__(self, worksheet, row=None, column=None):
|
| 318 |
+
super().__init__(worksheet)
|
| 319 |
+
self.row = row
|
| 320 |
+
self.column = column
|
| 321 |
+
|
| 322 |
+
|
| 323 |
+
def __repr__(self):
|
| 324 |
+
return "<MergedCell {0!r}.{1}>".format(self.parent.title, self.coordinate)
|
| 325 |
+
|
| 326 |
+
coordinate = Cell.coordinate
|
| 327 |
+
_comment = comment
|
| 328 |
+
value = _value
|
| 329 |
+
|
| 330 |
+
|
| 331 |
+
def WriteOnlyCell(ws=None, value=None):
|
| 332 |
+
return Cell(worksheet=ws, column=1, row=1, value=value)
|
parrot/lib/python3.10/site-packages/openpyxl/cell/rich_text.py
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2010-2024 openpyxl
|
| 2 |
+
|
| 3 |
+
"""
|
| 4 |
+
RichText definition
|
| 5 |
+
"""
|
| 6 |
+
from copy import copy
|
| 7 |
+
from openpyxl.compat import NUMERIC_TYPES
|
| 8 |
+
from openpyxl.cell.text import InlineFont, Text
|
| 9 |
+
from openpyxl.descriptors import (
|
| 10 |
+
Strict,
|
| 11 |
+
String,
|
| 12 |
+
Typed
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
from openpyxl.xml.functions import Element, whitespace
|
| 16 |
+
|
| 17 |
+
class TextBlock(Strict):
|
| 18 |
+
""" Represents text string in a specific format
|
| 19 |
+
|
| 20 |
+
This class is used as part of constructing a rich text strings.
|
| 21 |
+
"""
|
| 22 |
+
font = Typed(expected_type=InlineFont)
|
| 23 |
+
text = String()
|
| 24 |
+
|
| 25 |
+
def __init__(self, font, text):
|
| 26 |
+
self.font = font
|
| 27 |
+
self.text = text
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def __eq__(self, other):
|
| 31 |
+
return self.text == other.text and self.font == other.font
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def __str__(self):
|
| 35 |
+
"""Just retun the text"""
|
| 36 |
+
return self.text
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def __repr__(self):
|
| 40 |
+
font = self.font != InlineFont() and self.font or "default"
|
| 41 |
+
return f"{self.__class__.__name__} text={self.text}, font={font}"
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def to_tree(self):
|
| 45 |
+
el = Element("r")
|
| 46 |
+
el.append(self.font.to_tree(tagname="rPr"))
|
| 47 |
+
t = Element("t")
|
| 48 |
+
t.text = self.text
|
| 49 |
+
whitespace(t)
|
| 50 |
+
el.append(t)
|
| 51 |
+
return el
|
| 52 |
+
|
| 53 |
+
#
|
| 54 |
+
# Rich Text class.
|
| 55 |
+
# This class behaves just like a list whose members are either simple strings, or TextBlock() instances.
|
| 56 |
+
# In addition, it can be initialized in several ways:
|
| 57 |
+
# t = CellRFichText([...]) # initialize with a list.
|
| 58 |
+
# t = CellRFichText((...)) # initialize with a tuple.
|
| 59 |
+
# t = CellRichText(node) # where node is an Element() from either lxml or xml.etree (has a 'tag' element)
|
| 60 |
+
class CellRichText(list):
|
| 61 |
+
"""Represents a rich text string.
|
| 62 |
+
|
| 63 |
+
Initialize with a list made of pure strings or :class:`TextBlock` elements
|
| 64 |
+
Can index object to access or modify individual rich text elements
|
| 65 |
+
it also supports the + and += operators between rich text strings
|
| 66 |
+
There are no user methods for this class
|
| 67 |
+
|
| 68 |
+
operations which modify the string will generally call an optimization pass afterwards,
|
| 69 |
+
that merges text blocks with identical formats, consecutive pure text strings,
|
| 70 |
+
and remove empty strings and empty text blocks
|
| 71 |
+
"""
|
| 72 |
+
|
| 73 |
+
def __init__(self, *args):
|
| 74 |
+
if len(args) == 1:
|
| 75 |
+
args = args[0]
|
| 76 |
+
if isinstance(args, (list, tuple)):
|
| 77 |
+
CellRichText._check_rich_text(args)
|
| 78 |
+
else:
|
| 79 |
+
CellRichText._check_element(args)
|
| 80 |
+
args = [args]
|
| 81 |
+
else:
|
| 82 |
+
CellRichText._check_rich_text(args)
|
| 83 |
+
super().__init__(args)
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
@classmethod
|
| 87 |
+
def _check_element(cls, value):
|
| 88 |
+
if not isinstance(value, (str, TextBlock, NUMERIC_TYPES)):
|
| 89 |
+
raise TypeError(f"Illegal CellRichText element {value}")
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
@classmethod
|
| 93 |
+
def _check_rich_text(cls, rich_text):
|
| 94 |
+
for t in rich_text:
|
| 95 |
+
CellRichText._check_element(t)
|
| 96 |
+
|
| 97 |
+
@classmethod
|
| 98 |
+
def from_tree(cls, node):
|
| 99 |
+
text = Text.from_tree(node)
|
| 100 |
+
if text.t:
|
| 101 |
+
return (text.t.replace('x005F_', ''),)
|
| 102 |
+
s = []
|
| 103 |
+
for r in text.r:
|
| 104 |
+
t = ""
|
| 105 |
+
if r.t:
|
| 106 |
+
t = r.t.replace('x005F_', '')
|
| 107 |
+
if r.rPr:
|
| 108 |
+
s.append(TextBlock(r.rPr, t))
|
| 109 |
+
else:
|
| 110 |
+
s.append(t)
|
| 111 |
+
return cls(s)
|
| 112 |
+
|
| 113 |
+
# Merge TextBlocks with identical formatting
|
| 114 |
+
# remove empty elements
|
| 115 |
+
def _opt(self):
|
| 116 |
+
last_t = None
|
| 117 |
+
l = CellRichText(tuple())
|
| 118 |
+
for t in self:
|
| 119 |
+
if isinstance(t, str):
|
| 120 |
+
if not t:
|
| 121 |
+
continue
|
| 122 |
+
elif not t.text:
|
| 123 |
+
continue
|
| 124 |
+
if type(last_t) == type(t):
|
| 125 |
+
if isinstance(t, str):
|
| 126 |
+
last_t += t
|
| 127 |
+
continue
|
| 128 |
+
elif last_t.font == t.font:
|
| 129 |
+
last_t.text += t.text
|
| 130 |
+
continue
|
| 131 |
+
if last_t:
|
| 132 |
+
l.append(last_t)
|
| 133 |
+
last_t = t
|
| 134 |
+
if last_t:
|
| 135 |
+
# Add remaining TextBlock at end of rich text
|
| 136 |
+
l.append(last_t)
|
| 137 |
+
super().__setitem__(slice(None), l)
|
| 138 |
+
return self
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
def __iadd__(self, arg):
|
| 142 |
+
# copy used here to create new TextBlock() so we don't modify the right hand side in _opt()
|
| 143 |
+
CellRichText._check_rich_text(arg)
|
| 144 |
+
super().__iadd__([copy(e) for e in list(arg)])
|
| 145 |
+
return self._opt()
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
def __add__(self, arg):
|
| 149 |
+
return CellRichText([copy(e) for e in list(self) + list(arg)])._opt()
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
def __setitem__(self, indx, val):
|
| 153 |
+
CellRichText._check_element(val)
|
| 154 |
+
super().__setitem__(indx, val)
|
| 155 |
+
self._opt()
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
def append(self, arg):
|
| 159 |
+
CellRichText._check_element(arg)
|
| 160 |
+
super().append(arg)
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
def extend(self, arg):
|
| 164 |
+
CellRichText._check_rich_text(arg)
|
| 165 |
+
super().extend(arg)
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
def __repr__(self):
|
| 169 |
+
return "CellRichText([{}])".format(', '.join((repr(s) for s in self)))
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
def __str__(self):
|
| 173 |
+
return ''.join([str(s) for s in self])
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
def as_list(self):
|
| 177 |
+
"""
|
| 178 |
+
Returns a list of the strings contained.
|
| 179 |
+
The main reason for this is to make editing easier.
|
| 180 |
+
"""
|
| 181 |
+
return [str(s) for s in self]
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
def to_tree(self):
|
| 185 |
+
"""
|
| 186 |
+
Return the full XML representation
|
| 187 |
+
"""
|
| 188 |
+
container = Element("is")
|
| 189 |
+
for obj in self:
|
| 190 |
+
if isinstance(obj, TextBlock):
|
| 191 |
+
container.append(obj.to_tree())
|
| 192 |
+
|
| 193 |
+
else:
|
| 194 |
+
el = Element("r")
|
| 195 |
+
t = Element("t")
|
| 196 |
+
t.text = obj
|
| 197 |
+
whitespace(t)
|
| 198 |
+
el.append(t)
|
| 199 |
+
container.append(el)
|
| 200 |
+
|
| 201 |
+
return container
|
| 202 |
+
|
parrot/lib/python3.10/site-packages/openpyxl/descriptors/__init__.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2010-2024 openpyxl
|
| 2 |
+
|
| 3 |
+
from .base import *
|
| 4 |
+
from .sequence import Sequence
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class MetaStrict(type):
|
| 8 |
+
|
| 9 |
+
def __new__(cls, clsname, bases, methods):
|
| 10 |
+
for k, v in methods.items():
|
| 11 |
+
if isinstance(v, Descriptor):
|
| 12 |
+
v.name = k
|
| 13 |
+
return type.__new__(cls, clsname, bases, methods)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class Strict(metaclass=MetaStrict):
|
| 17 |
+
|
| 18 |
+
pass
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class MetaSerialisable(type):
|
| 22 |
+
|
| 23 |
+
def __new__(cls, clsname, bases, methods):
|
| 24 |
+
attrs = []
|
| 25 |
+
nested = []
|
| 26 |
+
elements = []
|
| 27 |
+
namespaced = []
|
| 28 |
+
for k, v in methods.items():
|
| 29 |
+
if isinstance(v, Descriptor):
|
| 30 |
+
ns= getattr(v, 'namespace', None)
|
| 31 |
+
if ns:
|
| 32 |
+
namespaced.append((k, "{%s}%s" % (ns, k)))
|
| 33 |
+
if getattr(v, 'nested', False):
|
| 34 |
+
nested.append(k)
|
| 35 |
+
elements.append(k)
|
| 36 |
+
elif isinstance(v, Sequence):
|
| 37 |
+
elements.append(k)
|
| 38 |
+
elif isinstance(v, Typed):
|
| 39 |
+
if hasattr(v.expected_type, 'to_tree'):
|
| 40 |
+
elements.append(k)
|
| 41 |
+
elif isinstance(v.expected_type, tuple):
|
| 42 |
+
if any((hasattr(el, "to_tree") for el in v.expected_type)):
|
| 43 |
+
# don't bind elements as attrs
|
| 44 |
+
continue
|
| 45 |
+
else:
|
| 46 |
+
attrs.append(k)
|
| 47 |
+
else:
|
| 48 |
+
if not isinstance(v, Alias):
|
| 49 |
+
attrs.append(k)
|
| 50 |
+
|
| 51 |
+
if methods.get('__attrs__') is None:
|
| 52 |
+
methods['__attrs__'] = tuple(attrs)
|
| 53 |
+
methods['__namespaced__'] = tuple(namespaced)
|
| 54 |
+
if methods.get('__nested__') is None:
|
| 55 |
+
methods['__nested__'] = tuple(sorted(nested))
|
| 56 |
+
if methods.get('__elements__') is None:
|
| 57 |
+
methods['__elements__'] = tuple(sorted(elements))
|
| 58 |
+
return MetaStrict.__new__(cls, clsname, bases, methods)
|
parrot/lib/python3.10/site-packages/openpyxl/descriptors/__pycache__/excel.cpython-310.pyc
ADDED
|
Binary file (3.58 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/openpyxl/descriptors/__pycache__/serialisable.cpython-310.pyc
ADDED
|
Binary file (5.32 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/openpyxl/descriptors/__pycache__/slots.cpython-310.pyc
ADDED
|
Binary file (1.03 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/openpyxl/descriptors/base.py
ADDED
|
@@ -0,0 +1,272 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2010-2024 openpyxl
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
"""
|
| 5 |
+
Based on Python Cookbook 3rd Edition, 8.13
|
| 6 |
+
http://chimera.labs.oreilly.com/books/1230000000393/ch08.html#_discussiuncion_130
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import datetime
|
| 10 |
+
import re
|
| 11 |
+
|
| 12 |
+
from openpyxl import DEBUG
|
| 13 |
+
from openpyxl.utils.datetime import from_ISO8601
|
| 14 |
+
|
| 15 |
+
from .namespace import namespaced
|
| 16 |
+
|
| 17 |
+
class Descriptor:
|
| 18 |
+
|
| 19 |
+
def __init__(self, name=None, **kw):
|
| 20 |
+
self.name = name
|
| 21 |
+
for k, v in kw.items():
|
| 22 |
+
setattr(self, k, v)
|
| 23 |
+
|
| 24 |
+
def __set__(self, instance, value):
|
| 25 |
+
instance.__dict__[self.name] = value
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
class Typed(Descriptor):
|
| 29 |
+
"""Values must of a particular type"""
|
| 30 |
+
|
| 31 |
+
expected_type = type(None)
|
| 32 |
+
allow_none = False
|
| 33 |
+
nested = False
|
| 34 |
+
|
| 35 |
+
def __init__(self, *args, **kw):
|
| 36 |
+
super().__init__(*args, **kw)
|
| 37 |
+
self.__doc__ = f"Values must be of type {self.expected_type}"
|
| 38 |
+
|
| 39 |
+
def __set__(self, instance, value):
|
| 40 |
+
if not isinstance(value, self.expected_type):
|
| 41 |
+
if (not self.allow_none
|
| 42 |
+
or (self.allow_none and value is not None)):
|
| 43 |
+
msg = f"{instance.__class__}.{self.name} should be {self.expected_type} but value is {type(value)}"
|
| 44 |
+
if DEBUG:
|
| 45 |
+
msg = f"{instance.__class__}.{self.name} should be {self.expected_type} but {value} is {type(value)}"
|
| 46 |
+
raise TypeError(msg)
|
| 47 |
+
super().__set__(instance, value)
|
| 48 |
+
|
| 49 |
+
def __repr__(self):
|
| 50 |
+
return self.__doc__
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def _convert(expected_type, value):
|
| 54 |
+
"""
|
| 55 |
+
Check value is of or can be converted to expected type.
|
| 56 |
+
"""
|
| 57 |
+
if not isinstance(value, expected_type):
|
| 58 |
+
try:
|
| 59 |
+
value = expected_type(value)
|
| 60 |
+
except:
|
| 61 |
+
raise TypeError('expected ' + str(expected_type))
|
| 62 |
+
return value
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
class Convertible(Typed):
|
| 66 |
+
"""Values must be convertible to a particular type"""
|
| 67 |
+
|
| 68 |
+
def __set__(self, instance, value):
|
| 69 |
+
if ((self.allow_none and value is not None)
|
| 70 |
+
or not self.allow_none):
|
| 71 |
+
value = _convert(self.expected_type, value)
|
| 72 |
+
super().__set__(instance, value)
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
class Max(Convertible):
|
| 76 |
+
"""Values must be less than a `max` value"""
|
| 77 |
+
|
| 78 |
+
expected_type = float
|
| 79 |
+
allow_none = False
|
| 80 |
+
|
| 81 |
+
def __init__(self, **kw):
|
| 82 |
+
if 'max' not in kw and not hasattr(self, 'max'):
|
| 83 |
+
raise TypeError('missing max value')
|
| 84 |
+
super().__init__(**kw)
|
| 85 |
+
|
| 86 |
+
def __set__(self, instance, value):
|
| 87 |
+
if ((self.allow_none and value is not None)
|
| 88 |
+
or not self.allow_none):
|
| 89 |
+
value = _convert(self.expected_type, value)
|
| 90 |
+
if value > self.max:
|
| 91 |
+
raise ValueError('Max value is {0}'.format(self.max))
|
| 92 |
+
super().__set__(instance, value)
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
class Min(Convertible):
|
| 96 |
+
"""Values must be greater than a `min` value"""
|
| 97 |
+
|
| 98 |
+
expected_type = float
|
| 99 |
+
allow_none = False
|
| 100 |
+
|
| 101 |
+
def __init__(self, **kw):
|
| 102 |
+
if 'min' not in kw and not hasattr(self, 'min'):
|
| 103 |
+
raise TypeError('missing min value')
|
| 104 |
+
super().__init__(**kw)
|
| 105 |
+
|
| 106 |
+
def __set__(self, instance, value):
|
| 107 |
+
if ((self.allow_none and value is not None)
|
| 108 |
+
or not self.allow_none):
|
| 109 |
+
value = _convert(self.expected_type, value)
|
| 110 |
+
if value < self.min:
|
| 111 |
+
raise ValueError('Min value is {0}'.format(self.min))
|
| 112 |
+
super().__set__(instance, value)
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
class MinMax(Min, Max):
|
| 116 |
+
"""Values must be greater than `min` value and less than a `max` one"""
|
| 117 |
+
pass
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
class Set(Descriptor):
|
| 121 |
+
"""Value can only be from a set of know values"""
|
| 122 |
+
|
| 123 |
+
def __init__(self, name=None, **kw):
|
| 124 |
+
if not 'values' in kw:
|
| 125 |
+
raise TypeError("missing set of values")
|
| 126 |
+
kw['values'] = set(kw['values'])
|
| 127 |
+
super().__init__(name, **kw)
|
| 128 |
+
self.__doc__ = "Value must be one of {0}".format(self.values)
|
| 129 |
+
|
| 130 |
+
def __set__(self, instance, value):
|
| 131 |
+
if value not in self.values:
|
| 132 |
+
raise ValueError(self.__doc__)
|
| 133 |
+
super().__set__(instance, value)
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
class NoneSet(Set):
|
| 137 |
+
|
| 138 |
+
"""'none' will be treated as None"""
|
| 139 |
+
|
| 140 |
+
def __init__(self, name=None, **kw):
|
| 141 |
+
super().__init__(name, **kw)
|
| 142 |
+
self.values.add(None)
|
| 143 |
+
|
| 144 |
+
def __set__(self, instance, value):
|
| 145 |
+
if value == 'none':
|
| 146 |
+
value = None
|
| 147 |
+
super().__set__(instance, value)
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
class Integer(Convertible):
|
| 151 |
+
|
| 152 |
+
expected_type = int
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
class Float(Convertible):
|
| 156 |
+
|
| 157 |
+
expected_type = float
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
class Bool(Convertible):
|
| 161 |
+
|
| 162 |
+
expected_type = bool
|
| 163 |
+
|
| 164 |
+
def __set__(self, instance, value):
|
| 165 |
+
if isinstance(value, str):
|
| 166 |
+
if value in ('false', 'f', '0'):
|
| 167 |
+
value = False
|
| 168 |
+
super().__set__(instance, value)
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
class String(Typed):
|
| 172 |
+
|
| 173 |
+
expected_type = str
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
class Text(String, Convertible):
|
| 177 |
+
|
| 178 |
+
pass
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
class ASCII(Typed):
|
| 182 |
+
|
| 183 |
+
expected_type = bytes
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
class Tuple(Typed):
|
| 187 |
+
|
| 188 |
+
expected_type = tuple
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
class Length(Descriptor):
|
| 192 |
+
|
| 193 |
+
def __init__(self, name=None, **kw):
|
| 194 |
+
if "length" not in kw:
|
| 195 |
+
raise TypeError("value length must be supplied")
|
| 196 |
+
super().__init__(**kw)
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
def __set__(self, instance, value):
|
| 200 |
+
if len(value) != self.length:
|
| 201 |
+
raise ValueError("Value must be length {0}".format(self.length))
|
| 202 |
+
super().__set__(instance, value)
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
class Default(Typed):
|
| 206 |
+
"""
|
| 207 |
+
When called returns an instance of the expected type.
|
| 208 |
+
Additional default values can be passed in to the descriptor
|
| 209 |
+
"""
|
| 210 |
+
|
| 211 |
+
def __init__(self, name=None, **kw):
|
| 212 |
+
if "defaults" not in kw:
|
| 213 |
+
kw['defaults'] = {}
|
| 214 |
+
super().__init__(**kw)
|
| 215 |
+
|
| 216 |
+
def __call__(self):
|
| 217 |
+
return self.expected_type()
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
class Alias(Descriptor):
|
| 221 |
+
"""
|
| 222 |
+
Aliases can be used when either the desired attribute name is not allowed
|
| 223 |
+
or confusing in Python (eg. "type") or a more descriptive name is desired
|
| 224 |
+
(eg. "underline" for "u")
|
| 225 |
+
"""
|
| 226 |
+
|
| 227 |
+
def __init__(self, alias):
|
| 228 |
+
self.alias = alias
|
| 229 |
+
|
| 230 |
+
def __set__(self, instance, value):
|
| 231 |
+
setattr(instance, self.alias, value)
|
| 232 |
+
|
| 233 |
+
def __get__(self, instance, cls):
|
| 234 |
+
return getattr(instance, self.alias)
|
| 235 |
+
|
| 236 |
+
|
| 237 |
+
class MatchPattern(Descriptor):
|
| 238 |
+
"""Values must match a regex pattern """
|
| 239 |
+
allow_none = False
|
| 240 |
+
|
| 241 |
+
def __init__(self, name=None, **kw):
|
| 242 |
+
if 'pattern' not in kw and not hasattr(self, 'pattern'):
|
| 243 |
+
raise TypeError('missing pattern value')
|
| 244 |
+
|
| 245 |
+
super().__init__(name, **kw)
|
| 246 |
+
self.test_pattern = re.compile(self.pattern, re.VERBOSE)
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
def __set__(self, instance, value):
|
| 250 |
+
|
| 251 |
+
if value is None and not self.allow_none:
|
| 252 |
+
raise ValueError("Value must not be none")
|
| 253 |
+
|
| 254 |
+
if ((self.allow_none and value is not None)
|
| 255 |
+
or not self.allow_none):
|
| 256 |
+
if not self.test_pattern.match(value):
|
| 257 |
+
raise ValueError('Value does not match pattern {0}'.format(self.pattern))
|
| 258 |
+
|
| 259 |
+
super().__set__(instance, value)
|
| 260 |
+
|
| 261 |
+
|
| 262 |
+
class DateTime(Typed):
|
| 263 |
+
|
| 264 |
+
expected_type = datetime.datetime
|
| 265 |
+
|
| 266 |
+
def __set__(self, instance, value):
|
| 267 |
+
if value is not None and isinstance(value, str):
|
| 268 |
+
try:
|
| 269 |
+
value = from_ISO8601(value)
|
| 270 |
+
except ValueError:
|
| 271 |
+
raise ValueError("Value must be ISO datetime format")
|
| 272 |
+
super().__set__(instance, value)
|
parrot/lib/python3.10/site-packages/openpyxl/descriptors/container.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2010-2024 openpyxl
|
| 2 |
+
|
| 3 |
+
"""
|
| 4 |
+
Utility list for top level containers that contain one type of element
|
| 5 |
+
|
| 6 |
+
Provides the necessary API to read and write XML
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
from openpyxl.xml.functions import Element
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class ElementList(list):
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
@property
|
| 16 |
+
def tagname(self):
|
| 17 |
+
raise NotImplementedError
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
@property
|
| 21 |
+
def expected_type(self):
|
| 22 |
+
raise NotImplementedError
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
@classmethod
|
| 26 |
+
def from_tree(cls, tree):
|
| 27 |
+
l = [cls.expected_type.from_tree(el) for el in tree]
|
| 28 |
+
return cls(l)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def to_tree(self):
|
| 32 |
+
container = Element(self.tagname)
|
| 33 |
+
for el in self:
|
| 34 |
+
container.append(el.to_tree())
|
| 35 |
+
return container
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def append(self, value):
|
| 39 |
+
if not isinstance(value, self.expected_type):
|
| 40 |
+
raise TypeError(f"Value must of type {self.expected_type} {type(value)} provided")
|
| 41 |
+
super().append(value)
|
parrot/lib/python3.10/site-packages/openpyxl/descriptors/sequence.py
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2010-2024 openpyxl
|
| 2 |
+
|
| 3 |
+
from openpyxl.compat import safe_string
|
| 4 |
+
from openpyxl.xml.functions import Element
|
| 5 |
+
from openpyxl.utils.indexed_list import IndexedList
|
| 6 |
+
|
| 7 |
+
from .base import Descriptor, Alias, _convert
|
| 8 |
+
from .namespace import namespaced
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class Sequence(Descriptor):
|
| 12 |
+
"""
|
| 13 |
+
A sequence (list or tuple) that may only contain objects of the declared
|
| 14 |
+
type
|
| 15 |
+
"""
|
| 16 |
+
|
| 17 |
+
expected_type = type(None)
|
| 18 |
+
seq_types = (list, tuple)
|
| 19 |
+
idx_base = 0
|
| 20 |
+
unique = False
|
| 21 |
+
container = list
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def __set__(self, instance, seq):
|
| 25 |
+
if not isinstance(seq, self.seq_types):
|
| 26 |
+
raise TypeError("Value must be a sequence")
|
| 27 |
+
seq = self.container(_convert(self.expected_type, value) for value in seq)
|
| 28 |
+
if self.unique:
|
| 29 |
+
seq = IndexedList(seq)
|
| 30 |
+
|
| 31 |
+
super().__set__(instance, seq)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def to_tree(self, tagname, obj, namespace=None):
|
| 35 |
+
"""
|
| 36 |
+
Convert the sequence represented by the descriptor to an XML element
|
| 37 |
+
"""
|
| 38 |
+
for idx, v in enumerate(obj, self.idx_base):
|
| 39 |
+
if hasattr(v, "to_tree"):
|
| 40 |
+
el = v.to_tree(tagname, idx)
|
| 41 |
+
else:
|
| 42 |
+
tagname = namespaced(obj, tagname, namespace)
|
| 43 |
+
el = Element(tagname)
|
| 44 |
+
el.text = safe_string(v)
|
| 45 |
+
yield el
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
class UniqueSequence(Sequence):
|
| 49 |
+
"""
|
| 50 |
+
Use a set to keep values unique
|
| 51 |
+
"""
|
| 52 |
+
seq_types = (list, tuple, set)
|
| 53 |
+
container = set
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
class ValueSequence(Sequence):
|
| 57 |
+
"""
|
| 58 |
+
A sequence of primitive types that are stored as a single attribute.
|
| 59 |
+
"val" is the default attribute
|
| 60 |
+
"""
|
| 61 |
+
|
| 62 |
+
attribute = "val"
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def to_tree(self, tagname, obj, namespace=None):
|
| 66 |
+
tagname = namespaced(self, tagname, namespace)
|
| 67 |
+
for v in obj:
|
| 68 |
+
yield Element(tagname, {self.attribute:safe_string(v)})
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def from_tree(self, node):
|
| 72 |
+
|
| 73 |
+
return node.get(self.attribute)
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
class NestedSequence(Sequence):
|
| 77 |
+
"""
|
| 78 |
+
Wrap a sequence in an containing object
|
| 79 |
+
"""
|
| 80 |
+
|
| 81 |
+
count = False
|
| 82 |
+
|
| 83 |
+
def to_tree(self, tagname, obj, namespace=None):
|
| 84 |
+
tagname = namespaced(self, tagname, namespace)
|
| 85 |
+
container = Element(tagname)
|
| 86 |
+
if self.count:
|
| 87 |
+
container.set('count', str(len(obj)))
|
| 88 |
+
for v in obj:
|
| 89 |
+
container.append(v.to_tree())
|
| 90 |
+
return container
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def from_tree(self, node):
|
| 94 |
+
return [self.expected_type.from_tree(el) for el in node]
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
class MultiSequence(Sequence):
|
| 98 |
+
"""
|
| 99 |
+
Sequences can contain objects with different tags
|
| 100 |
+
"""
|
| 101 |
+
|
| 102 |
+
def __set__(self, instance, seq):
|
| 103 |
+
if not isinstance(seq, (tuple, list)):
|
| 104 |
+
raise ValueError("Value must be a sequence")
|
| 105 |
+
seq = list(seq)
|
| 106 |
+
Descriptor.__set__(self, instance, seq)
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
def to_tree(self, tagname, obj, namespace=None):
|
| 110 |
+
"""
|
| 111 |
+
Convert the sequence represented by the descriptor to an XML element
|
| 112 |
+
"""
|
| 113 |
+
for v in obj:
|
| 114 |
+
el = v.to_tree(namespace=namespace)
|
| 115 |
+
yield el
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
class MultiSequencePart(Alias):
|
| 119 |
+
"""
|
| 120 |
+
Allow a multisequence to be built up from parts
|
| 121 |
+
|
| 122 |
+
Excluded from the instance __elements__ or __attrs__ as is effectively an Alias
|
| 123 |
+
"""
|
| 124 |
+
|
| 125 |
+
def __init__(self, expected_type, store):
|
| 126 |
+
self.expected_type = expected_type
|
| 127 |
+
self.store = store
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
def __set__(self, instance, value):
|
| 131 |
+
value = _convert(self.expected_type, value)
|
| 132 |
+
instance.__dict__[self.store].append(value)
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def __get__(self, instance, cls):
|
| 136 |
+
return self
|
parrot/lib/python3.10/site-packages/openpyxl/descriptors/slots.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Metaclass for mixing slots and descriptors
|
| 2 |
+
# From "Programming in Python 3" by Mark Summerfield Ch.8 p. 383
|
| 3 |
+
|
| 4 |
+
class AutoSlotProperties(type):
|
| 5 |
+
|
| 6 |
+
def __new__(mcl, classname, bases, dictionary):
|
| 7 |
+
slots = list(dictionary.get("__slots__", []))
|
| 8 |
+
for getter_name in [key for key in dictionary if key.startswith("get_")]:
|
| 9 |
+
name = getter_name
|
| 10 |
+
slots.append("__" + name)
|
| 11 |
+
getter = dictionary.pop(getter_name)
|
| 12 |
+
setter = dictionary.get(setter_name, None)
|
| 13 |
+
if (setter is not None
|
| 14 |
+
and isinstance(setter, collections.Callable)):
|
| 15 |
+
del dictionary[setter_name]
|
| 16 |
+
dictionary[name] = property(getter. setter)
|
| 17 |
+
dictionary["__slots__"] = tuple(slots)
|
| 18 |
+
return super().__new__(mcl, classname, bases, dictionary)
|
parrot/lib/python3.10/site-packages/openpyxl/drawing/__init__.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2010-2024 openpyxl
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
from .drawing import Drawing
|
parrot/lib/python3.10/site-packages/openpyxl/drawing/drawing.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
# Copyright (c) 2010-2024 openpyxl
|
| 3 |
+
|
| 4 |
+
import math
|
| 5 |
+
|
| 6 |
+
from openpyxl.utils.units import pixels_to_EMU
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class Drawing:
|
| 10 |
+
""" a drawing object - eg container for shapes or charts
|
| 11 |
+
we assume user specifies dimensions in pixels; units are
|
| 12 |
+
converted to EMU in the drawing part
|
| 13 |
+
"""
|
| 14 |
+
|
| 15 |
+
count = 0
|
| 16 |
+
|
| 17 |
+
def __init__(self):
|
| 18 |
+
|
| 19 |
+
self.name = ''
|
| 20 |
+
self.description = ''
|
| 21 |
+
self.coordinates = ((1, 2), (16, 8))
|
| 22 |
+
self.left = 0
|
| 23 |
+
self.top = 0
|
| 24 |
+
self._width = 21 # default in px
|
| 25 |
+
self._height = 192 #default in px
|
| 26 |
+
self.resize_proportional = False
|
| 27 |
+
self.rotation = 0
|
| 28 |
+
self.anchortype = "absolute"
|
| 29 |
+
self.anchorcol = 0 # left cell
|
| 30 |
+
self.anchorrow = 0 # top row
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
@property
|
| 34 |
+
def width(self):
|
| 35 |
+
return self._width
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
@width.setter
|
| 39 |
+
def width(self, w):
|
| 40 |
+
if self.resize_proportional and w:
|
| 41 |
+
ratio = self._height / self._width
|
| 42 |
+
self._height = round(ratio * w)
|
| 43 |
+
self._width = w
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
@property
|
| 47 |
+
def height(self):
|
| 48 |
+
return self._height
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
@height.setter
|
| 52 |
+
def height(self, h):
|
| 53 |
+
if self.resize_proportional and h:
|
| 54 |
+
ratio = self._width / self._height
|
| 55 |
+
self._width = round(ratio * h)
|
| 56 |
+
self._height = h
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def set_dimension(self, w=0, h=0):
|
| 60 |
+
|
| 61 |
+
xratio = w / self._width
|
| 62 |
+
yratio = h / self._height
|
| 63 |
+
|
| 64 |
+
if self.resize_proportional and w and h:
|
| 65 |
+
if (xratio * self._height) < h:
|
| 66 |
+
self._height = math.ceil(xratio * self._height)
|
| 67 |
+
self._width = w
|
| 68 |
+
else:
|
| 69 |
+
self._width = math.ceil(yratio * self._width)
|
| 70 |
+
self._height = h
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
@property
|
| 74 |
+
def anchor(self):
|
| 75 |
+
from .spreadsheet_drawing import (
|
| 76 |
+
OneCellAnchor,
|
| 77 |
+
TwoCellAnchor,
|
| 78 |
+
AbsoluteAnchor)
|
| 79 |
+
if self.anchortype == "absolute":
|
| 80 |
+
anchor = AbsoluteAnchor()
|
| 81 |
+
anchor.pos.x = pixels_to_EMU(self.left)
|
| 82 |
+
anchor.pos.y = pixels_to_EMU(self.top)
|
| 83 |
+
|
| 84 |
+
elif self.anchortype == "oneCell":
|
| 85 |
+
anchor = OneCellAnchor()
|
| 86 |
+
anchor._from.col = self.anchorcol
|
| 87 |
+
anchor._from.row = self.anchorrow
|
| 88 |
+
|
| 89 |
+
anchor.ext.width = pixels_to_EMU(self._width)
|
| 90 |
+
anchor.ext.height = pixels_to_EMU(self._height)
|
| 91 |
+
|
| 92 |
+
return anchor
|
parrot/lib/python3.10/site-packages/openpyxl/drawing/graphic.py
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2010-2024 openpyxl
|
| 2 |
+
|
| 3 |
+
from openpyxl.xml.constants import CHART_NS, DRAWING_NS
|
| 4 |
+
from openpyxl.descriptors.serialisable import Serialisable
|
| 5 |
+
from openpyxl.descriptors import (
|
| 6 |
+
Typed,
|
| 7 |
+
Bool,
|
| 8 |
+
String,
|
| 9 |
+
Alias,
|
| 10 |
+
)
|
| 11 |
+
from openpyxl.descriptors.excel import ExtensionList as OfficeArtExtensionList
|
| 12 |
+
|
| 13 |
+
from .effect import (
|
| 14 |
+
EffectList,
|
| 15 |
+
EffectContainer,
|
| 16 |
+
)
|
| 17 |
+
from .fill import (
|
| 18 |
+
Blip,
|
| 19 |
+
GradientFillProperties,
|
| 20 |
+
BlipFillProperties,
|
| 21 |
+
)
|
| 22 |
+
from .picture import PictureFrame
|
| 23 |
+
from .properties import (
|
| 24 |
+
NonVisualDrawingProps,
|
| 25 |
+
NonVisualGroupShape,
|
| 26 |
+
GroupShapeProperties,
|
| 27 |
+
)
|
| 28 |
+
from .relation import ChartRelation
|
| 29 |
+
from .xdr import XDRTransform2D
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
class GraphicFrameLocking(Serialisable):
|
| 33 |
+
|
| 34 |
+
noGrp = Bool(allow_none=True)
|
| 35 |
+
noDrilldown = Bool(allow_none=True)
|
| 36 |
+
noSelect = Bool(allow_none=True)
|
| 37 |
+
noChangeAspect = Bool(allow_none=True)
|
| 38 |
+
noMove = Bool(allow_none=True)
|
| 39 |
+
noResize = Bool(allow_none=True)
|
| 40 |
+
extLst = Typed(expected_type=OfficeArtExtensionList, allow_none=True)
|
| 41 |
+
|
| 42 |
+
def __init__(self,
|
| 43 |
+
noGrp=None,
|
| 44 |
+
noDrilldown=None,
|
| 45 |
+
noSelect=None,
|
| 46 |
+
noChangeAspect=None,
|
| 47 |
+
noMove=None,
|
| 48 |
+
noResize=None,
|
| 49 |
+
extLst=None,
|
| 50 |
+
):
|
| 51 |
+
self.noGrp = noGrp
|
| 52 |
+
self.noDrilldown = noDrilldown
|
| 53 |
+
self.noSelect = noSelect
|
| 54 |
+
self.noChangeAspect = noChangeAspect
|
| 55 |
+
self.noMove = noMove
|
| 56 |
+
self.noResize = noResize
|
| 57 |
+
self.extLst = extLst
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
class NonVisualGraphicFrameProperties(Serialisable):
|
| 61 |
+
|
| 62 |
+
tagname = "cNvGraphicFramePr"
|
| 63 |
+
|
| 64 |
+
graphicFrameLocks = Typed(expected_type=GraphicFrameLocking, allow_none=True)
|
| 65 |
+
extLst = Typed(expected_type=OfficeArtExtensionList, allow_none=True)
|
| 66 |
+
|
| 67 |
+
def __init__(self,
|
| 68 |
+
graphicFrameLocks=None,
|
| 69 |
+
extLst=None,
|
| 70 |
+
):
|
| 71 |
+
self.graphicFrameLocks = graphicFrameLocks
|
| 72 |
+
self.extLst = extLst
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
class NonVisualGraphicFrame(Serialisable):
|
| 76 |
+
|
| 77 |
+
tagname = "nvGraphicFramePr"
|
| 78 |
+
|
| 79 |
+
cNvPr = Typed(expected_type=NonVisualDrawingProps)
|
| 80 |
+
cNvGraphicFramePr = Typed(expected_type=NonVisualGraphicFrameProperties)
|
| 81 |
+
|
| 82 |
+
__elements__ = ('cNvPr', 'cNvGraphicFramePr')
|
| 83 |
+
|
| 84 |
+
def __init__(self,
|
| 85 |
+
cNvPr=None,
|
| 86 |
+
cNvGraphicFramePr=None,
|
| 87 |
+
):
|
| 88 |
+
if cNvPr is None:
|
| 89 |
+
cNvPr = NonVisualDrawingProps(id=0, name="Chart 0")
|
| 90 |
+
self.cNvPr = cNvPr
|
| 91 |
+
if cNvGraphicFramePr is None:
|
| 92 |
+
cNvGraphicFramePr = NonVisualGraphicFrameProperties()
|
| 93 |
+
self.cNvGraphicFramePr = cNvGraphicFramePr
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
class GraphicData(Serialisable):
|
| 97 |
+
|
| 98 |
+
tagname = "graphicData"
|
| 99 |
+
namespace = DRAWING_NS
|
| 100 |
+
|
| 101 |
+
uri = String()
|
| 102 |
+
chart = Typed(expected_type=ChartRelation, allow_none=True)
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
def __init__(self,
|
| 106 |
+
uri=CHART_NS,
|
| 107 |
+
chart=None,
|
| 108 |
+
):
|
| 109 |
+
self.uri = uri
|
| 110 |
+
self.chart = chart
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
class GraphicObject(Serialisable):
|
| 114 |
+
|
| 115 |
+
tagname = "graphic"
|
| 116 |
+
namespace = DRAWING_NS
|
| 117 |
+
|
| 118 |
+
graphicData = Typed(expected_type=GraphicData)
|
| 119 |
+
|
| 120 |
+
def __init__(self,
|
| 121 |
+
graphicData=None,
|
| 122 |
+
):
|
| 123 |
+
if graphicData is None:
|
| 124 |
+
graphicData = GraphicData()
|
| 125 |
+
self.graphicData = graphicData
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
class GraphicFrame(Serialisable):
|
| 129 |
+
|
| 130 |
+
tagname = "graphicFrame"
|
| 131 |
+
|
| 132 |
+
nvGraphicFramePr = Typed(expected_type=NonVisualGraphicFrame)
|
| 133 |
+
xfrm = Typed(expected_type=XDRTransform2D)
|
| 134 |
+
graphic = Typed(expected_type=GraphicObject)
|
| 135 |
+
macro = String(allow_none=True)
|
| 136 |
+
fPublished = Bool(allow_none=True)
|
| 137 |
+
|
| 138 |
+
__elements__ = ('nvGraphicFramePr', 'xfrm', 'graphic', 'macro', 'fPublished')
|
| 139 |
+
|
| 140 |
+
def __init__(self,
|
| 141 |
+
nvGraphicFramePr=None,
|
| 142 |
+
xfrm=None,
|
| 143 |
+
graphic=None,
|
| 144 |
+
macro=None,
|
| 145 |
+
fPublished=None,
|
| 146 |
+
):
|
| 147 |
+
if nvGraphicFramePr is None:
|
| 148 |
+
nvGraphicFramePr = NonVisualGraphicFrame()
|
| 149 |
+
self.nvGraphicFramePr = nvGraphicFramePr
|
| 150 |
+
if xfrm is None:
|
| 151 |
+
xfrm = XDRTransform2D()
|
| 152 |
+
self.xfrm = xfrm
|
| 153 |
+
if graphic is None:
|
| 154 |
+
graphic = GraphicObject()
|
| 155 |
+
self.graphic = graphic
|
| 156 |
+
self.macro = macro
|
| 157 |
+
self.fPublished = fPublished
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
class GroupShape(Serialisable):
|
| 161 |
+
|
| 162 |
+
nvGrpSpPr = Typed(expected_type=NonVisualGroupShape)
|
| 163 |
+
nonVisualProperties = Alias("nvGrpSpPr")
|
| 164 |
+
grpSpPr = Typed(expected_type=GroupShapeProperties)
|
| 165 |
+
visualProperties = Alias("grpSpPr")
|
| 166 |
+
pic = Typed(expected_type=PictureFrame, allow_none=True)
|
| 167 |
+
|
| 168 |
+
__elements__ = ["nvGrpSpPr", "grpSpPr", "pic"]
|
| 169 |
+
|
| 170 |
+
def __init__(self,
|
| 171 |
+
nvGrpSpPr=None,
|
| 172 |
+
grpSpPr=None,
|
| 173 |
+
pic=None,
|
| 174 |
+
):
|
| 175 |
+
self.nvGrpSpPr = nvGrpSpPr
|
| 176 |
+
self.grpSpPr = grpSpPr
|
| 177 |
+
self.pic = pic
|
parrot/lib/python3.10/site-packages/openpyxl/drawing/image.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2010-2024 openpyxl
|
| 2 |
+
|
| 3 |
+
from io import BytesIO
|
| 4 |
+
|
| 5 |
+
try:
|
| 6 |
+
from PIL import Image as PILImage
|
| 7 |
+
except ImportError:
|
| 8 |
+
PILImage = False
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def _import_image(img):
|
| 12 |
+
if not PILImage:
|
| 13 |
+
raise ImportError('You must install Pillow to fetch image objects')
|
| 14 |
+
|
| 15 |
+
if not isinstance(img, PILImage.Image):
|
| 16 |
+
img = PILImage.open(img)
|
| 17 |
+
|
| 18 |
+
return img
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class Image:
|
| 22 |
+
"""Image in a spreadsheet"""
|
| 23 |
+
|
| 24 |
+
_id = 1
|
| 25 |
+
_path = "/xl/media/image{0}.{1}"
|
| 26 |
+
anchor = "A1"
|
| 27 |
+
|
| 28 |
+
def __init__(self, img):
|
| 29 |
+
|
| 30 |
+
self.ref = img
|
| 31 |
+
mark_to_close = isinstance(img, str)
|
| 32 |
+
image = _import_image(img)
|
| 33 |
+
self.width, self.height = image.size
|
| 34 |
+
|
| 35 |
+
try:
|
| 36 |
+
self.format = image.format.lower()
|
| 37 |
+
except AttributeError:
|
| 38 |
+
self.format = "png"
|
| 39 |
+
if mark_to_close:
|
| 40 |
+
# PIL instances created for metadata should be closed.
|
| 41 |
+
image.close()
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def _data(self):
|
| 45 |
+
"""
|
| 46 |
+
Return image data, convert to supported types if necessary
|
| 47 |
+
"""
|
| 48 |
+
img = _import_image(self.ref)
|
| 49 |
+
# don't convert these file formats
|
| 50 |
+
if self.format in ['gif', 'jpeg', 'png']:
|
| 51 |
+
img.fp.seek(0)
|
| 52 |
+
fp = img.fp
|
| 53 |
+
else:
|
| 54 |
+
fp = BytesIO()
|
| 55 |
+
img.save(fp, format="png")
|
| 56 |
+
fp.seek(0)
|
| 57 |
+
|
| 58 |
+
data = fp.read()
|
| 59 |
+
fp.close()
|
| 60 |
+
return data
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
@property
|
| 64 |
+
def path(self):
|
| 65 |
+
return self._path.format(self._id, self.format)
|
parrot/lib/python3.10/site-packages/openpyxl/pivot/__pycache__/record.cpython-310.pyc
ADDED
|
Binary file (3.12 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/openpyxl/reader/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2010-2024 openpyxl
|
parrot/lib/python3.10/site-packages/openpyxl/reader/__pycache__/drawings.cpython-310.pyc
ADDED
|
Binary file (2.01 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/openpyxl/reader/excel.py
ADDED
|
@@ -0,0 +1,349 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2010-2024 openpyxl
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
"""Read an xlsx file into Python"""
|
| 5 |
+
|
| 6 |
+
# Python stdlib imports
|
| 7 |
+
from zipfile import ZipFile, ZIP_DEFLATED
|
| 8 |
+
from io import BytesIO
|
| 9 |
+
import os.path
|
| 10 |
+
import warnings
|
| 11 |
+
|
| 12 |
+
from openpyxl.pivot.table import TableDefinition
|
| 13 |
+
|
| 14 |
+
# Allow blanket setting of KEEP_VBA for testing
|
| 15 |
+
try:
|
| 16 |
+
from ..tests import KEEP_VBA
|
| 17 |
+
except ImportError:
|
| 18 |
+
KEEP_VBA = False
|
| 19 |
+
|
| 20 |
+
# package imports
|
| 21 |
+
from openpyxl.utils.exceptions import InvalidFileException
|
| 22 |
+
from openpyxl.xml.constants import (
|
| 23 |
+
ARC_CORE,
|
| 24 |
+
ARC_CUSTOM,
|
| 25 |
+
ARC_CONTENT_TYPES,
|
| 26 |
+
ARC_WORKBOOK,
|
| 27 |
+
ARC_THEME,
|
| 28 |
+
COMMENTS_NS,
|
| 29 |
+
SHARED_STRINGS,
|
| 30 |
+
XLTM,
|
| 31 |
+
XLTX,
|
| 32 |
+
XLSM,
|
| 33 |
+
XLSX,
|
| 34 |
+
)
|
| 35 |
+
from openpyxl.cell import MergedCell
|
| 36 |
+
from openpyxl.comments.comment_sheet import CommentSheet
|
| 37 |
+
|
| 38 |
+
from .strings import read_string_table, read_rich_text
|
| 39 |
+
from .workbook import WorkbookParser
|
| 40 |
+
from openpyxl.styles.stylesheet import apply_stylesheet
|
| 41 |
+
|
| 42 |
+
from openpyxl.packaging.core import DocumentProperties
|
| 43 |
+
from openpyxl.packaging.custom import CustomPropertyList
|
| 44 |
+
from openpyxl.packaging.manifest import Manifest, Override
|
| 45 |
+
|
| 46 |
+
from openpyxl.packaging.relationship import (
|
| 47 |
+
RelationshipList,
|
| 48 |
+
get_dependents,
|
| 49 |
+
get_rels_path,
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
from openpyxl.worksheet._read_only import ReadOnlyWorksheet
|
| 53 |
+
from openpyxl.worksheet._reader import WorksheetReader
|
| 54 |
+
from openpyxl.chartsheet import Chartsheet
|
| 55 |
+
from openpyxl.worksheet.table import Table
|
| 56 |
+
from openpyxl.drawing.spreadsheet_drawing import SpreadsheetDrawing
|
| 57 |
+
|
| 58 |
+
from openpyxl.xml.functions import fromstring
|
| 59 |
+
|
| 60 |
+
from .drawings import find_images
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
SUPPORTED_FORMATS = ('.xlsx', '.xlsm', '.xltx', '.xltm')
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def _validate_archive(filename):
|
| 67 |
+
"""
|
| 68 |
+
Does a first check whether filename is a string or a file-like
|
| 69 |
+
object. If it is a string representing a filename, a check is done
|
| 70 |
+
for supported formats by checking the given file-extension. If the
|
| 71 |
+
file-extension is not in SUPPORTED_FORMATS an InvalidFileException
|
| 72 |
+
will raised. Otherwise the filename (resp. file-like object) will
|
| 73 |
+
forwarded to zipfile.ZipFile returning a ZipFile-Instance.
|
| 74 |
+
"""
|
| 75 |
+
is_file_like = hasattr(filename, 'read')
|
| 76 |
+
if not is_file_like:
|
| 77 |
+
file_format = os.path.splitext(filename)[-1].lower()
|
| 78 |
+
if file_format not in SUPPORTED_FORMATS:
|
| 79 |
+
if file_format == '.xls':
|
| 80 |
+
msg = ('openpyxl does not support the old .xls file format, '
|
| 81 |
+
'please use xlrd to read this file, or convert it to '
|
| 82 |
+
'the more recent .xlsx file format.')
|
| 83 |
+
elif file_format == '.xlsb':
|
| 84 |
+
msg = ('openpyxl does not support binary format .xlsb, '
|
| 85 |
+
'please convert this file to .xlsx format if you want '
|
| 86 |
+
'to open it with openpyxl')
|
| 87 |
+
else:
|
| 88 |
+
msg = ('openpyxl does not support %s file format, '
|
| 89 |
+
'please check you can open '
|
| 90 |
+
'it with Excel first. '
|
| 91 |
+
'Supported formats are: %s') % (file_format,
|
| 92 |
+
','.join(SUPPORTED_FORMATS))
|
| 93 |
+
raise InvalidFileException(msg)
|
| 94 |
+
|
| 95 |
+
archive = ZipFile(filename, 'r')
|
| 96 |
+
return archive
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def _find_workbook_part(package):
|
| 100 |
+
workbook_types = [XLTM, XLTX, XLSM, XLSX]
|
| 101 |
+
for ct in workbook_types:
|
| 102 |
+
part = package.find(ct)
|
| 103 |
+
if part:
|
| 104 |
+
return part
|
| 105 |
+
|
| 106 |
+
# some applications reassign the default for application/xml
|
| 107 |
+
defaults = {p.ContentType for p in package.Default}
|
| 108 |
+
workbook_type = defaults & set(workbook_types)
|
| 109 |
+
if workbook_type:
|
| 110 |
+
return Override("/" + ARC_WORKBOOK, workbook_type.pop())
|
| 111 |
+
|
| 112 |
+
raise IOError("File contains no valid workbook part")
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
class ExcelReader:
|
| 116 |
+
|
| 117 |
+
"""
|
| 118 |
+
Read an Excel package and dispatch the contents to the relevant modules
|
| 119 |
+
"""
|
| 120 |
+
|
| 121 |
+
def __init__(self, fn, read_only=False, keep_vba=KEEP_VBA,
|
| 122 |
+
data_only=False, keep_links=True, rich_text=False):
|
| 123 |
+
self.archive = _validate_archive(fn)
|
| 124 |
+
self.valid_files = self.archive.namelist()
|
| 125 |
+
self.read_only = read_only
|
| 126 |
+
self.keep_vba = keep_vba
|
| 127 |
+
self.data_only = data_only
|
| 128 |
+
self.keep_links = keep_links
|
| 129 |
+
self.rich_text = rich_text
|
| 130 |
+
self.shared_strings = []
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
def read_manifest(self):
|
| 134 |
+
src = self.archive.read(ARC_CONTENT_TYPES)
|
| 135 |
+
root = fromstring(src)
|
| 136 |
+
self.package = Manifest.from_tree(root)
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def read_strings(self):
|
| 140 |
+
ct = self.package.find(SHARED_STRINGS)
|
| 141 |
+
reader = read_string_table
|
| 142 |
+
if self.rich_text:
|
| 143 |
+
reader = read_rich_text
|
| 144 |
+
if ct is not None:
|
| 145 |
+
strings_path = ct.PartName[1:]
|
| 146 |
+
with self.archive.open(strings_path,) as src:
|
| 147 |
+
self.shared_strings = reader(src)
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
def read_workbook(self):
|
| 151 |
+
wb_part = _find_workbook_part(self.package)
|
| 152 |
+
self.parser = WorkbookParser(self.archive, wb_part.PartName[1:], keep_links=self.keep_links)
|
| 153 |
+
self.parser.parse()
|
| 154 |
+
wb = self.parser.wb
|
| 155 |
+
wb._sheets = []
|
| 156 |
+
wb._data_only = self.data_only
|
| 157 |
+
wb._read_only = self.read_only
|
| 158 |
+
wb.template = wb_part.ContentType in (XLTX, XLTM)
|
| 159 |
+
|
| 160 |
+
# If are going to preserve the vba then attach a copy of the archive to the
|
| 161 |
+
# workbook so that is available for the save.
|
| 162 |
+
if self.keep_vba:
|
| 163 |
+
wb.vba_archive = ZipFile(BytesIO(), 'a', ZIP_DEFLATED)
|
| 164 |
+
for name in self.valid_files:
|
| 165 |
+
wb.vba_archive.writestr(name, self.archive.read(name))
|
| 166 |
+
|
| 167 |
+
if self.read_only:
|
| 168 |
+
wb._archive = self.archive
|
| 169 |
+
|
| 170 |
+
self.wb = wb
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
def read_properties(self):
|
| 174 |
+
if ARC_CORE in self.valid_files:
|
| 175 |
+
src = fromstring(self.archive.read(ARC_CORE))
|
| 176 |
+
self.wb.properties = DocumentProperties.from_tree(src)
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
def read_custom(self):
|
| 180 |
+
if ARC_CUSTOM in self.valid_files:
|
| 181 |
+
src = fromstring(self.archive.read(ARC_CUSTOM))
|
| 182 |
+
self.wb.custom_doc_props = CustomPropertyList.from_tree(src)
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
def read_theme(self):
|
| 186 |
+
if ARC_THEME in self.valid_files:
|
| 187 |
+
self.wb.loaded_theme = self.archive.read(ARC_THEME)
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
def read_chartsheet(self, sheet, rel):
|
| 191 |
+
sheet_path = rel.target
|
| 192 |
+
rels_path = get_rels_path(sheet_path)
|
| 193 |
+
rels = []
|
| 194 |
+
if rels_path in self.valid_files:
|
| 195 |
+
rels = get_dependents(self.archive, rels_path)
|
| 196 |
+
|
| 197 |
+
with self.archive.open(sheet_path, "r") as src:
|
| 198 |
+
xml = src.read()
|
| 199 |
+
node = fromstring(xml)
|
| 200 |
+
cs = Chartsheet.from_tree(node)
|
| 201 |
+
cs._parent = self.wb
|
| 202 |
+
cs.title = sheet.name
|
| 203 |
+
self.wb._add_sheet(cs)
|
| 204 |
+
|
| 205 |
+
drawings = rels.find(SpreadsheetDrawing._rel_type)
|
| 206 |
+
for rel in drawings:
|
| 207 |
+
charts, images = find_images(self.archive, rel.target)
|
| 208 |
+
for c in charts:
|
| 209 |
+
cs.add_chart(c)
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
def read_worksheets(self):
|
| 213 |
+
comment_warning = """Cell '{0}':{1} is part of a merged range but has a comment which will be removed because merged cells cannot contain any data."""
|
| 214 |
+
for sheet, rel in self.parser.find_sheets():
|
| 215 |
+
if rel.target not in self.valid_files:
|
| 216 |
+
continue
|
| 217 |
+
|
| 218 |
+
if "chartsheet" in rel.Type:
|
| 219 |
+
self.read_chartsheet(sheet, rel)
|
| 220 |
+
continue
|
| 221 |
+
|
| 222 |
+
rels_path = get_rels_path(rel.target)
|
| 223 |
+
rels = RelationshipList()
|
| 224 |
+
if rels_path in self.valid_files:
|
| 225 |
+
rels = get_dependents(self.archive, rels_path)
|
| 226 |
+
|
| 227 |
+
if self.read_only:
|
| 228 |
+
ws = ReadOnlyWorksheet(self.wb, sheet.name, rel.target, self.shared_strings)
|
| 229 |
+
ws.sheet_state = sheet.state
|
| 230 |
+
self.wb._sheets.append(ws)
|
| 231 |
+
continue
|
| 232 |
+
else:
|
| 233 |
+
fh = self.archive.open(rel.target)
|
| 234 |
+
ws = self.wb.create_sheet(sheet.name)
|
| 235 |
+
ws._rels = rels
|
| 236 |
+
ws_parser = WorksheetReader(ws, fh, self.shared_strings, self.data_only, self.rich_text)
|
| 237 |
+
ws_parser.bind_all()
|
| 238 |
+
fh.close()
|
| 239 |
+
|
| 240 |
+
# assign any comments to cells
|
| 241 |
+
for r in rels.find(COMMENTS_NS):
|
| 242 |
+
src = self.archive.read(r.target)
|
| 243 |
+
comment_sheet = CommentSheet.from_tree(fromstring(src))
|
| 244 |
+
for ref, comment in comment_sheet.comments:
|
| 245 |
+
try:
|
| 246 |
+
ws[ref].comment = comment
|
| 247 |
+
except AttributeError:
|
| 248 |
+
c = ws[ref]
|
| 249 |
+
if isinstance(c, MergedCell):
|
| 250 |
+
warnings.warn(comment_warning.format(ws.title, c.coordinate))
|
| 251 |
+
continue
|
| 252 |
+
|
| 253 |
+
# preserve link to VML file if VBA
|
| 254 |
+
if self.wb.vba_archive and ws.legacy_drawing:
|
| 255 |
+
ws.legacy_drawing = rels.get(ws.legacy_drawing).target
|
| 256 |
+
else:
|
| 257 |
+
ws.legacy_drawing = None
|
| 258 |
+
|
| 259 |
+
for t in ws_parser.tables:
|
| 260 |
+
src = self.archive.read(t)
|
| 261 |
+
xml = fromstring(src)
|
| 262 |
+
table = Table.from_tree(xml)
|
| 263 |
+
ws.add_table(table)
|
| 264 |
+
|
| 265 |
+
drawings = rels.find(SpreadsheetDrawing._rel_type)
|
| 266 |
+
for rel in drawings:
|
| 267 |
+
charts, images = find_images(self.archive, rel.target)
|
| 268 |
+
for c in charts:
|
| 269 |
+
ws.add_chart(c, c.anchor)
|
| 270 |
+
for im in images:
|
| 271 |
+
ws.add_image(im, im.anchor)
|
| 272 |
+
|
| 273 |
+
pivot_rel = rels.find(TableDefinition.rel_type)
|
| 274 |
+
pivot_caches = self.parser.pivot_caches
|
| 275 |
+
for r in pivot_rel:
|
| 276 |
+
pivot_path = r.Target
|
| 277 |
+
src = self.archive.read(pivot_path)
|
| 278 |
+
tree = fromstring(src)
|
| 279 |
+
pivot = TableDefinition.from_tree(tree)
|
| 280 |
+
pivot.cache = pivot_caches[pivot.cacheId]
|
| 281 |
+
ws.add_pivot(pivot)
|
| 282 |
+
|
| 283 |
+
ws.sheet_state = sheet.state
|
| 284 |
+
|
| 285 |
+
|
| 286 |
+
def read(self):
|
| 287 |
+
action = "read manifest"
|
| 288 |
+
try:
|
| 289 |
+
self.read_manifest()
|
| 290 |
+
action = "read strings"
|
| 291 |
+
self.read_strings()
|
| 292 |
+
action = "read workbook"
|
| 293 |
+
self.read_workbook()
|
| 294 |
+
action = "read properties"
|
| 295 |
+
self.read_properties()
|
| 296 |
+
action = "read custom properties"
|
| 297 |
+
self.read_custom()
|
| 298 |
+
action = "read theme"
|
| 299 |
+
self.read_theme()
|
| 300 |
+
action = "read stylesheet"
|
| 301 |
+
apply_stylesheet(self.archive, self.wb)
|
| 302 |
+
action = "read worksheets"
|
| 303 |
+
self.read_worksheets()
|
| 304 |
+
action = "assign names"
|
| 305 |
+
self.parser.assign_names()
|
| 306 |
+
if not self.read_only:
|
| 307 |
+
self.archive.close()
|
| 308 |
+
except ValueError as e:
|
| 309 |
+
raise ValueError(
|
| 310 |
+
f"Unable to read workbook: could not {action} from {self.archive.filename}.\n"
|
| 311 |
+
"This is most probably because the workbook source files contain some invalid XML.\n"
|
| 312 |
+
"Please see the exception for more details."
|
| 313 |
+
) from e
|
| 314 |
+
|
| 315 |
+
|
| 316 |
+
def load_workbook(filename, read_only=False, keep_vba=KEEP_VBA,
|
| 317 |
+
data_only=False, keep_links=True, rich_text=False):
|
| 318 |
+
"""Open the given filename and return the workbook
|
| 319 |
+
|
| 320 |
+
:param filename: the path to open or a file-like object
|
| 321 |
+
:type filename: string or a file-like object open in binary mode c.f., :class:`zipfile.ZipFile`
|
| 322 |
+
|
| 323 |
+
:param read_only: optimised for reading, content cannot be edited
|
| 324 |
+
:type read_only: bool
|
| 325 |
+
|
| 326 |
+
:param keep_vba: preserve vba content (this does NOT mean you can use it)
|
| 327 |
+
:type keep_vba: bool
|
| 328 |
+
|
| 329 |
+
:param data_only: controls whether cells with formulae have either the formula (default) or the value stored the last time Excel read the sheet
|
| 330 |
+
:type data_only: bool
|
| 331 |
+
|
| 332 |
+
:param keep_links: whether links to external workbooks should be preserved. The default is True
|
| 333 |
+
:type keep_links: bool
|
| 334 |
+
|
| 335 |
+
:param rich_text: if set to True openpyxl will preserve any rich text formatting in cells. The default is False
|
| 336 |
+
:type rich_text: bool
|
| 337 |
+
|
| 338 |
+
:rtype: :class:`openpyxl.workbook.Workbook`
|
| 339 |
+
|
| 340 |
+
.. note::
|
| 341 |
+
|
| 342 |
+
When using lazy load, all worksheets will be :class:`openpyxl.worksheet.iter_worksheet.IterableWorksheet`
|
| 343 |
+
and the returned workbook will be read-only.
|
| 344 |
+
|
| 345 |
+
"""
|
| 346 |
+
reader = ExcelReader(filename, read_only, keep_vba,
|
| 347 |
+
data_only, keep_links, rich_text)
|
| 348 |
+
reader.read()
|
| 349 |
+
return reader.wb
|
parrot/lib/python3.10/site-packages/openpyxl/reader/strings.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2010-2024 openpyxl
|
| 2 |
+
|
| 3 |
+
from openpyxl.cell.text import Text
|
| 4 |
+
|
| 5 |
+
from openpyxl.xml.functions import iterparse
|
| 6 |
+
from openpyxl.xml.constants import SHEET_MAIN_NS
|
| 7 |
+
from openpyxl.cell.rich_text import CellRichText
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def read_string_table(xml_source):
|
| 11 |
+
"""Read in all shared strings in the table"""
|
| 12 |
+
|
| 13 |
+
strings = []
|
| 14 |
+
STRING_TAG = '{%s}si' % SHEET_MAIN_NS
|
| 15 |
+
|
| 16 |
+
for _, node in iterparse(xml_source):
|
| 17 |
+
if node.tag == STRING_TAG:
|
| 18 |
+
text = Text.from_tree(node).content
|
| 19 |
+
text = text.replace('x005F_', '')
|
| 20 |
+
node.clear()
|
| 21 |
+
|
| 22 |
+
strings.append(text)
|
| 23 |
+
|
| 24 |
+
return strings
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def read_rich_text(xml_source):
|
| 28 |
+
"""Read in all shared strings in the table"""
|
| 29 |
+
|
| 30 |
+
strings = []
|
| 31 |
+
STRING_TAG = '{%s}si' % SHEET_MAIN_NS
|
| 32 |
+
|
| 33 |
+
for _, node in iterparse(xml_source):
|
| 34 |
+
if node.tag == STRING_TAG:
|
| 35 |
+
text = CellRichText.from_tree(node)
|
| 36 |
+
if len(text) == 0:
|
| 37 |
+
text = ''
|
| 38 |
+
elif len(text) == 1 and isinstance(text[0], str):
|
| 39 |
+
text = text[0]
|
| 40 |
+
node.clear()
|
| 41 |
+
|
| 42 |
+
strings.append(text)
|
| 43 |
+
|
| 44 |
+
return strings
|
parrot/lib/python3.10/site-packages/openpyxl/worksheet/__pycache__/_read_only.cpython-310.pyc
ADDED
|
Binary file (5.16 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/openpyxl/worksheet/__pycache__/_reader.cpython-310.pyc
ADDED
|
Binary file (14.1 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/openpyxl/worksheet/__pycache__/datavalidation.cpython-310.pyc
ADDED
|
Binary file (5.83 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/openpyxl/worksheet/__pycache__/dimensions.cpython-310.pyc
ADDED
|
Binary file (8.21 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/openpyxl/worksheet/__pycache__/header_footer.cpython-310.pyc
ADDED
|
Binary file (7.57 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/openpyxl/worksheet/__pycache__/hyperlink.cpython-310.pyc
ADDED
|
Binary file (1.38 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/openpyxl/worksheet/__pycache__/ole.cpython-310.pyc
ADDED
|
Binary file (3.08 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/openpyxl/worksheet/__pycache__/page.cpython-310.pyc
ADDED
|
Binary file (4.38 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/openpyxl/worksheet/__pycache__/properties.cpython-310.pyc
ADDED
|
Binary file (2.4 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/openpyxl/worksheet/__pycache__/smart_tag.cpython-310.pyc
ADDED
|
Binary file (2.02 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/openpyxl/worksheet/picture.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#Autogenerated schema
|
| 2 |
+
from openpyxl.descriptors.serialisable import Serialisable
|
| 3 |
+
|
| 4 |
+
# same as related
|
| 5 |
+
|
| 6 |
+
class SheetBackgroundPicture(Serialisable):
|
| 7 |
+
|
| 8 |
+
tagname = "sheetBackgroundPicture"
|
parrot/lib/python3.10/site-packages/openpyxl/xml/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (1.15 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/openpyxl/xml/__pycache__/functions.cpython-310.pyc
ADDED
|
Binary file (1.87 kB). View file
|
|
|
vlmpy310/lib/python3.10/site-packages/Pympler-1.1.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
vlmpy310/lib/python3.10/site-packages/Pympler-1.1.dist-info/RECORD
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Pympler-1.1.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 2 |
+
Pympler-1.1.dist-info/LICENSE,sha256=yVuuHRzgI17MzTVgt3LsHvuX80innw--CmNPDCzO_iw,11358
|
| 3 |
+
Pympler-1.1.dist-info/METADATA,sha256=9c1VYBYuxdpVVrfKHs7SQh53cxHCEd6UINK7C448c6s,3574
|
| 4 |
+
Pympler-1.1.dist-info/NOTICE,sha256=EF0MDMN2UAwrOqsgfzQMADTY41G74If2LEGzOO_v2ZU,858
|
| 5 |
+
Pympler-1.1.dist-info/RECORD,,
|
| 6 |
+
Pympler-1.1.dist-info/WHEEL,sha256=mguMlWGMX-VHnMpKOjjQidIo1ssRlCFu4a4mBpz1s2M,91
|
| 7 |
+
Pympler-1.1.dist-info/top_level.txt,sha256=-6IMKoWR28iIl8dVdtnd-9o9u-sDXu8CEzFXqFzWElA,8
|
| 8 |
+
pympler/__init__.py,sha256=NHNJCNKpUhz9Pp66avvm-g1TtJ_vX2luf489Gcd_rKk,20
|
| 9 |
+
pympler/__pycache__/__init__.cpython-310.pyc,,
|
| 10 |
+
pympler/__pycache__/asizeof.cpython-310.pyc,,
|
| 11 |
+
pympler/__pycache__/charts.cpython-310.pyc,,
|
| 12 |
+
pympler/__pycache__/classtracker.cpython-310.pyc,,
|
| 13 |
+
pympler/__pycache__/classtracker_stats.cpython-310.pyc,,
|
| 14 |
+
pympler/__pycache__/garbagegraph.cpython-310.pyc,,
|
| 15 |
+
pympler/__pycache__/mprofile.cpython-310.pyc,,
|
| 16 |
+
pympler/__pycache__/muppy.cpython-310.pyc,,
|
| 17 |
+
pympler/__pycache__/panels.cpython-310.pyc,,
|
| 18 |
+
pympler/__pycache__/process.cpython-310.pyc,,
|
| 19 |
+
pympler/__pycache__/refbrowser.cpython-310.pyc,,
|
| 20 |
+
pympler/__pycache__/refgraph.cpython-310.pyc,,
|
| 21 |
+
pympler/__pycache__/summary.cpython-310.pyc,,
|
| 22 |
+
pympler/__pycache__/tracker.cpython-310.pyc,,
|
| 23 |
+
pympler/__pycache__/web.cpython-310.pyc,,
|
| 24 |
+
pympler/asizeof.py,sha256=kEXKMbWF2ZFEbSQMHsqhVJ--5bQ4eYekSIszHSZGSz8,92116
|
| 25 |
+
pympler/charts.py,sha256=xKXoOQMC-UM6xwLXRvjDpYZ4QvEC_VPa20N1ey8crBc,2164
|
| 26 |
+
pympler/classtracker.py,sha256=O4nER_Apt7mTJ_QQ7MaL_dimzj9uJo8gHajOuoku1KQ,22355
|
| 27 |
+
pympler/classtracker_stats.py,sha256=Cd8ZoiFdROjAXXQ4bBAZ2PyAGDduH6XoFKaE7-aUe3Y,28931
|
| 28 |
+
pympler/garbagegraph.py,sha256=9uXHJezkECuf3JqTxnohSF0yirCi97RlxsUFlKSp7R0,2618
|
| 29 |
+
pympler/mprofile.py,sha256=OPhETrh9LeM8v-_tr7ZCh5lawIntzVf5sFye3m_bzY4,3423
|
| 30 |
+
pympler/muppy.py,sha256=vlKpcHbsEqYsoathJslmN4R-OrSPWtViuthW5sdqPPk,9057
|
| 31 |
+
pympler/panels.py,sha256=EmyMbQPEzDnqy_7959fz8UkTUZnWXPs7_xgNMa9h6D0,3686
|
| 32 |
+
pympler/process.py,sha256=XbnGMiwnLsgbxbrqgc9OOSFV6dMlaGJDhrLuprcG4Ws,8341
|
| 33 |
+
pympler/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 34 |
+
pympler/refbrowser.py,sha256=wn2TUTrlJ7eL-W8RLjIXC5Txzdo_T8er9vpF8cwjJJw,15340
|
| 35 |
+
pympler/refgraph.py,sha256=3ChC2wTl0QxUO_rsZbb2UQ5-yR8PdvHPmZIDIXSAO0Q,11961
|
| 36 |
+
pympler/static/jquery.sparkline.min.js,sha256=AswbW7MLXGPPAENjbg1DCI_FafPpng6iSTuhr7U5HN0,44541
|
| 37 |
+
pympler/summary.py,sha256=4tfF3M94E2IpnimqkPujcXR9guobQ71TLX81xNB8FbA,10568
|
| 38 |
+
pympler/templates/asized_referents.tpl,sha256=RC6v-vIGBe5elRpk1iSNfHR-_JhBskn_z3d4CYfvZJU,269
|
| 39 |
+
pympler/templates/footer.tpl,sha256=KwTLunZnAPwo5A_Tn9Y7rQoRejrlkBSJn8CUGjLKwyY,44
|
| 40 |
+
pympler/templates/garbage.tpl,sha256=X3FJgNHFoPOaM__9oV7_acuU7ocMBCt_laMl50c_4S8,725
|
| 41 |
+
pympler/templates/garbage_index.tpl,sha256=nNhTVtCXHPDcxfccqLjpEyPja2Xel9EfKmE_FUx0ODE,1279
|
| 42 |
+
pympler/templates/header.tpl,sha256=9UU2vqHs8-rHEST1j-bHGsF0Gs3Y5gDFl4cIK5tdXw8,913
|
| 43 |
+
pympler/templates/index.tpl,sha256=2G061FsImgTTVL0eX4av6tFQC4NaMnjZ44gbTNDBZ68,572
|
| 44 |
+
pympler/templates/jquery.flot.min.js,sha256=ukSYpSGMcWWK5kM7YlZkzQ_MmYDQZUmYPqB5goFZwWk,52966
|
| 45 |
+
pympler/templates/jquery.flot.stack.min.js,sha256=JkpR_FfPitVZNybQ5jsM_ZWhiAw_1GsDFlBs9RZ7bXY,2465
|
| 46 |
+
pympler/templates/jquery.flot.tooltip.min.js,sha256=T_7W8kYIjSrpyBoYjft9ulx_MDT-MOfjlwYH70fUvGs,7412
|
| 47 |
+
pympler/templates/memory_panel.html,sha256=Ah_UY5g7yZoF4utwzfg19eBZjaPkKnR21nuMhZY7aHI,1549
|
| 48 |
+
pympler/templates/process.tpl,sha256=kivLoj8lxTQ21pxps9PU30FvH80vgfrfJIWfLkvLSWA,2291
|
| 49 |
+
pympler/templates/referents.tpl,sha256=wBO7pFhXSodqWIpHE05J7qPP51XQLfdUZEpWPmnUF08,522
|
| 50 |
+
pympler/templates/stacktrace.tpl,sha256=vU5IXaGRGsHW96X_jvTZ7YwD3Ido4B3hilOcRyiglFU,1206
|
| 51 |
+
pympler/templates/style.css,sha256=FvQaYbztxydzSAgqch2rPaN9dF3Cqe37jPkvXnN3ALM,15427
|
| 52 |
+
pympler/templates/tracker.tpl,sha256=40LAfvSNeKO85OR7mCe02wPoqi4ubvNHIbMH6qdY8AU,4407
|
| 53 |
+
pympler/templates/tracker_class.tpl,sha256=aRW6Y4sT27y_Cubh8x0i6WR1luSuDq6Kv6m_uFqzID4,2581
|
| 54 |
+
pympler/tracker.py,sha256=efl8osXP6W68SVjA9y2-d5upnBddNubXOpWXQWioI6w,10419
|
| 55 |
+
pympler/util/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 56 |
+
pympler/util/__pycache__/__init__.cpython-310.pyc,,
|
| 57 |
+
pympler/util/__pycache__/bottle.cpython-310.pyc,,
|
| 58 |
+
pympler/util/__pycache__/compat.cpython-310.pyc,,
|
| 59 |
+
pympler/util/__pycache__/stringutils.cpython-310.pyc,,
|
| 60 |
+
pympler/util/bottle.py,sha256=iJVdWAfpOi2ksPZlyZtALczPj9aqqcNXrSXSClUCJwc,151993
|
| 61 |
+
pympler/util/compat.py,sha256=ZDuqwrXC-QGBGHV6KMVKy4RvB_v7BrNKwxF_gbao7Zs,469
|
| 62 |
+
pympler/util/stringutils.py,sha256=TcvYZhQPIhYyBlhtFBAgTlUKHaDstVpbu-v1UmY5G_E,2052
|
| 63 |
+
pympler/web.py,sha256=uyq7BqwOi_slg1zWgYRkt0MbNxXdTceHrmuLuYDFGQI,11001
|
vlmpy310/lib/python3.10/site-packages/Pympler-1.1.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: setuptools (70.1.1)
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py3-none-any
|
| 5 |
+
|
vlmpy310/lib/python3.10/site-packages/Pympler-1.1.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pympler
|
vlmpy310/lib/python3.10/site-packages/antlr4/BufferedTokenStream.py
ADDED
|
@@ -0,0 +1,302 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
|
| 3 |
+
# Use of this file is governed by the BSD 3-clause license that
|
| 4 |
+
# can be found in the LICENSE.txt file in the project root.
|
| 5 |
+
|
| 6 |
+
# This implementation of {@link TokenStream} loads tokens from a
|
| 7 |
+
# {@link TokenSource} on-demand, and places the tokens in a buffer to provide
|
| 8 |
+
# access to any previous token by index.
|
| 9 |
+
#
|
| 10 |
+
# <p>
|
| 11 |
+
# This token stream ignores the value of {@link Token#getChannel}. If your
|
| 12 |
+
# parser requires the token stream filter tokens to only those on a particular
|
| 13 |
+
# channel, such as {@link Token#DEFAULT_CHANNEL} or
|
| 14 |
+
# {@link Token#HIDDEN_CHANNEL}, use a filtering token stream such a
|
| 15 |
+
# {@link CommonTokenStream}.</p>
|
| 16 |
+
from io import StringIO
|
| 17 |
+
from antlr4.Token import Token
|
| 18 |
+
from antlr4.error.Errors import IllegalStateException
|
| 19 |
+
|
| 20 |
+
# need forward declaration
|
| 21 |
+
Lexer = None
|
| 22 |
+
|
| 23 |
+
# this is just to keep meaningful parameter types to Parser
|
| 24 |
+
class TokenStream(object):
|
| 25 |
+
|
| 26 |
+
pass
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
class BufferedTokenStream(TokenStream):
|
| 30 |
+
__slots__ = ('tokenSource', 'tokens', 'index', 'fetchedEOF')
|
| 31 |
+
|
| 32 |
+
def __init__(self, tokenSource:Lexer):
|
| 33 |
+
# The {@link TokenSource} from which tokens for this stream are fetched.
|
| 34 |
+
self.tokenSource = tokenSource
|
| 35 |
+
|
| 36 |
+
# A collection of all tokens fetched from the token source. The list is
|
| 37 |
+
# considered a complete view of the input once {@link #fetchedEOF} is set
|
| 38 |
+
# to {@code true}.
|
| 39 |
+
self.tokens = []
|
| 40 |
+
|
| 41 |
+
# The index into {@link #tokens} of the current token (next token to
|
| 42 |
+
# {@link #consume}). {@link #tokens}{@code [}{@link #p}{@code ]} should be
|
| 43 |
+
# {@link #LT LT(1)}.
|
| 44 |
+
#
|
| 45 |
+
# <p>This field is set to -1 when the stream is first constructed or when
|
| 46 |
+
# {@link #setTokenSource} is called, indicating that the first token has
|
| 47 |
+
# not yet been fetched from the token source. For additional information,
|
| 48 |
+
# see the documentation of {@link IntStream} for a description of
|
| 49 |
+
# Initializing Methods.</p>
|
| 50 |
+
self.index = -1
|
| 51 |
+
|
| 52 |
+
# Indicates whether the {@link Token#EOF} token has been fetched from
|
| 53 |
+
# {@link #tokenSource} and added to {@link #tokens}. This field improves
|
| 54 |
+
# performance for the following cases:
|
| 55 |
+
#
|
| 56 |
+
# <ul>
|
| 57 |
+
# <li>{@link #consume}: The lookahead check in {@link #consume} to prevent
|
| 58 |
+
# consuming the EOF symbol is optimized by checking the values of
|
| 59 |
+
# {@link #fetchedEOF} and {@link #p} instead of calling {@link #LA}.</li>
|
| 60 |
+
# <li>{@link #fetch}: The check to prevent adding multiple EOF symbols into
|
| 61 |
+
# {@link #tokens} is trivial with this field.</li>
|
| 62 |
+
# <ul>
|
| 63 |
+
self.fetchedEOF = False
|
| 64 |
+
|
| 65 |
+
def mark(self):
|
| 66 |
+
return 0
|
| 67 |
+
|
| 68 |
+
def release(self, marker:int):
|
| 69 |
+
# no resources to release
|
| 70 |
+
pass
|
| 71 |
+
|
| 72 |
+
def reset(self):
|
| 73 |
+
self.seek(0)
|
| 74 |
+
|
| 75 |
+
def seek(self, index:int):
|
| 76 |
+
self.lazyInit()
|
| 77 |
+
self.index = self.adjustSeekIndex(index)
|
| 78 |
+
|
| 79 |
+
def get(self, index:int):
|
| 80 |
+
self.lazyInit()
|
| 81 |
+
return self.tokens[index]
|
| 82 |
+
|
| 83 |
+
def consume(self):
|
| 84 |
+
skipEofCheck = False
|
| 85 |
+
if self.index >= 0:
|
| 86 |
+
if self.fetchedEOF:
|
| 87 |
+
# the last token in tokens is EOF. skip check if p indexes any
|
| 88 |
+
# fetched token except the last.
|
| 89 |
+
skipEofCheck = self.index < len(self.tokens) - 1
|
| 90 |
+
else:
|
| 91 |
+
# no EOF token in tokens. skip check if p indexes a fetched token.
|
| 92 |
+
skipEofCheck = self.index < len(self.tokens)
|
| 93 |
+
else:
|
| 94 |
+
# not yet initialized
|
| 95 |
+
skipEofCheck = False
|
| 96 |
+
|
| 97 |
+
if not skipEofCheck and self.LA(1) == Token.EOF:
|
| 98 |
+
raise IllegalStateException("cannot consume EOF")
|
| 99 |
+
|
| 100 |
+
if self.sync(self.index + 1):
|
| 101 |
+
self.index = self.adjustSeekIndex(self.index + 1)
|
| 102 |
+
|
| 103 |
+
# Make sure index {@code i} in tokens has a token.
|
| 104 |
+
#
|
| 105 |
+
# @return {@code true} if a token is located at index {@code i}, otherwise
|
| 106 |
+
# {@code false}.
|
| 107 |
+
# @see #get(int i)
|
| 108 |
+
#/
|
| 109 |
+
def sync(self, i:int):
|
| 110 |
+
n = i - len(self.tokens) + 1 # how many more elements we need?
|
| 111 |
+
if n > 0 :
|
| 112 |
+
fetched = self.fetch(n)
|
| 113 |
+
return fetched >= n
|
| 114 |
+
return True
|
| 115 |
+
|
| 116 |
+
# Add {@code n} elements to buffer.
|
| 117 |
+
#
|
| 118 |
+
# @return The actual number of elements added to the buffer.
|
| 119 |
+
#/
|
| 120 |
+
def fetch(self, n:int):
|
| 121 |
+
if self.fetchedEOF:
|
| 122 |
+
return 0
|
| 123 |
+
for i in range(0, n):
|
| 124 |
+
t = self.tokenSource.nextToken()
|
| 125 |
+
t.tokenIndex = len(self.tokens)
|
| 126 |
+
self.tokens.append(t)
|
| 127 |
+
if t.type==Token.EOF:
|
| 128 |
+
self.fetchedEOF = True
|
| 129 |
+
return i + 1
|
| 130 |
+
return n
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
# Get all tokens from start..stop inclusively#/
|
| 134 |
+
def getTokens(self, start:int, stop:int, types:set=None):
|
| 135 |
+
if start<0 or stop<0:
|
| 136 |
+
return None
|
| 137 |
+
self.lazyInit()
|
| 138 |
+
subset = []
|
| 139 |
+
if stop >= len(self.tokens):
|
| 140 |
+
stop = len(self.tokens)-1
|
| 141 |
+
for i in range(start, stop):
|
| 142 |
+
t = self.tokens[i]
|
| 143 |
+
if t.type==Token.EOF:
|
| 144 |
+
break
|
| 145 |
+
if types is None or t.type in types:
|
| 146 |
+
subset.append(t)
|
| 147 |
+
return subset
|
| 148 |
+
|
| 149 |
+
def LA(self, i:int):
|
| 150 |
+
return self.LT(i).type
|
| 151 |
+
|
| 152 |
+
def LB(self, k:int):
|
| 153 |
+
if (self.index-k) < 0:
|
| 154 |
+
return None
|
| 155 |
+
return self.tokens[self.index-k]
|
| 156 |
+
|
| 157 |
+
def LT(self, k:int):
|
| 158 |
+
self.lazyInit()
|
| 159 |
+
if k==0:
|
| 160 |
+
return None
|
| 161 |
+
if k < 0:
|
| 162 |
+
return self.LB(-k)
|
| 163 |
+
i = self.index + k - 1
|
| 164 |
+
self.sync(i)
|
| 165 |
+
if i >= len(self.tokens): # return EOF token
|
| 166 |
+
# EOF must be last token
|
| 167 |
+
return self.tokens[len(self.tokens)-1]
|
| 168 |
+
return self.tokens[i]
|
| 169 |
+
|
| 170 |
+
# Allowed derived classes to modify the behavior of operations which change
|
| 171 |
+
# the current stream position by adjusting the target token index of a seek
|
| 172 |
+
# operation. The default implementation simply returns {@code i}. If an
|
| 173 |
+
# exception is thrown in this method, the current stream index should not be
|
| 174 |
+
# changed.
|
| 175 |
+
#
|
| 176 |
+
# <p>For example, {@link CommonTokenStream} overrides this method to ensure that
|
| 177 |
+
# the seek target is always an on-channel token.</p>
|
| 178 |
+
#
|
| 179 |
+
# @param i The target token index.
|
| 180 |
+
# @return The adjusted target token index.
|
| 181 |
+
|
| 182 |
+
def adjustSeekIndex(self, i:int):
|
| 183 |
+
return i
|
| 184 |
+
|
| 185 |
+
def lazyInit(self):
|
| 186 |
+
if self.index == -1:
|
| 187 |
+
self.setup()
|
| 188 |
+
|
| 189 |
+
def setup(self):
|
| 190 |
+
self.sync(0)
|
| 191 |
+
self.index = self.adjustSeekIndex(0)
|
| 192 |
+
|
| 193 |
+
# Reset this token stream by setting its token source.#/
|
| 194 |
+
def setTokenSource(self, tokenSource:Lexer):
|
| 195 |
+
self.tokenSource = tokenSource
|
| 196 |
+
self.tokens = []
|
| 197 |
+
self.index = -1
|
| 198 |
+
self.fetchedEOF = False
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
# Given a starting index, return the index of the next token on channel.
|
| 202 |
+
# Return i if tokens[i] is on channel. Return the index of the EOF token
|
| 203 |
+
# if there are no tokens on channel between i and EOF.
|
| 204 |
+
#/
|
| 205 |
+
def nextTokenOnChannel(self, i:int, channel:int):
|
| 206 |
+
self.sync(i)
|
| 207 |
+
if i>=len(self.tokens):
|
| 208 |
+
return len(self.tokens) - 1
|
| 209 |
+
token = self.tokens[i]
|
| 210 |
+
while token.channel!=channel:
|
| 211 |
+
if token.type==Token.EOF:
|
| 212 |
+
return i
|
| 213 |
+
i += 1
|
| 214 |
+
self.sync(i)
|
| 215 |
+
token = self.tokens[i]
|
| 216 |
+
return i
|
| 217 |
+
|
| 218 |
+
# Given a starting index, return the index of the previous token on channel.
|
| 219 |
+
# Return i if tokens[i] is on channel. Return -1 if there are no tokens
|
| 220 |
+
# on channel between i and 0.
|
| 221 |
+
def previousTokenOnChannel(self, i:int, channel:int):
|
| 222 |
+
while i>=0 and self.tokens[i].channel!=channel:
|
| 223 |
+
i -= 1
|
| 224 |
+
return i
|
| 225 |
+
|
| 226 |
+
# Collect all tokens on specified channel to the right of
|
| 227 |
+
# the current token up until we see a token on DEFAULT_TOKEN_CHANNEL or
|
| 228 |
+
# EOF. If channel is -1, find any non default channel token.
|
| 229 |
+
def getHiddenTokensToRight(self, tokenIndex:int, channel:int=-1):
|
| 230 |
+
self.lazyInit()
|
| 231 |
+
if tokenIndex<0 or tokenIndex>=len(self.tokens):
|
| 232 |
+
raise Exception(str(tokenIndex) + " not in 0.." + str(len(self.tokens)-1))
|
| 233 |
+
from antlr4.Lexer import Lexer
|
| 234 |
+
nextOnChannel = self.nextTokenOnChannel(tokenIndex + 1, Lexer.DEFAULT_TOKEN_CHANNEL)
|
| 235 |
+
from_ = tokenIndex+1
|
| 236 |
+
# if none onchannel to right, nextOnChannel=-1 so set to = last token
|
| 237 |
+
to = (len(self.tokens)-1) if nextOnChannel==-1 else nextOnChannel
|
| 238 |
+
return self.filterForChannel(from_, to, channel)
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
# Collect all tokens on specified channel to the left of
|
| 242 |
+
# the current token up until we see a token on DEFAULT_TOKEN_CHANNEL.
|
| 243 |
+
# If channel is -1, find any non default channel token.
|
| 244 |
+
def getHiddenTokensToLeft(self, tokenIndex:int, channel:int=-1):
|
| 245 |
+
self.lazyInit()
|
| 246 |
+
if tokenIndex<0 or tokenIndex>=len(self.tokens):
|
| 247 |
+
raise Exception(str(tokenIndex) + " not in 0.." + str(len(self.tokens)-1))
|
| 248 |
+
from antlr4.Lexer import Lexer
|
| 249 |
+
prevOnChannel = self.previousTokenOnChannel(tokenIndex - 1, Lexer.DEFAULT_TOKEN_CHANNEL)
|
| 250 |
+
if prevOnChannel == tokenIndex - 1:
|
| 251 |
+
return None
|
| 252 |
+
# if none on channel to left, prevOnChannel=-1 then from=0
|
| 253 |
+
from_ = prevOnChannel+1
|
| 254 |
+
to = tokenIndex-1
|
| 255 |
+
return self.filterForChannel(from_, to, channel)
|
| 256 |
+
|
| 257 |
+
|
| 258 |
+
def filterForChannel(self, left:int, right:int, channel:int):
|
| 259 |
+
hidden = []
|
| 260 |
+
for i in range(left, right+1):
|
| 261 |
+
t = self.tokens[i]
|
| 262 |
+
if channel==-1:
|
| 263 |
+
from antlr4.Lexer import Lexer
|
| 264 |
+
if t.channel!= Lexer.DEFAULT_TOKEN_CHANNEL:
|
| 265 |
+
hidden.append(t)
|
| 266 |
+
elif t.channel==channel:
|
| 267 |
+
hidden.append(t)
|
| 268 |
+
if len(hidden)==0:
|
| 269 |
+
return None
|
| 270 |
+
return hidden
|
| 271 |
+
|
| 272 |
+
def getSourceName(self):
|
| 273 |
+
return self.tokenSource.getSourceName()
|
| 274 |
+
|
| 275 |
+
# Get the text of all tokens in this buffer.#/
|
| 276 |
+
def getText(self, start:int=None, stop:int=None):
|
| 277 |
+
self.lazyInit()
|
| 278 |
+
self.fill()
|
| 279 |
+
if isinstance(start, Token):
|
| 280 |
+
start = start.tokenIndex
|
| 281 |
+
elif start is None:
|
| 282 |
+
start = 0
|
| 283 |
+
if isinstance(stop, Token):
|
| 284 |
+
stop = stop.tokenIndex
|
| 285 |
+
elif stop is None or stop >= len(self.tokens):
|
| 286 |
+
stop = len(self.tokens) - 1
|
| 287 |
+
if start < 0 or stop < 0 or stop < start:
|
| 288 |
+
return ""
|
| 289 |
+
with StringIO() as buf:
|
| 290 |
+
for i in range(start, stop+1):
|
| 291 |
+
t = self.tokens[i]
|
| 292 |
+
if t.type==Token.EOF:
|
| 293 |
+
break
|
| 294 |
+
buf.write(t.text)
|
| 295 |
+
return buf.getvalue()
|
| 296 |
+
|
| 297 |
+
|
| 298 |
+
# Get all tokens from lexer until EOF#/
|
| 299 |
+
def fill(self):
|
| 300 |
+
self.lazyInit()
|
| 301 |
+
while self.fetch(1000)==1000:
|
| 302 |
+
pass
|
vlmpy310/lib/python3.10/site-packages/antlr4/CommonTokenFactory.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
|
| 3 |
+
# Use of this file is governed by the BSD 3-clause license that
|
| 4 |
+
# can be found in the LICENSE.txt file in the project root.
|
| 5 |
+
#
|
| 6 |
+
|
| 7 |
+
#
|
| 8 |
+
# This default implementation of {@link TokenFactory} creates
|
| 9 |
+
# {@link CommonToken} objects.
|
| 10 |
+
#
|
| 11 |
+
from antlr4.Token import CommonToken
|
| 12 |
+
|
| 13 |
+
class TokenFactory(object):
|
| 14 |
+
|
| 15 |
+
pass
|
| 16 |
+
|
| 17 |
+
class CommonTokenFactory(TokenFactory):
|
| 18 |
+
__slots__ = 'copyText'
|
| 19 |
+
|
| 20 |
+
#
|
| 21 |
+
# The default {@link CommonTokenFactory} instance.
|
| 22 |
+
#
|
| 23 |
+
# <p>
|
| 24 |
+
# This token factory does not explicitly copy token text when constructing
|
| 25 |
+
# tokens.</p>
|
| 26 |
+
#
|
| 27 |
+
DEFAULT = None
|
| 28 |
+
|
| 29 |
+
def __init__(self, copyText:bool=False):
|
| 30 |
+
# Indicates whether {@link CommonToken#setText} should be called after
|
| 31 |
+
# constructing tokens to explicitly set the text. This is useful for cases
|
| 32 |
+
# where the input stream might not be able to provide arbitrary substrings
|
| 33 |
+
# of text from the input after the lexer creates a token (e.g. the
|
| 34 |
+
# implementation of {@link CharStream#getText} in
|
| 35 |
+
# {@link UnbufferedCharStream} throws an
|
| 36 |
+
# {@link UnsupportedOperationException}). Explicitly setting the token text
|
| 37 |
+
# allows {@link Token#getText} to be called at any time regardless of the
|
| 38 |
+
# input stream implementation.
|
| 39 |
+
#
|
| 40 |
+
# <p>
|
| 41 |
+
# The default value is {@code false} to avoid the performance and memory
|
| 42 |
+
# overhead of copying text for every token unless explicitly requested.</p>
|
| 43 |
+
#
|
| 44 |
+
self.copyText = copyText
|
| 45 |
+
|
| 46 |
+
def create(self, source, type:int, text:str, channel:int, start:int, stop:int, line:int, column:int):
|
| 47 |
+
t = CommonToken(source, type, channel, start, stop)
|
| 48 |
+
t.line = line
|
| 49 |
+
t.column = column
|
| 50 |
+
if text is not None:
|
| 51 |
+
t.text = text
|
| 52 |
+
elif self.copyText and source[1] is not None:
|
| 53 |
+
t.text = source[1].getText(start,stop)
|
| 54 |
+
return t
|
| 55 |
+
|
| 56 |
+
def createThin(self, type:int, text:str):
|
| 57 |
+
t = CommonToken(type=type)
|
| 58 |
+
t.text = text
|
| 59 |
+
return t
|
| 60 |
+
|
| 61 |
+
CommonTokenFactory.DEFAULT = CommonTokenFactory()
|
vlmpy310/lib/python3.10/site-packages/antlr4/CommonTokenStream.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
|
| 3 |
+
# Use of this file is governed by the BSD 3-clause license that
|
| 4 |
+
# can be found in the LICENSE.txt file in the project root.
|
| 5 |
+
#/
|
| 6 |
+
|
| 7 |
+
#
|
| 8 |
+
# This class extends {@link BufferedTokenStream} with functionality to filter
|
| 9 |
+
# token streams to tokens on a particular channel (tokens where
|
| 10 |
+
# {@link Token#getChannel} returns a particular value).
|
| 11 |
+
#
|
| 12 |
+
# <p>
|
| 13 |
+
# This token stream provides access to all tokens by index or when calling
|
| 14 |
+
# methods like {@link #getText}. The channel filtering is only used for code
|
| 15 |
+
# accessing tokens via the lookahead methods {@link #LA}, {@link #LT}, and
|
| 16 |
+
# {@link #LB}.</p>
|
| 17 |
+
#
|
| 18 |
+
# <p>
|
| 19 |
+
# By default, tokens are placed on the default channel
|
| 20 |
+
# ({@link Token#DEFAULT_CHANNEL}), but may be reassigned by using the
|
| 21 |
+
# {@code ->channel(HIDDEN)} lexer command, or by using an embedded action to
|
| 22 |
+
# call {@link Lexer#setChannel}.
|
| 23 |
+
# </p>
|
| 24 |
+
#
|
| 25 |
+
# <p>
|
| 26 |
+
# Note: lexer rules which use the {@code ->skip} lexer command or call
|
| 27 |
+
# {@link Lexer#skip} do not produce tokens at all, so input text matched by
|
| 28 |
+
# such a rule will not be available as part of the token stream, regardless of
|
| 29 |
+
# channel.</p>
|
| 30 |
+
#/
|
| 31 |
+
|
| 32 |
+
from antlr4.BufferedTokenStream import BufferedTokenStream
|
| 33 |
+
from antlr4.Lexer import Lexer
|
| 34 |
+
from antlr4.Token import Token
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
class CommonTokenStream(BufferedTokenStream):
|
| 38 |
+
__slots__ = 'channel'
|
| 39 |
+
|
| 40 |
+
def __init__(self, lexer:Lexer, channel:int=Token.DEFAULT_CHANNEL):
|
| 41 |
+
super().__init__(lexer)
|
| 42 |
+
self.channel = channel
|
| 43 |
+
|
| 44 |
+
def adjustSeekIndex(self, i:int):
|
| 45 |
+
return self.nextTokenOnChannel(i, self.channel)
|
| 46 |
+
|
| 47 |
+
def LB(self, k:int):
|
| 48 |
+
if k==0 or (self.index-k)<0:
|
| 49 |
+
return None
|
| 50 |
+
i = self.index
|
| 51 |
+
n = 1
|
| 52 |
+
# find k good tokens looking backwards
|
| 53 |
+
while n <= k:
|
| 54 |
+
# skip off-channel tokens
|
| 55 |
+
i = self.previousTokenOnChannel(i - 1, self.channel)
|
| 56 |
+
n += 1
|
| 57 |
+
if i < 0:
|
| 58 |
+
return None
|
| 59 |
+
return self.tokens[i]
|
| 60 |
+
|
| 61 |
+
def LT(self, k:int):
|
| 62 |
+
self.lazyInit()
|
| 63 |
+
if k == 0:
|
| 64 |
+
return None
|
| 65 |
+
if k < 0:
|
| 66 |
+
return self.LB(-k)
|
| 67 |
+
i = self.index
|
| 68 |
+
n = 1 # we know tokens[pos] is a good one
|
| 69 |
+
# find k good tokens
|
| 70 |
+
while n < k:
|
| 71 |
+
# skip off-channel tokens, but make sure to not look past EOF
|
| 72 |
+
if self.sync(i + 1):
|
| 73 |
+
i = self.nextTokenOnChannel(i + 1, self.channel)
|
| 74 |
+
n += 1
|
| 75 |
+
return self.tokens[i]
|
| 76 |
+
|
| 77 |
+
# Count EOF just once.#/
|
| 78 |
+
def getNumberOfOnChannelTokens(self):
|
| 79 |
+
n = 0
|
| 80 |
+
self.fill()
|
| 81 |
+
for i in range(0, len(self.tokens)):
|
| 82 |
+
t = self.tokens[i]
|
| 83 |
+
if t.channel==self.channel:
|
| 84 |
+
n += 1
|
| 85 |
+
if t.type==Token.EOF:
|
| 86 |
+
break
|
| 87 |
+
return n
|
vlmpy310/lib/python3.10/site-packages/antlr4/FileStream.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
|
| 3 |
+
# Use of this file is governed by the BSD 3-clause license that
|
| 4 |
+
# can be found in the LICENSE.txt file in the project root.
|
| 5 |
+
#
|
| 6 |
+
|
| 7 |
+
#
|
| 8 |
+
# This is an InputStream that is loaded from a file all at once
|
| 9 |
+
# when you construct the object.
|
| 10 |
+
#
|
| 11 |
+
|
| 12 |
+
import codecs
|
| 13 |
+
from antlr4.InputStream import InputStream
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class FileStream(InputStream):
|
| 17 |
+
__slots__ = 'fileName'
|
| 18 |
+
|
| 19 |
+
def __init__(self, fileName:str, encoding:str='ascii', errors:str='strict'):
|
| 20 |
+
super().__init__(self.readDataFrom(fileName, encoding, errors))
|
| 21 |
+
self.fileName = fileName
|
| 22 |
+
|
| 23 |
+
def readDataFrom(self, fileName:str, encoding:str, errors:str='strict'):
|
| 24 |
+
# read binary to avoid line ending conversion
|
| 25 |
+
with open(fileName, 'rb') as file:
|
| 26 |
+
bytes = file.read()
|
| 27 |
+
return codecs.decode(bytes, encoding, errors)
|
vlmpy310/lib/python3.10/site-packages/antlr4/InputStream.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
|
| 3 |
+
# Use of this file is governed by the BSD 3-clause license that
|
| 4 |
+
# can be found in the LICENSE.txt file in the project root.
|
| 5 |
+
#
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
#
|
| 9 |
+
# Vacuum all input from a string and then treat it like a buffer.
|
| 10 |
+
#
|
| 11 |
+
from antlr4.Token import Token
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class InputStream (object):
|
| 15 |
+
__slots__ = ('name', 'strdata', '_index', 'data', '_size')
|
| 16 |
+
|
| 17 |
+
def __init__(self, data: str):
|
| 18 |
+
self.name = "<empty>"
|
| 19 |
+
self.strdata = data
|
| 20 |
+
self._loadString()
|
| 21 |
+
|
| 22 |
+
def _loadString(self):
|
| 23 |
+
self._index = 0
|
| 24 |
+
self.data = [ord(c) for c in self.strdata]
|
| 25 |
+
self._size = len(self.data)
|
| 26 |
+
|
| 27 |
+
@property
|
| 28 |
+
def index(self):
|
| 29 |
+
return self._index
|
| 30 |
+
|
| 31 |
+
@property
|
| 32 |
+
def size(self):
|
| 33 |
+
return self._size
|
| 34 |
+
|
| 35 |
+
# Reset the stream so that it's in the same state it was
|
| 36 |
+
# when the object was created *except* the data array is not
|
| 37 |
+
# touched.
|
| 38 |
+
#
|
| 39 |
+
def reset(self):
|
| 40 |
+
self._index = 0
|
| 41 |
+
|
| 42 |
+
def consume(self):
|
| 43 |
+
if self._index >= self._size:
|
| 44 |
+
assert self.LA(1) == Token.EOF
|
| 45 |
+
raise Exception("cannot consume EOF")
|
| 46 |
+
self._index += 1
|
| 47 |
+
|
| 48 |
+
def LA(self, offset: int):
|
| 49 |
+
if offset==0:
|
| 50 |
+
return 0 # undefined
|
| 51 |
+
if offset<0:
|
| 52 |
+
offset += 1 # e.g., translate LA(-1) to use offset=0
|
| 53 |
+
pos = self._index + offset - 1
|
| 54 |
+
if pos < 0 or pos >= self._size: # invalid
|
| 55 |
+
return Token.EOF
|
| 56 |
+
return self.data[pos]
|
| 57 |
+
|
| 58 |
+
def LT(self, offset: int):
|
| 59 |
+
return self.LA(offset)
|
| 60 |
+
|
| 61 |
+
# mark/release do nothing; we have entire buffer
|
| 62 |
+
def mark(self):
|
| 63 |
+
return -1
|
| 64 |
+
|
| 65 |
+
def release(self, marker: int):
|
| 66 |
+
pass
|
| 67 |
+
|
| 68 |
+
# consume() ahead until p==_index; can't just set p=_index as we must
|
| 69 |
+
# update line and column. If we seek backwards, just set p
|
| 70 |
+
#
|
| 71 |
+
def seek(self, _index: int):
|
| 72 |
+
if _index<=self._index:
|
| 73 |
+
self._index = _index # just jump; don't update stream state (line, ...)
|
| 74 |
+
return
|
| 75 |
+
# seek forward
|
| 76 |
+
self._index = min(_index, self._size)
|
| 77 |
+
|
| 78 |
+
def getText(self, start :int, stop: int):
|
| 79 |
+
if stop >= self._size:
|
| 80 |
+
stop = self._size-1
|
| 81 |
+
if start >= self._size:
|
| 82 |
+
return ""
|
| 83 |
+
else:
|
| 84 |
+
return self.strdata[start:stop+1]
|
| 85 |
+
|
| 86 |
+
def __str__(self):
|
| 87 |
+
return self.strdata
|
vlmpy310/lib/python3.10/site-packages/antlr4/IntervalSet.py
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
|
| 3 |
+
# Use of this file is governed by the BSD 3-clause license that
|
| 4 |
+
# can be found in the LICENSE.txt file in the project root.
|
| 5 |
+
#
|
| 6 |
+
|
| 7 |
+
from io import StringIO
|
| 8 |
+
from antlr4.Token import Token
|
| 9 |
+
|
| 10 |
+
# need forward declarations
|
| 11 |
+
IntervalSet = None
|
| 12 |
+
|
| 13 |
+
class IntervalSet(object):
|
| 14 |
+
__slots__ = ('intervals', 'readonly')
|
| 15 |
+
|
| 16 |
+
def __init__(self):
|
| 17 |
+
self.intervals = None
|
| 18 |
+
self.readonly = False
|
| 19 |
+
|
| 20 |
+
def __iter__(self):
|
| 21 |
+
if self.intervals is not None:
|
| 22 |
+
for i in self.intervals:
|
| 23 |
+
for c in i:
|
| 24 |
+
yield c
|
| 25 |
+
|
| 26 |
+
def __getitem__(self, item):
|
| 27 |
+
i = 0
|
| 28 |
+
for k in self:
|
| 29 |
+
if i==item:
|
| 30 |
+
return k
|
| 31 |
+
else:
|
| 32 |
+
i += 1
|
| 33 |
+
return Token.INVALID_TYPE
|
| 34 |
+
|
| 35 |
+
def addOne(self, v:int):
|
| 36 |
+
self.addRange(range(v, v+1))
|
| 37 |
+
|
| 38 |
+
def addRange(self, v:range):
|
| 39 |
+
if self.intervals is None:
|
| 40 |
+
self.intervals = list()
|
| 41 |
+
self.intervals.append(v)
|
| 42 |
+
else:
|
| 43 |
+
# find insert pos
|
| 44 |
+
k = 0
|
| 45 |
+
for i in self.intervals:
|
| 46 |
+
# distinct range -> insert
|
| 47 |
+
if v.stop<i.start:
|
| 48 |
+
self.intervals.insert(k, v)
|
| 49 |
+
return
|
| 50 |
+
# contiguous range -> adjust
|
| 51 |
+
elif v.stop==i.start:
|
| 52 |
+
self.intervals[k] = range(v.start, i.stop)
|
| 53 |
+
return
|
| 54 |
+
# overlapping range -> adjust and reduce
|
| 55 |
+
elif v.start<=i.stop:
|
| 56 |
+
self.intervals[k] = range(min(i.start,v.start), max(i.stop,v.stop))
|
| 57 |
+
self.reduce(k)
|
| 58 |
+
return
|
| 59 |
+
k += 1
|
| 60 |
+
# greater than any existing
|
| 61 |
+
self.intervals.append(v)
|
| 62 |
+
|
| 63 |
+
def addSet(self, other:IntervalSet):
|
| 64 |
+
if other.intervals is not None:
|
| 65 |
+
for i in other.intervals:
|
| 66 |
+
self.addRange(i)
|
| 67 |
+
return self
|
| 68 |
+
|
| 69 |
+
def reduce(self, k:int):
|
| 70 |
+
# only need to reduce if k is not the last
|
| 71 |
+
if k<len(self.intervals)-1:
|
| 72 |
+
l = self.intervals[k]
|
| 73 |
+
r = self.intervals[k+1]
|
| 74 |
+
# if r contained in l
|
| 75 |
+
if l.stop >= r.stop:
|
| 76 |
+
self.intervals.pop(k+1)
|
| 77 |
+
self.reduce(k)
|
| 78 |
+
elif l.stop >= r.start:
|
| 79 |
+
self.intervals[k] = range(l.start, r.stop)
|
| 80 |
+
self.intervals.pop(k+1)
|
| 81 |
+
|
| 82 |
+
def complement(self, start, stop):
|
| 83 |
+
result = IntervalSet()
|
| 84 |
+
result.addRange(range(start,stop+1))
|
| 85 |
+
for i in self.intervals:
|
| 86 |
+
result.removeRange(i)
|
| 87 |
+
return result
|
| 88 |
+
|
| 89 |
+
def __contains__(self, item):
|
| 90 |
+
if self.intervals is None:
|
| 91 |
+
return False
|
| 92 |
+
else:
|
| 93 |
+
return any(item in i for i in self.intervals)
|
| 94 |
+
|
| 95 |
+
def __len__(self):
|
| 96 |
+
return sum(len(i) for i in self.intervals)
|
| 97 |
+
|
| 98 |
+
def removeRange(self, v):
|
| 99 |
+
if v.start==v.stop-1:
|
| 100 |
+
self.removeOne(v.start)
|
| 101 |
+
elif self.intervals is not None:
|
| 102 |
+
k = 0
|
| 103 |
+
for i in self.intervals:
|
| 104 |
+
# intervals are ordered
|
| 105 |
+
if v.stop<=i.start:
|
| 106 |
+
return
|
| 107 |
+
# check for including range, split it
|
| 108 |
+
elif v.start>i.start and v.stop<i.stop:
|
| 109 |
+
self.intervals[k] = range(i.start, v.start)
|
| 110 |
+
x = range(v.stop, i.stop)
|
| 111 |
+
self.intervals.insert(k, x)
|
| 112 |
+
return
|
| 113 |
+
# check for included range, remove it
|
| 114 |
+
elif v.start<=i.start and v.stop>=i.stop:
|
| 115 |
+
self.intervals.pop(k)
|
| 116 |
+
k -= 1 # need another pass
|
| 117 |
+
# check for lower boundary
|
| 118 |
+
elif v.start<i.stop:
|
| 119 |
+
self.intervals[k] = range(i.start, v.start)
|
| 120 |
+
# check for upper boundary
|
| 121 |
+
elif v.stop<i.stop:
|
| 122 |
+
self.intervals[k] = range(v.stop, i.stop)
|
| 123 |
+
k += 1
|
| 124 |
+
|
| 125 |
+
def removeOne(self, v):
|
| 126 |
+
if self.intervals is not None:
|
| 127 |
+
k = 0
|
| 128 |
+
for i in self.intervals:
|
| 129 |
+
# intervals is ordered
|
| 130 |
+
if v<i.start:
|
| 131 |
+
return
|
| 132 |
+
# check for single value range
|
| 133 |
+
elif v==i.start and v==i.stop-1:
|
| 134 |
+
self.intervals.pop(k)
|
| 135 |
+
return
|
| 136 |
+
# check for lower boundary
|
| 137 |
+
elif v==i.start:
|
| 138 |
+
self.intervals[k] = range(i.start+1, i.stop)
|
| 139 |
+
return
|
| 140 |
+
# check for upper boundary
|
| 141 |
+
elif v==i.stop-1:
|
| 142 |
+
self.intervals[k] = range(i.start, i.stop-1)
|
| 143 |
+
return
|
| 144 |
+
# split existing range
|
| 145 |
+
elif v<i.stop-1:
|
| 146 |
+
x = range(i.start, v)
|
| 147 |
+
self.intervals[k] = range(v + 1, i.stop)
|
| 148 |
+
self.intervals.insert(k, x)
|
| 149 |
+
return
|
| 150 |
+
k += 1
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
def toString(self, literalNames:list, symbolicNames:list):
|
| 154 |
+
if self.intervals is None:
|
| 155 |
+
return "{}"
|
| 156 |
+
with StringIO() as buf:
|
| 157 |
+
if len(self)>1:
|
| 158 |
+
buf.write("{")
|
| 159 |
+
first = True
|
| 160 |
+
for i in self.intervals:
|
| 161 |
+
for j in i:
|
| 162 |
+
if not first:
|
| 163 |
+
buf.write(", ")
|
| 164 |
+
buf.write(self.elementName(literalNames, symbolicNames, j))
|
| 165 |
+
first = False
|
| 166 |
+
if len(self)>1:
|
| 167 |
+
buf.write("}")
|
| 168 |
+
return buf.getvalue()
|
| 169 |
+
|
| 170 |
+
def elementName(self, literalNames:list, symbolicNames:list, a:int):
|
| 171 |
+
if a==Token.EOF:
|
| 172 |
+
return "<EOF>"
|
| 173 |
+
elif a==Token.EPSILON:
|
| 174 |
+
return "<EPSILON>"
|
| 175 |
+
else:
|
| 176 |
+
if a<len(literalNames) and literalNames[a] != "<INVALID>":
|
| 177 |
+
return literalNames[a]
|
| 178 |
+
if a<len(symbolicNames):
|
| 179 |
+
return symbolicNames[a]
|
| 180 |
+
return "<UNKNOWN>"
|