Skip to content

Commit

Permalink
Make swift and obj-c patterns Python3 compatible (dropbox#203)
Browse files Browse the repository at this point in the history
* Make swift and obj-c patterns Python3 compatible
* Remove trailing whitespace
* Bump six version
  • Loading branch information
changusmc committed Dec 3, 2020
1 parent 02f4579 commit 837ee6d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ply>= 3.4
six>= 1.12.0
4 changes: 3 additions & 1 deletion stone/backends/obj_c_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import os
import shutil
import six

from stone.ir import (
is_list_type,
Expand Down Expand Up @@ -911,7 +912,8 @@ def _determine_validator_type(self, data_type, value, has_default):
elif is_string_type(data_type):
if data_type.pattern or data_type.min_length or data_type.max_length:
pattern = data_type.pattern.encode('unicode_escape').replace(
"\"", "\\\"") if data_type.pattern else None
six.ensure_binary("\""),
six.ensure_binary("\\\"")) if data_type.pattern else None
validator = '{}:{}'.format(
fmt_validator(data_type),
fmt_func_args([
Expand Down
4 changes: 3 additions & 1 deletion stone/backends/swift_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import os
import shutil
import six

from contextlib import contextmanager

Expand Down Expand Up @@ -235,7 +236,8 @@ def _determine_validator_type(self, data_type, value):
)
elif is_string_type(data_type):
pat = data_type.pattern if data_type.pattern else None
pat = pat.encode('unicode_escape').replace("\"", "\\\"") if pat else pat
pat = pat.encode('unicode_escape').replace(six.ensure_binary("\""),
six.ensure_binary("\\\"")) if pat else pat
v = "stringValidator({})".format(
self._func_args([
("minLength", data_type.min_length),
Expand Down

0 comments on commit 837ee6d

Please sign in to comment.