Add @unique decorator to all enumerations

Currently, there are no enumerations using the enum module which reuse
values/need aliases. Add the @unique decorator to all enum classes as a
safety net for future modifications.
This commit is contained in:
Markus Böhme 2017-03-04 21:22:46 +01:00
parent 5cc92efcb6
commit 8df8486def
14 changed files with 34 additions and 14 deletions

View File

@ -23,7 +23,7 @@
## along with Gajim. If not, see <http://www.gnu.org/licenses/>. ## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
## ##
from enum import IntEnum from enum import IntEnum, unique
from gi.repository import Gtk from gi.repository import Gtk
import gtkgui_helpers import gtkgui_helpers
@ -32,6 +32,7 @@ from gi.repository import Pango
from common import gajim from common import gajim
@unique
class Column(IntEnum): class Column(IntEnum):
PREFERENCE_NAME = 0 PREFERENCE_NAME = 0
VALUE = 1 VALUE = 1

View File

@ -35,8 +35,9 @@
import re import re
from common import defs from common import defs
from gi.repository import GLib from gi.repository import GLib
from enum import IntEnum from enum import IntEnum, unique
@unique
class Option(IntEnum): class Option(IntEnum):
TYPE = 0 TYPE = 0
VAL = 1 VAL = 1

View File

@ -26,8 +26,9 @@ import os
import sys import sys
import tempfile import tempfile
from common import defs from common import defs
from enum import Enum from enum import Enum, unique
@unique
class Type(Enum): class Type(Enum):
CONFIG = 0 CONFIG = 0
CACHE = 1 CACHE = 1

View File

@ -23,7 +23,7 @@ import hashlib
import logging import logging
import os import os
import threading import threading
from enum import IntEnum from enum import IntEnum, unique
import nbxmpp import nbxmpp
from common import gajim from common import gajim
from common import configpaths from common import configpaths
@ -39,6 +39,7 @@ from common.jingle_ftstates import (
log = logging.getLogger('gajim.c.jingle_ft') log = logging.getLogger('gajim.c.jingle_ft')
@unique
class State(IntEnum): class State(IntEnum):
NOT_STARTED = 0 NOT_STARTED = 0
INITIALIZED = 1 INITIALIZED = 1

View File

@ -29,7 +29,7 @@ Handles Jingle sessions (XEP 0166)
# * timeout # * timeout
import logging import logging
from enum import Enum from enum import Enum, unique
import nbxmpp import nbxmpp
from common import gajim from common import gajim
from common.jingle_transport import get_jingle_transport, JingleTransportIBB from common.jingle_transport import get_jingle_transport, JingleTransportIBB
@ -43,6 +43,7 @@ from common.connection_handlers_events import (
log = logging.getLogger("gajim.c.jingle_session") log = logging.getLogger("gajim.c.jingle_session")
# FIXME: Move it to JingleSession.States? # FIXME: Move it to JingleSession.States?
@unique
class JingleStates(Enum): class JingleStates(Enum):
""" """
States in which jingle session may exist States in which jingle session may exist

View File

@ -19,7 +19,7 @@ Handles Jingle Transports (currently only ICE-UDP)
import logging import logging
import socket import socket
from enum import IntEnum from enum import IntEnum, unique
import nbxmpp import nbxmpp
from common import gajim from common import gajim
@ -34,6 +34,7 @@ def get_jingle_transport(node):
return transports[namespace](node) return transports[namespace](node)
@unique
class TransportType(IntEnum): class TransportType(IntEnum):
""" """
Possible types of a JingleTransport Possible types of a JingleTransport

View File

@ -36,7 +36,7 @@ import json
from gzip import GzipFile from gzip import GzipFile
from io import BytesIO from io import BytesIO
from gi.repository import GLib from gi.repository import GLib
from enum import IntEnum from enum import IntEnum, unique
from common import exceptions from common import exceptions
from common import gajim from common import gajim
@ -51,10 +51,12 @@ CACHE_DB_PATH = gajim.gajimpaths['CACHE_DB']
import logging import logging
log = logging.getLogger('gajim.c.logger') log = logging.getLogger('gajim.c.logger')
@unique
class JIDConstant(IntEnum): class JIDConstant(IntEnum):
NORMAL_TYPE = 0 NORMAL_TYPE = 0
ROOM_TYPE = 1 ROOM_TYPE = 1
@unique
class KindConstant(IntEnum): class KindConstant(IntEnum):
STATUS = 0 STATUS = 0
GCSTATUS = 1 GCSTATUS = 1
@ -65,6 +67,7 @@ class KindConstant(IntEnum):
CHAT_MSG_SENT = 6 CHAT_MSG_SENT = 6
ERROR = 7 ERROR = 7
@unique
class ShowConstant(IntEnum): class ShowConstant(IntEnum):
ONLINE = 0 ONLINE = 0
CHAT = 1 CHAT = 1
@ -73,6 +76,7 @@ class ShowConstant(IntEnum):
DND = 4 DND = 4
OFFLINE = 5 OFFLINE = 5
@unique
class TypeConstant(IntEnum): class TypeConstant(IntEnum):
AIM = 0 AIM = 0
GG = 1 GG = 1
@ -90,6 +94,7 @@ class TypeConstant(IntEnum):
MRIM = 13 MRIM = 13
NO_TRANSPORT = 14 NO_TRANSPORT = 14
@unique
class SubscriptionConstant(IntEnum): class SubscriptionConstant(IntEnum):
NONE = 0 NONE = 0
TO = 1 TO = 1

View File

@ -17,8 +17,9 @@
## along with Gajim. If not, see <http://www.gnu.org/licenses/>. ## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
## ##
from enum import IntEnum from enum import IntEnum, unique
@unique
class Constant(IntEnum): class Constant(IntEnum):
NAME = 0 NAME = 0
DOMAIN = 1 DOMAIN = 1
@ -26,6 +27,7 @@ class Constant(IntEnum):
BARE_NAME = 3 BARE_NAME = 3
TXT = 4 TXT = 4
@unique
class ConstantRI(IntEnum): class ConstantRI(IntEnum):
INTERFACE = 0 INTERFACE = 0
PROTOCOL = 1 PROTOCOL = 1

View File

@ -29,7 +29,7 @@ from gi.repository import Pango
import os import os
import time import time
from enum import IntEnum from enum import IntEnum, unique
import gtkgui_helpers import gtkgui_helpers
import tooltips import tooltips
@ -44,6 +44,7 @@ from nbxmpp.protocol import NS_JINGLE_FILE_TRANSFER
import logging import logging
log = logging.getLogger('gajim.filetransfer_window') log = logging.getLogger('gajim.filetransfer_window')
@unique
class Column(IntEnum): class Column(IntEnum):
IMAGE = 0 IMAGE = 0
LABELS = 1 LABELS = 1

View File

@ -46,7 +46,7 @@ import cell_renderer_image
import dataforms_widget import dataforms_widget
import nbxmpp import nbxmpp
from enum import IntEnum from enum import IntEnum, unique
from common import events from common import events
from common import gajim from common import gajim
@ -65,6 +65,7 @@ from common.connection_handlers_events import GcMessageOutgoingEvent
import logging import logging
log = logging.getLogger('gajim.groupchat_control') log = logging.getLogger('gajim.groupchat_control')
@unique
class Column(IntEnum): class Column(IntEnum):
IMG = 0 # image to show state (online, new message etc) IMG = 0 # image to show state (online, new message etc)
NICK = 1 # contact nickame or ROLE name NICK = 1 # contact nickame or ROLE name

View File

@ -77,8 +77,9 @@ from common.logger import LOG_DB_PATH, JIDConstant, KindConstant
from common import helpers from common import helpers
import dialogs import dialogs
from enum import IntEnum from enum import IntEnum, unique
@unique
class Column(IntEnum): class Column(IntEnum):
UNIXTIME = 2 UNIXTIME = 2
MESSAGE = 3 MESSAGE = 3

View File

@ -31,7 +31,7 @@ from gi.repository import GLib
import time import time
import calendar import calendar
from enum import IntEnum from enum import IntEnum, unique
import gtkgui_helpers import gtkgui_helpers
import conversation_textview import conversation_textview
@ -43,6 +43,7 @@ from common import exceptions
from common.logger import ShowConstant, KindConstant from common.logger import ShowConstant, KindConstant
@unique
class InfoColumn(IntEnum): class InfoColumn(IntEnum):
'''Completion dict''' '''Completion dict'''
JID = 0 JID = 0
@ -50,6 +51,7 @@ class InfoColumn(IntEnum):
NAME = 2 NAME = 2
COMPLETION = 3 COMPLETION = 3
@unique
class Column(IntEnum): class Column(IntEnum):
LOG_JID = 0 LOG_JID = 0
CONTACT_NAME = 1 CONTACT_NAME = 1

View File

@ -32,7 +32,7 @@ from gi.repository import GdkPixbuf
from gi.repository import GLib, Gdk from gi.repository import GLib, Gdk
import os import os
from enum import IntEnum from enum import IntEnum, unique
import gtkgui_helpers import gtkgui_helpers
from dialogs import WarningDialog, YesNoDialog, ArchiveChooserDialog from dialogs import WarningDialog, YesNoDialog, ArchiveChooserDialog
@ -43,6 +43,7 @@ from plugins.helpers import GajimPluginActivateException
from plugins.plugins_i18n import _ from plugins.plugins_i18n import _
from common.exceptions import PluginsystemError from common.exceptions import PluginsystemError
@unique
class Column(IntEnum): class Column(IntEnum):
PLUGIN = 0 PLUGIN = 0
NAME = 1 NAME = 1

View File

@ -43,7 +43,7 @@ import os
import time import time
import locale import locale
from enum import IntEnum from enum import IntEnum, unique
import common.sleepy import common.sleepy
import history_window import history_window
@ -69,6 +69,7 @@ from message_window import MessageWindowMgr
from nbxmpp.protocol import NS_FILE, NS_ROSTERX, NS_CONFERENCE from nbxmpp.protocol import NS_FILE, NS_ROSTERX, NS_CONFERENCE
@unique
class Column(IntEnum): class Column(IntEnum):
IMG = 0 # image to show state (online, new message etc) IMG = 0 # image to show state (online, new message etc)
NAME = 1 # cellrenderer text that holds contact nickame NAME = 1 # cellrenderer text that holds contact nickame