This is an automated email from the ASF dual-hosted git repository. brondsem pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/allura.git
commit 3a291337b91f353a419e4fc0b7ec06a312fd0442 Author: Dillon Walls <[email protected]> AuthorDate: Tue Jan 24 19:51:21 2023 +0000 [#8495] fix DeprecationWarning '_to_python' --- Allura/allura/lib/helpers.py | 2 +- Allura/allura/lib/validators.py | 52 ++++++++++++------------ Allura/allura/lib/widgets/discuss.py | 2 +- Allura/allura/lib/widgets/form_fields.py | 4 +- Allura/allura/webhooks.py | 2 +- ForgeDiscussion/forgediscussion/widgets/admin.py | 2 +- ForgeImporters/forgeimporters/github/__init__.py | 4 +- ForgeImporters/forgeimporters/trac/__init__.py | 4 +- ForgeSVN/forgesvn/widgets.py | 4 +- 9 files changed, 38 insertions(+), 38 deletions(-) diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py index e0467a56a..cf25ec8d0 100644 --- a/Allura/allura/lib/helpers.py +++ b/Allura/allura/lib/helpers.py @@ -524,7 +524,7 @@ def ago_string(s): class DateTimeConverter(FancyValidator): - def _to_python(self, value, state): + def _convert_to_python(self, value, state): try: return parse(value) except (ValueError, TypeError): diff --git a/Allura/allura/lib/validators.py b/Allura/allura/lib/validators.py index 4d9368e38..0ce0f7c90 100644 --- a/Allura/allura/lib/validators.py +++ b/Allura/allura/lib/validators.py @@ -50,8 +50,8 @@ class URL(fev.URL): class URLIsPrivate(URL): - def _to_python(self, value, state): - value = super(URLIsPrivate, self)._to_python(value, state) + def _convert_to_python(self, value, state): + value = super(URLIsPrivate, self)._convert_to_python(value, state) url_components = urlsplit(value) try: host_ip = socket.gethostbyname(url_components.netloc) @@ -107,7 +107,7 @@ class Ming(fev.FancyValidator): self.cls = cls super().__init__(**kw) - def _to_python(self, value, state): + def _convert_to_python(self, value, state): result = self.cls.query.get(_id=value) if result is None: try: @@ -125,7 +125,7 @@ class Ming(fev.FancyValidator): class UniqueOAuthApplicationName(UnicodeString): - def _to_python(self, value, state): + def _convert_to_python(self, value, state): from allura import model as M app = M.OAuthConsumerToken.query.get(name=value, user_id=c.user._id) if app is not None: @@ -149,7 +149,7 @@ class NullValidator(fev.Validator): class MaxBytesValidator(fev.FancyValidator): max = 255 - def _to_python(self, value, state): + def _convert_to_python(self, value, state): value_bytes = h.really_unicode(value or '').encode('utf-8') if len(value_bytes) > self.max: raise fe.Invalid("Please enter a value less than %s bytes long." % @@ -168,7 +168,7 @@ class MountPointValidator(UnicodeString): self.app_class = app_class self.reserved_mount_points = reserved_mount_points - def _to_python(self, value, state): + def _convert_to_python(self, value, state): mount_point, App = value, self.app_class if not App.relaxed_mount_points: mount_point = mount_point.lower() @@ -196,7 +196,7 @@ class MountPointValidator(UnicodeString): class TaskValidator(fev.FancyValidator): - def _to_python(self, value, state): + def _convert_to_python(self, value, state): try: mod, func = value.rsplit('.', 1) except ValueError: @@ -220,7 +220,7 @@ class TaskValidator(fev.FancyValidator): class UserValidator(fev.FancyValidator): - def _to_python(self, value, state): + def _convert_to_python(self, value, state): from allura import model as M user = M.User.by_username(value) if not user: @@ -230,7 +230,7 @@ class UserValidator(fev.FancyValidator): class AnonymousValidator(fev.FancyValidator): - def _to_python(self, value, state): + def _convert_to_python(self, value, state): from allura.model import User if value: if c.user == User.anonymous(): @@ -241,7 +241,7 @@ class AnonymousValidator(fev.FancyValidator): class PathValidator(fev.FancyValidator): - def _to_python(self, value, state): + def _convert_to_python(self, value, state): from allura import model as M parts = value.strip('/').split('/') @@ -282,7 +282,7 @@ class JsonValidator(fev.FancyValidator): """Validates a string as JSON and returns the original string""" - def _to_python(self, value, state): + def _convert_to_python(self, value, state): try: json.loads(value) except ValueError as e: @@ -297,7 +297,7 @@ class JsonConverter(fev.FancyValidator): Must be an object, not a simple literal """ - def _to_python(self, value, state): + def _convert_to_python(self, value, state): try: obj = json.loads(value) except ValueError as e: @@ -313,7 +313,7 @@ class JsonFile(fev.FieldStorageUploadConverter): """ - def _to_python(self, value, state): + def _convert_to_python(self, value, state): return JsonConverter.to_python(value.value) @@ -330,8 +330,8 @@ class UserMapJsonFile(JsonFile): def __init__(self, as_string=False): self.as_string = as_string - def _to_python(self, value, state): - value = super(self.__class__, self)._to_python(value, state) + def _convert_to_python(self, value, state): + value = super(self.__class__, self)._convert_to_python(value, state) try: for k, v in value.items(): if not(isinstance(k, str) and isinstance(v, str)): @@ -361,7 +361,7 @@ class CreateSiteNotificationSchema(fe.Schema): class DateValidator(fev.FancyValidator): - def _to_python(self, value, state): + def _convert_to_python(self, value, state): value = convertDate(value) if not value: raise fe.Invalid( @@ -372,7 +372,7 @@ class DateValidator(fev.FancyValidator): class TimeValidator(fev.FancyValidator): - def _to_python(self, value, state): + def _convert_to_python(self, value, state): value = convertTime(value) if not value: raise fe.Invalid( @@ -388,7 +388,7 @@ class OneOfValidator(fev.FancyValidator): self.not_empty = not_empty super().__init__() - def _to_python(self, value, state): + def _convert_to_python(self, value, state): if not value.strip(): if self.not_empty: raise fe.Invalid("This field can't be empty.", value, state) @@ -413,7 +413,7 @@ class MapValidator(fev.FancyValidator): self.not_empty = not_empty super().__init__() - def _to_python(self, value, state): + def _convert_to_python(self, value, state): if not value.strip(): if self.not_empty: raise fe.Invalid("This field can't be empty.", value, state) @@ -438,7 +438,7 @@ class YouTubeConverter(fev.FancyValidator): r'(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))' + r'((\w|-){11})(?:\S+)?$') - def _to_python(self, value, state): + def _convert_to_python(self, value, state): match = re.match(YouTubeConverter.REGEX, value) if match: video_id = match.group(1) @@ -477,7 +477,7 @@ def convertTime(timestring): class IconValidator(fev.FancyValidator): regex = '(jpg|jpeg|gif|png|bmp)$' - def _to_python(self, value, state): + def _convert_to_python(self, value, state): p = re.compile(self.regex, flags=re.I) result = p.search(value.filename) @@ -491,7 +491,7 @@ class IconValidator(fev.FancyValidator): FEDIVERSE_REGEX = r'^@[\w-]+@[\w-]+(\.[\w-]+)+$' class LinkedinValidator(fev.FancyValidator): - def _to_python(self, value, state): + def _convert_to_python(self, value, state): if value.startswith('@') and not re.match(FEDIVERSE_REGEX, value): value = f'https://linkedin.com/in/{value.replace("@", "")}/' elif 'linkedin.com' not in value: @@ -500,7 +500,7 @@ class LinkedinValidator(fev.FancyValidator): class TwitterValidator(fev.FancyValidator): - def _to_python(self, value, state): + def _convert_to_python(self, value, state): if value.startswith('@') and not re.match(FEDIVERSE_REGEX, value): value = f'https://twitter.com/{value.replace("@", "")}' elif 'twitter.com' not in value: @@ -509,7 +509,7 @@ class TwitterValidator(fev.FancyValidator): class InstagramValidator(fev.FancyValidator): - def _to_python(self, value, state): + def _convert_to_python(self, value, state): if value.startswith('@') and not re.match(FEDIVERSE_REGEX, value): value = f'https://instagram.com/{value.replace("@", "")}' elif 'instagram.com' not in value: @@ -518,7 +518,7 @@ class InstagramValidator(fev.FancyValidator): class FacebookValidator(fev.FancyValidator): - def _to_python(self, value, state): + def _convert_to_python(self, value, state): if value.startswith('@') and not re.match(FEDIVERSE_REGEX, value): value = f'https://facebook.com/{value.replace("@", "")}' elif 'facebook.com' not in value: @@ -527,7 +527,7 @@ class FacebookValidator(fev.FancyValidator): class FediverseValidator(fev.FancyValidator): - def _to_python(self, value, state): + def _convert_to_python(self, value, state): if value.startswith('http'): url = urlsplit(value) value = f'{url.path.replace("/", "")}@{url.netloc}' diff --git a/Allura/allura/lib/widgets/discuss.py b/Allura/allura/lib/widgets/discuss.py index 1917e0590..41b18fede 100644 --- a/Allura/allura/lib/widgets/discuss.py +++ b/Allura/allura/lib/widgets/discuss.py @@ -33,7 +33,7 @@ class NullValidator(fev.FancyValidator): perform_validation = True accept_iterator = True - def _to_python(self, value, state): + def _convert_to_python(self, value, state): return value def _from_python(self, value, state): diff --git a/Allura/allura/lib/widgets/form_fields.py b/Allura/allura/lib/widgets/form_fields.py index 957630f7c..844a09018 100644 --- a/Allura/allura/lib/widgets/form_fields.py +++ b/Allura/allura/lib/widgets/form_fields.py @@ -46,8 +46,8 @@ class LabelList(v.UnicodeString): kwargs.setdefault('if_empty', []) super().__init__(*args, **kwargs) - def _to_python(self, value, state): - value = super()._to_python(value, state) + def _convert_to_python(self, value, state): + value = super()._convert_to_python(value, state) return value.split(',') def _from_python(self, value, state): diff --git a/Allura/allura/webhooks.py b/Allura/allura/webhooks.py index a56f18e63..4f9e90db4 100644 --- a/Allura/allura/webhooks.py +++ b/Allura/allura/webhooks.py @@ -54,7 +54,7 @@ class WebhookValidator(fev.FancyValidator): self.sender = sender super().__init__(**kw) - def _to_python(self, value, state): + def _convert_to_python(self, value, state): wh = None if isinstance(value, M.Webhook): wh = value diff --git a/ForgeDiscussion/forgediscussion/widgets/admin.py b/ForgeDiscussion/forgediscussion/widgets/admin.py index c1cb62c2c..eba27dcd7 100644 --- a/ForgeDiscussion/forgediscussion/widgets/admin.py +++ b/ForgeDiscussion/forgediscussion/widgets/admin.py @@ -88,7 +88,7 @@ class AddForumShort(AddForum): class UniqueForumShortnameValidator(fev.FancyValidator): - def _to_python(self, value, state): + def _convert_to_python(self, value, state): forums = DM.Forum.query.find( dict(app_config_id=ObjectId(state.full_dict['app_id']))).all() value = h.really_unicode(value.lower() or '') diff --git a/ForgeImporters/forgeimporters/github/__init__.py b/ForgeImporters/forgeimporters/github/__init__.py index 968eb2b89..9fd2cadca 100644 --- a/ForgeImporters/forgeimporters/github/__init__.py +++ b/ForgeImporters/forgeimporters/github/__init__.py @@ -39,7 +39,7 @@ log = logging.getLogger(__name__) class GitHubURLValidator(fev.FancyValidator): regex = r'https?:\/\/github\.com' - def _to_python(self, value, state): + def _convert_to_python(self, value, state): valid_url = urlparse(value.strip()) if not bool(valid_url.scheme): raise fev.Invalid('Invalid URL', value, state) @@ -55,7 +55,7 @@ class GitHubProjectNameValidator(fev.FancyValidator): 'unavailable': 'This is not a valid Github project that can be used for import', } - def _to_python(self, value, state=None): + def _convert_to_python(self, value, state=None): user_name = state.full_dict.get('user_name', '') user_name = state.full_dict.get('gh_user_name', user_name).strip() project_name = value.strip() diff --git a/ForgeImporters/forgeimporters/trac/__init__.py b/ForgeImporters/forgeimporters/trac/__init__.py index c86da5c03..126466651 100644 --- a/ForgeImporters/forgeimporters/trac/__init__.py +++ b/ForgeImporters/forgeimporters/trac/__init__.py @@ -27,8 +27,8 @@ class TracURLValidator(validators.URLIsPrivate): 'unavailable': 'This project is unavailable for import' } - def _to_python(self, value, state=None): - value = super()._to_python(value, state) + def _convert_to_python(self, value, state=None): + value = super()._convert_to_python(value, state) # remove extraneous /wiki/[PageName] from the end of the URL url_parts = value.split('/') try: diff --git a/ForgeSVN/forgesvn/widgets.py b/ForgeSVN/forgesvn/widgets.py index 8f4ad6539..abf2044e6 100644 --- a/ForgeSVN/forgesvn/widgets.py +++ b/ForgeSVN/forgesvn/widgets.py @@ -40,8 +40,8 @@ class ValidateSvnUrl(validators.URLIsPrivate): $ ''', re.I | re.VERBOSE) - def _to_python(self, value, state): - value = super()._to_python(value, state) + def _convert_to_python(self, value, state): + value = super()._convert_to_python(value, state) if 'plugins.svn.wordpress.org' in value: raise fev.Invalid("That SVN repo is to large to import from.", value, state) return value
