1# Lint as: python2, python3 2# Copyright 2017 The Chromium OS Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6"""This module contains stuff for reporting deprecation. 7 8TODO(ayatane): The reason for putting this module here is so client tests can use it. 9""" 10from six.moves import urllib 11import warnings 12 13 14def warn(deprecated_name, stacklevel=3): 15 """Convenience function for making deprecation warnings. 16 17 @param deprecated_name: The name of the deprecated function or module 18 @param stacklevel: See warnings.warn(). 19 """ 20 warnings.warn(APIDeprecationWarning(deprecated_name), 21 stacklevel=stacklevel) 22 23 24class APIDeprecationWarning(UserWarning): 25 """API deprecation warning. 26 27 This is different from DeprecationWarning. DeprecationWarning is 28 for Python deprecations, this class is for our deprecations. 29 """ 30 31 def __init__(self, deprecated_name): 32 """Initialize instance. 33 34 @param deprecated_name: The name of the deprecated function or module 35 """ 36 super(APIDeprecationWarning, self).__init__(deprecated_name) 37 self._deprecated_name = deprecated_name 38 39 def __str__(self): 40 return ('%s is deprecated; please file a fixit bug: %s' 41 % (self._deprecated_name, self._get_fixit_bug_url())) 42 43 def _get_fixit_bug_url(self): 44 """Return the URL for making a fixit bug.""" 45 return ('https://bugs.chromium.org/p/chromium/issues/entry?' 46 + urllib.parse.urlencode({ 47 'summary': 'Deprecated use of %s' % self._deprecated_name, 48 'description': 'Please paste the warning message below\n', 49 'components': 'Infra>Client>ChromeOS', 50 'labels': 'Pri-3,Type-Bug,Hotlist-Fixit', 51 })) 52