mirror of
https://github.com/zulip/zulip.git
synced 2025-11-19 22:19:48 +00:00
python: Modernize legacy Python 2 syntax with pyupgrade.
Generated by `pyupgrade --py3-plus --keep-percent-format` on all our Python code except `zthumbor` and `zulip-ec2-configure-interfaces`, followed by manual indentation fixes. Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
committed by
Tim Abbott
parent
fff2d3958a
commit
c734bbd95d
@@ -106,10 +106,10 @@ def flush_per_request_caches() -> None:
|
||||
per_request_realm_filters_cache = {}
|
||||
|
||||
def get_realm_emoji_cache_key(realm: 'Realm') -> str:
|
||||
return u'realm_emoji:%s' % (realm.id,)
|
||||
return 'realm_emoji:%s' % (realm.id,)
|
||||
|
||||
def get_active_realm_emoji_cache_key(realm: 'Realm') -> str:
|
||||
return u'active_realm_emoji:%s' % (realm.id,)
|
||||
return 'active_realm_emoji:%s' % (realm.id,)
|
||||
|
||||
# This simple call-once caching saves ~500us in auth_enabled_helper,
|
||||
# which is a significant optimization for common_context. Note that
|
||||
@@ -134,13 +134,13 @@ class Realm(models.Model):
|
||||
MAX_GOOGLE_HANGOUTS_DOMAIN_LENGTH = 255 # This is just the maximum domain length by RFC
|
||||
INVITES_STANDARD_REALM_DAILY_MAX = 3000
|
||||
MESSAGE_VISIBILITY_LIMITED = 10000
|
||||
AUTHENTICATION_FLAGS = [u'Google', u'Email', u'GitHub', u'LDAP', u'Dev',
|
||||
u'RemoteUser', u'AzureAD', u'SAML', u'GitLab']
|
||||
AUTHENTICATION_FLAGS = ['Google', 'Email', 'GitHub', 'LDAP', 'Dev',
|
||||
'RemoteUser', 'AzureAD', 'SAML', 'GitLab']
|
||||
SUBDOMAIN_FOR_ROOT_DOMAIN = ''
|
||||
|
||||
# User-visible display name and description used on e.g. the organization homepage
|
||||
name = models.CharField(max_length=MAX_REALM_NAME_LENGTH, null=True) # type: Optional[str]
|
||||
description = models.TextField(default=u"") # type: str
|
||||
description = models.TextField(default="") # type: str
|
||||
|
||||
# A short, identifier-like name for the organization. Used in subdomains;
|
||||
# e.g. on a server at example.com, an org with string_id `foo` is reached
|
||||
@@ -250,10 +250,10 @@ class Realm(models.Model):
|
||||
|
||||
# Defaults for new users
|
||||
default_twenty_four_hour_time = models.BooleanField(default=False) # type: bool
|
||||
default_language = models.CharField(default=u'en', max_length=MAX_LANGUAGE_ID_LENGTH) # type: str
|
||||
default_language = models.CharField(default='en', max_length=MAX_LANGUAGE_ID_LENGTH) # type: str
|
||||
|
||||
DEFAULT_NOTIFICATION_STREAM_NAME = u'general'
|
||||
INITIAL_PRIVATE_STREAM_NAME = u'core team'
|
||||
DEFAULT_NOTIFICATION_STREAM_NAME = 'general'
|
||||
INITIAL_PRIVATE_STREAM_NAME = 'core team'
|
||||
STREAM_EVENTS_NOTIFICATION_TOPIC = _('stream events')
|
||||
notifications_stream = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE) # type: Optional[Stream]
|
||||
signup_notifications_stream = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE) # type: Optional[Stream]
|
||||
@@ -306,15 +306,15 @@ class Realm(models.Model):
|
||||
'id': 0
|
||||
},
|
||||
'jitsi_meet': {
|
||||
'name': u"Jitsi Meet",
|
||||
'name': "Jitsi Meet",
|
||||
'id': 1
|
||||
},
|
||||
'google_hangouts': {
|
||||
'name': u"Google Hangouts",
|
||||
'name': "Google Hangouts",
|
||||
'id': 2
|
||||
},
|
||||
'zoom': {
|
||||
'name': u"Zoom",
|
||||
'name': "Zoom",
|
||||
'id': 3
|
||||
}
|
||||
}
|
||||
@@ -368,8 +368,8 @@ class Realm(models.Model):
|
||||
DIGEST_WEEKDAY_VALUES = [0, 1, 2, 3, 4, 5, 6]
|
||||
|
||||
# Icon is the square mobile icon.
|
||||
ICON_FROM_GRAVATAR = u'G'
|
||||
ICON_UPLOADED = u'U'
|
||||
ICON_FROM_GRAVATAR = 'G'
|
||||
ICON_UPLOADED = 'U'
|
||||
ICON_SOURCES = (
|
||||
(ICON_FROM_GRAVATAR, 'Hosted by Gravatar'),
|
||||
(ICON_UPLOADED, 'Uploaded by administrator'),
|
||||
@@ -379,8 +379,8 @@ class Realm(models.Model):
|
||||
icon_version = models.PositiveSmallIntegerField(default=1) # type: int
|
||||
|
||||
# Logo is the horizontal logo we show in top-left of webapp navbar UI.
|
||||
LOGO_DEFAULT = u'D'
|
||||
LOGO_UPLOADED = u'U'
|
||||
LOGO_DEFAULT = 'D'
|
||||
LOGO_UPLOADED = 'U'
|
||||
LOGO_SOURCES = (
|
||||
(LOGO_DEFAULT, 'Default to Zulip'),
|
||||
(LOGO_UPLOADED, 'Uploaded by administrator'),
|
||||
@@ -679,7 +679,7 @@ class RealmFilter(models.Model):
|
||||
return "<RealmFilter(%s): %s %s>" % (self.realm.string_id, self.pattern, self.url_format_string)
|
||||
|
||||
def get_realm_filters_cache_key(realm_id: int) -> str:
|
||||
return u'%s:all_realm_filters:%s' % (cache.KEY_PREFIX, realm_id,)
|
||||
return '%s:all_realm_filters:%s' % (cache.KEY_PREFIX, realm_id,)
|
||||
|
||||
# We have a per-process cache to avoid doing 1000 remote cache queries during page load
|
||||
per_request_realm_filters_cache = {} # type: Dict[int, List[Tuple[str, str, int]]]
|
||||
@@ -903,7 +903,7 @@ class UserProfile(AbstractBaseUser, PermissionsMixin):
|
||||
realm_name_in_notifications = models.BooleanField(default=False) # type: bool
|
||||
|
||||
# Words that trigger a mention for this user, formatted as a json-serialized list of strings
|
||||
alert_words = models.TextField(default=u'[]') # type: str
|
||||
alert_words = models.TextField(default='[]') # type: str
|
||||
|
||||
# Used for rate-limiting certain automated messages generated by bots
|
||||
last_reminder = models.DateTimeField(default=None, null=True) # type: Optional[datetime.datetime]
|
||||
@@ -913,7 +913,7 @@ class UserProfile(AbstractBaseUser, PermissionsMixin):
|
||||
BOT_OWNER_STREAM_ALERT_WAITPERIOD = 1
|
||||
|
||||
# API rate limits, formatted as a comma-separated list of range:max pairs
|
||||
rate_limits = models.CharField(default=u"", max_length=100) # type: str
|
||||
rate_limits = models.CharField(default="", max_length=100) # type: str
|
||||
|
||||
# Hours to wait before sending another email to a user
|
||||
EMAIL_REMINDER_WAITPERIOD = 24
|
||||
@@ -928,7 +928,7 @@ class UserProfile(AbstractBaseUser, PermissionsMixin):
|
||||
left_side_userlist = models.BooleanField(default=False) # type: bool
|
||||
|
||||
# display settings
|
||||
default_language = models.CharField(default=u'en', max_length=MAX_LANGUAGE_ID_LENGTH) # type: str
|
||||
default_language = models.CharField(default='en', max_length=MAX_LANGUAGE_ID_LENGTH) # type: str
|
||||
dense_mode = models.BooleanField(default=True) # type: bool
|
||||
fluid_layout_width = models.BooleanField(default=False) # type: bool
|
||||
high_contrast_mode = models.BooleanField(default=False) # type: bool
|
||||
@@ -959,7 +959,7 @@ class UserProfile(AbstractBaseUser, PermissionsMixin):
|
||||
# In Django, the convention is to use an empty string instead of NULL/None
|
||||
# for text-based fields. For more information, see
|
||||
# https://docs.djangoproject.com/en/1.10/ref/models/fields/#django.db.models.Field.null.
|
||||
timezone = models.CharField(max_length=40, default=u'') # type: str
|
||||
timezone = models.CharField(max_length=40, default='') # type: str
|
||||
|
||||
# Emojisets
|
||||
GOOGLE_EMOJISET = 'google'
|
||||
@@ -972,8 +972,8 @@ class UserProfile(AbstractBaseUser, PermissionsMixin):
|
||||
(TEXT_EMOJISET, "Plain text"))
|
||||
emojiset = models.CharField(default=GOOGLE_BLOB_EMOJISET, choices=EMOJISET_CHOICES, max_length=20) # type: str
|
||||
|
||||
AVATAR_FROM_GRAVATAR = u'G'
|
||||
AVATAR_FROM_USER = u'U'
|
||||
AVATAR_FROM_GRAVATAR = 'G'
|
||||
AVATAR_FROM_USER = 'U'
|
||||
AVATAR_SOURCES = (
|
||||
(AVATAR_FROM_GRAVATAR, 'Hosted by Gravatar'),
|
||||
(AVATAR_FROM_USER, 'Uploaded by user'),
|
||||
@@ -982,9 +982,9 @@ class UserProfile(AbstractBaseUser, PermissionsMixin):
|
||||
avatar_version = models.PositiveSmallIntegerField(default=1) # type: int
|
||||
avatar_hash = models.CharField(null=True, max_length=64) # type: Optional[str]
|
||||
|
||||
TUTORIAL_WAITING = u'W'
|
||||
TUTORIAL_STARTED = u'S'
|
||||
TUTORIAL_FINISHED = u'F'
|
||||
TUTORIAL_WAITING = 'W'
|
||||
TUTORIAL_STARTED = 'S'
|
||||
TUTORIAL_FINISHED = 'F'
|
||||
TUTORIAL_STATES = ((TUTORIAL_WAITING, "Waiting"),
|
||||
(TUTORIAL_STARTED, "Started"),
|
||||
(TUTORIAL_FINISHED, "Finished"))
|
||||
@@ -994,7 +994,7 @@ class UserProfile(AbstractBaseUser, PermissionsMixin):
|
||||
# [("step 1", true), ("step 2", false)]
|
||||
# where the second element of each tuple is if the step has been
|
||||
# completed.
|
||||
onboarding_steps = models.TextField(default=u'[]') # type: str
|
||||
onboarding_steps = models.TextField(default='[]') # type: str
|
||||
|
||||
objects = UserManager() # type: UserManager
|
||||
|
||||
@@ -1198,7 +1198,7 @@ class UserGroup(models.Model):
|
||||
name = models.CharField(max_length=100)
|
||||
members = models.ManyToManyField(UserProfile, through='UserGroupMembership')
|
||||
realm = models.ForeignKey(Realm, on_delete=CASCADE)
|
||||
description = models.TextField(default=u'') # type: str
|
||||
description = models.TextField(default='') # type: str
|
||||
|
||||
class Meta:
|
||||
unique_together = (('realm', 'name'),)
|
||||
@@ -1341,8 +1341,8 @@ class Stream(models.Model):
|
||||
realm = models.ForeignKey(Realm, db_index=True, on_delete=CASCADE) # type: Realm
|
||||
date_created = models.DateTimeField(default=timezone_now) # type: datetime.datetime
|
||||
deactivated = models.BooleanField(default=False) # type: bool
|
||||
description = models.CharField(max_length=MAX_DESCRIPTION_LENGTH, default=u'') # type: str
|
||||
rendered_description = models.TextField(default=u'') # type: str
|
||||
description = models.CharField(max_length=MAX_DESCRIPTION_LENGTH, default='') # type: str
|
||||
rendered_description = models.TextField(default='') # type: str
|
||||
|
||||
# Foreign key to the Recipient object for STREAM type messages to this stream.
|
||||
recipient = models.ForeignKey(Recipient, null=True, on_delete=models.SET_NULL)
|
||||
@@ -1483,7 +1483,7 @@ def get_client(name: str) -> Client:
|
||||
return get_client_cache[cache_name]
|
||||
|
||||
def get_client_cache_key(name: str) -> str:
|
||||
return u'get_client:%s' % (make_safe_digest(name),)
|
||||
return 'get_client:%s' % (make_safe_digest(name),)
|
||||
|
||||
@cache_with_key(get_client_cache_key, timeout=3600*24*7)
|
||||
def get_client_remote_cache(name: str) -> Client:
|
||||
@@ -1782,9 +1782,9 @@ class AbstractReaction(models.Model):
|
||||
# field encodes which one the user selected.
|
||||
emoji_name = models.TextField() # type: str
|
||||
|
||||
UNICODE_EMOJI = u'unicode_emoji'
|
||||
REALM_EMOJI = u'realm_emoji'
|
||||
ZULIP_EXTRA_EMOJI = u'zulip_extra_emoji'
|
||||
UNICODE_EMOJI = 'unicode_emoji'
|
||||
REALM_EMOJI = 'realm_emoji'
|
||||
ZULIP_EXTRA_EMOJI = 'zulip_extra_emoji'
|
||||
REACTION_TYPES = ((UNICODE_EMOJI, _("Unicode emoji")),
|
||||
(REALM_EMOJI, _("Custom emoji")),
|
||||
(ZULIP_EXTRA_EMOJI, _("Zulip extra emoji")))
|
||||
@@ -2070,7 +2070,7 @@ class Subscription(models.Model):
|
||||
# Whether this user had muted this stream.
|
||||
is_muted = models.NullBooleanField(default=False) # type: Optional[bool]
|
||||
|
||||
DEFAULT_STREAM_COLOR = u"#c2c2c2"
|
||||
DEFAULT_STREAM_COLOR = "#c2c2c2"
|
||||
color = models.CharField(max_length=10, default=DEFAULT_STREAM_COLOR) # type: str
|
||||
pin_to_top = models.BooleanField(default=False) # type: bool
|
||||
|
||||
@@ -2282,7 +2282,7 @@ def get_huddle_hash(id_list: List[int]) -> str:
|
||||
return make_safe_digest(hash_key)
|
||||
|
||||
def huddle_hash_cache_key(huddle_hash: str) -> str:
|
||||
return u"huddle_by_hash:%s" % (huddle_hash,)
|
||||
return "huddle_by_hash:%s" % (huddle_hash,)
|
||||
|
||||
def get_huddle(id_list: List[int]) -> Huddle:
|
||||
huddle_hash = get_huddle_hash(id_list)
|
||||
@@ -2423,7 +2423,7 @@ class DefaultStreamGroup(models.Model):
|
||||
name = models.CharField(max_length=MAX_NAME_LENGTH, db_index=True) # type: str
|
||||
realm = models.ForeignKey(Realm, on_delete=CASCADE) # type: Realm
|
||||
streams = models.ManyToManyField('Stream') # type: Manager
|
||||
description = models.CharField(max_length=1024, default=u'') # type: str
|
||||
description = models.CharField(max_length=1024, default='') # type: str
|
||||
|
||||
class Meta:
|
||||
unique_together = ("realm", "name")
|
||||
@@ -2777,8 +2777,8 @@ class CustomProfileFieldValue(models.Model):
|
||||
# Interfaces for services
|
||||
# They provide additional functionality like parsing message to obtain query url, data to be sent to url,
|
||||
# and parsing the response.
|
||||
GENERIC_INTERFACE = u'GenericService'
|
||||
SLACK_INTERFACE = u'SlackOutgoingWebhookService'
|
||||
GENERIC_INTERFACE = 'GenericService'
|
||||
SLACK_INTERFACE = 'SlackOutgoingWebhookService'
|
||||
|
||||
# A Service corresponds to either an outgoing webhook bot or an embedded bot.
|
||||
# The type of Service is determined by the bot_type field of the referenced
|
||||
@@ -2844,7 +2844,7 @@ class BotConfigData(models.Model):
|
||||
key = models.TextField(db_index=True) # type: str
|
||||
value = models.TextField() # type: str
|
||||
|
||||
class Meta(object):
|
||||
class Meta:
|
||||
unique_together = ("bot_profile", "key")
|
||||
|
||||
class InvalidFakeEmailDomain(Exception):
|
||||
|
||||
Reference in New Issue
Block a user