mirror of
https://github.com/SickGear/SickGear.git
synced 2024-11-15 09:25:04 +00:00
e56303798c
Initial SickGear for Python 3.
28 lines
717 B
Python
28 lines
717 B
Python
import functools
|
|
from hachoir.core.iso639 import ISO639_2
|
|
|
|
|
|
@functools.total_ordering
|
|
class Language:
|
|
|
|
def __init__(self, code):
|
|
code = str(code)
|
|
if code not in ISO639_2:
|
|
raise ValueError("Invalid language code: %r" % code)
|
|
self.code = code
|
|
|
|
def __eq__(self, other):
|
|
if other.__class__ != Language:
|
|
return NotImplemented
|
|
return self.code == other.code
|
|
|
|
def __lt__(self, other):
|
|
if other.__class__ != Language:
|
|
return NotImplemented
|
|
return self.code < other.code
|
|
|
|
def __str__(self):
|
|
return ISO639_2[self.code]
|
|
|
|
def __repr__(self):
|
|
return "<Language '%s', code=%r>" % (str(self), self.code)
|