Skip to content

Commit 85b2b9f

Browse files
Upgrade cel-python to 0.2.0 (#252)
Ref: https://github.com/cloud-custodian/cel-python/releases/tag/v0.2 Relates to #180.
1 parent 5b8ab98 commit 85b2b9f

File tree

6 files changed

+38
-191
lines changed

6 files changed

+38
-191
lines changed

Pipfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ verify_ssl = true
44
name = "pypi"
55

66
[packages]
7-
cel-python = "==0.1.5"
7+
cel-python = "==0.2.*"
88
protobuf = "==5.*"
99

1010
[dev-packages]

Pipfile.lock

Lines changed: 21 additions & 143 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protovalidate/internal/constraints.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ def make_duration(msg: message.Message) -> celtypes.DurationType:
3636

3737

3838
def make_timestamp(msg: message.Message) -> celtypes.TimestampType:
39-
return make_duration(msg) + celtypes.TimestampType(1970, 1, 1)
39+
return celtypes.TimestampType(1970, 1, 1) + make_duration(msg)
4040

4141

4242
def unwrap(msg: message.Message) -> celtypes.Value:
4343
return _field_to_cel(msg, msg.DESCRIPTOR.fields_by_name["value"])
4444

4545

46-
_MSG_TYPE_URL_TO_CTOR = {
46+
_MSG_TYPE_URL_TO_CTOR: dict[str, typing.Callable[..., celtypes.Value]] = {
4747
"google.protobuf.Duration": make_duration,
4848
"google.protobuf.Timestamp": make_timestamp,
4949
"google.protobuf.StringValue": unwrap,
@@ -89,7 +89,7 @@ def _msg_to_cel(msg: message.Message) -> celtypes.Value:
8989
return MessageType(msg)
9090

9191

92-
_TYPE_TO_CTOR = {
92+
_TYPE_TO_CTOR: dict[str, typing.Callable[..., celtypes.Value]] = {
9393
descriptor.FieldDescriptor.TYPE_MESSAGE: _msg_to_cel,
9494
descriptor.FieldDescriptor.TYPE_GROUP: _msg_to_cel,
9595
descriptor.FieldDescriptor.TYPE_ENUM: celtypes.IntType,

protovalidate/internal/extra_func.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ def is_ip_prefix(val: celtypes.Value, *args) -> celpy.Result:
143143
raise celpy.CELEvalError(msg)
144144
try:
145145
if version is None:
146-
ip_network(val, strict=strict)
146+
ip_network(val, strict=bool(strict))
147147
elif version == 4:
148-
IPv4Network(val, strict=strict)
148+
IPv4Network(val, strict=bool(strict))
149149
elif version == 6:
150-
IPv6Network(val, strict=strict)
150+
IPv6Network(val, strict=bool(strict))
151151
else:
152152
msg = "invalid argument, expected 4 or 6"
153153
raise celpy.CELEvalError(msg)
@@ -164,7 +164,7 @@ def is_email(string: celtypes.Value) -> celpy.Result:
164164

165165

166166
def is_uri(string: celtypes.Value) -> celpy.Result:
167-
url = urlparse.urlparse(string)
167+
url = urlparse.urlparse(str(string))
168168
# urlparse correctly reads the scheme from URNs but parses everything
169169
# after (except the query string) as the path.
170170
if url.scheme == "urn":
@@ -182,7 +182,7 @@ def is_uri(string: celtypes.Value) -> celpy.Result:
182182

183183

184184
def is_uri_ref(string: celtypes.Value) -> celpy.Result:
185-
url = urlparse.urlparse(string)
185+
url = urlparse.urlparse(str(string))
186186
if not all([url.scheme, url.path]) and url.fragment:
187187
return celtypes.BoolType(False)
188188
return celtypes.BoolType(True)
@@ -238,7 +238,9 @@ def unique(val: celtypes.Value) -> celpy.Result:
238238

239239

240240
def make_extra_funcs(locale: str) -> dict[str, celpy.CELFunction]:
241-
string_fmt = string_format.StringFormat(locale)
241+
# TODO(#257): Fix types and add tests for StringFormat.
242+
# For now, ignoring the type.
243+
string_fmt = string_format.StringFormat(locale) # type: ignore
242244
return {
243245
# Missing standard functions
244246
"format": string_fmt.format,

protovalidate/internal/field_path.py

Lines changed: 0 additions & 36 deletions
This file was deleted.

protovalidate/internal/string_format.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
# type: ignore
16+
# TODO(#257): Fully test and fix types in this file.
17+
1518
from decimal import Decimal
1619

1720
import celpy # type: ignore
@@ -44,9 +47,9 @@ def __init__(self, locale: str):
4447

4548
def format(self, fmt: celtypes.Value, args: celtypes.Value) -> celpy.Result:
4649
if not isinstance(fmt, celtypes.StringType):
47-
return celpy.native_to_cel(celpy.new_error("format() requires a string as the first argument"))
50+
return celpy.CELEvalError("format() requires a string as the first argument")
4851
if not isinstance(args, celtypes.ListType):
49-
return celpy.native_to_cel(celpy.new_error("format() requires a list as the second argument"))
52+
return celpy.CELEvalError("format() requires a list as the second argument")
5053
# printf style formatting
5154
i = 0
5255
j = 0

0 commit comments

Comments
 (0)