[go: up one dir, main page]

Skip to content

Commit

Permalink
Run pyupgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-blanchard committed Dec 10, 2020
1 parent c248586 commit 8a67090
Show file tree
Hide file tree
Showing 37 changed files with 126 additions and 152 deletions.
2 changes: 0 additions & 2 deletions bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
:author: Ian Cordasco
"""

from __future__ import print_function, with_statement

import argparse
import sys
import time
from collections import defaultdict
from io import open
from os import listdir
from os.path import dirname, isdir, join, realpath, relpath, splitext

Expand Down
2 changes: 1 addition & 1 deletion chardet/big5prober.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

class Big5Prober(MultiByteCharSetProber):
def __init__(self):
super(Big5Prober, self).__init__()
super().__init__()
self.coding_sm = CodingStateMachine(BIG5_SM_MODEL)
self.distribution_analyzer = Big5DistributionAnalysis()
self.reset()
Expand Down
14 changes: 7 additions & 7 deletions chardet/chardistribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
JIS_TYPICAL_DISTRIBUTION_RATIO)


class CharDistributionAnalysis(object):
class CharDistributionAnalysis:
ENOUGH_DATA_THRESHOLD = 1024
SURE_YES = 0.99
SURE_NO = 0.01
Expand Down Expand Up @@ -112,7 +112,7 @@ def get_order(self, byte_str):

class EUCTWDistributionAnalysis(CharDistributionAnalysis):
def __init__(self):
super(EUCTWDistributionAnalysis, self).__init__()
super().__init__()
self._char_to_freq_order = EUCTW_CHAR_TO_FREQ_ORDER
self._table_size = EUCTW_TABLE_SIZE
self.typical_distribution_ratio = EUCTW_TYPICAL_DISTRIBUTION_RATIO
Expand All @@ -131,7 +131,7 @@ def get_order(self, byte_str):

class EUCKRDistributionAnalysis(CharDistributionAnalysis):
def __init__(self):
super(EUCKRDistributionAnalysis, self).__init__()
super().__init__()
self._char_to_freq_order = EUCKR_CHAR_TO_FREQ_ORDER
self._table_size = EUCKR_TABLE_SIZE
self.typical_distribution_ratio = EUCKR_TYPICAL_DISTRIBUTION_RATIO
Expand All @@ -150,7 +150,7 @@ def get_order(self, byte_str):

class GB2312DistributionAnalysis(CharDistributionAnalysis):
def __init__(self):
super(GB2312DistributionAnalysis, self).__init__()
super().__init__()
self._char_to_freq_order = GB2312_CHAR_TO_FREQ_ORDER
self._table_size = GB2312_TABLE_SIZE
self.typical_distribution_ratio = GB2312_TYPICAL_DISTRIBUTION_RATIO
Expand All @@ -169,7 +169,7 @@ def get_order(self, byte_str):

class Big5DistributionAnalysis(CharDistributionAnalysis):
def __init__(self):
super(Big5DistributionAnalysis, self).__init__()
super().__init__()
self._char_to_freq_order = BIG5_CHAR_TO_FREQ_ORDER
self._table_size = BIG5_TABLE_SIZE
self.typical_distribution_ratio = BIG5_TYPICAL_DISTRIBUTION_RATIO
Expand All @@ -191,7 +191,7 @@ def get_order(self, byte_str):

class SJISDistributionAnalysis(CharDistributionAnalysis):
def __init__(self):
super(SJISDistributionAnalysis, self).__init__()
super().__init__()
self._char_to_freq_order = JIS_CHAR_TO_FREQ_ORDER
self._table_size = JIS_TABLE_SIZE
self.typical_distribution_ratio = JIS_TYPICAL_DISTRIBUTION_RATIO
Expand All @@ -216,7 +216,7 @@ def get_order(self, byte_str):

class EUCJPDistributionAnalysis(CharDistributionAnalysis):
def __init__(self):
super(EUCJPDistributionAnalysis, self).__init__()
super().__init__()
self._char_to_freq_order = JIS_CHAR_TO_FREQ_ORDER
self._table_size = JIS_TABLE_SIZE
self.typical_distribution_ratio = JIS_TYPICAL_DISTRIBUTION_RATIO
Expand Down
4 changes: 2 additions & 2 deletions chardet/charsetgroupprober.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@

class CharSetGroupProber(CharSetProber):
def __init__(self, lang_filter=None):
super(CharSetGroupProber, self).__init__(lang_filter=lang_filter)
super().__init__(lang_filter=lang_filter)
self._active_num = 0
self.probers = []
self._best_guess_prober = None

def reset(self):
super(CharSetGroupProber, self).reset()
super().reset()
self._active_num = 0
for prober in self.probers:
if prober:
Expand Down
2 changes: 1 addition & 1 deletion chardet/charsetprober.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from .enums import ProbingState


class CharSetProber(object):
class CharSetProber:

SHORTCUT_THRESHOLD = 0.95

Expand Down
1 change: 0 additions & 1 deletion chardet/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

1 change: 0 additions & 1 deletion chardet/cli/chardetect.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"""

from __future__ import absolute_import, print_function, unicode_literals

import argparse
import sys
Expand Down
2 changes: 1 addition & 1 deletion chardet/codingstatemachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from .enums import MachineState


class CodingStateMachine(object):
class CodingStateMachine:
"""
A state machine to verify a byte sequence for a particular encoding. For
each byte the detector receives, it will feed that byte to every active
Expand Down
17 changes: 5 additions & 12 deletions chardet/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,8 @@
import sys


if sys.version_info < (3, 0):
PY2 = True
PY3 = False
string_types = (str, unicode)
text_type = unicode
iteritems = dict.iteritems
else:
PY2 = False
PY3 = True
string_types = (bytes, str)
text_type = str
iteritems = dict.items
PY2 = False
PY3 = True
string_types = (bytes, str)
text_type = str
iteritems = dict.items
2 changes: 1 addition & 1 deletion chardet/cp949prober.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

class CP949Prober(MultiByteCharSetProber):
def __init__(self):
super(CP949Prober, self).__init__()
super().__init__()
self.coding_sm = CodingStateMachine(CP949_SM_MODEL)
# NOTE: CP949 is a superset of EUC-KR, so the distribution should be
# not different.
Expand Down
12 changes: 6 additions & 6 deletions chardet/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""


class InputState(object):
class InputState:
"""
This enum represents the different states a universal detector can be in.
"""
Expand All @@ -14,7 +14,7 @@ class InputState(object):
HIGH_BYTE = 2


class LanguageFilter(object):
class LanguageFilter:
"""
This enum represents the different language filters we can apply to a
``UniversalDetector``.
Expand All @@ -29,7 +29,7 @@ class LanguageFilter(object):
CJK = CHINESE | JAPANESE | KOREAN


class ProbingState(object):
class ProbingState:
"""
This enum represents the different states a prober can be in.
"""
Expand All @@ -38,7 +38,7 @@ class ProbingState(object):
NOT_ME = 2


class MachineState(object):
class MachineState:
"""
This enum represents the different states a state machine can be in.
"""
Expand All @@ -47,7 +47,7 @@ class MachineState(object):
ITS_ME = 2


class SequenceLikelihood(object):
class SequenceLikelihood:
"""
This enum represents the likelihood of a character following the previous one.
"""
Expand All @@ -62,7 +62,7 @@ def get_num_categories(cls):
return 4


class CharacterCategory(object):
class CharacterCategory:
"""
This enum represents the different categories language models for
``SingleByteCharsetProber`` put characters into.
Expand Down
4 changes: 2 additions & 2 deletions chardet/escprober.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class EscCharSetProber(CharSetProber):
"""

def __init__(self, lang_filter=None):
super(EscCharSetProber, self).__init__(lang_filter=lang_filter)
super().__init__(lang_filter=lang_filter)
self.coding_sm = []
if self.lang_filter & LanguageFilter.CHINESE_SIMPLIFIED:
self.coding_sm.append(CodingStateMachine(HZ_SM_MODEL))
Expand All @@ -56,7 +56,7 @@ def __init__(self, lang_filter=None):
self.reset()

def reset(self):
super(EscCharSetProber, self).reset()
super().reset()
for coding_sm in self.coding_sm:
if not coding_sm:
continue
Expand Down
4 changes: 2 additions & 2 deletions chardet/eucjpprober.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@

class EUCJPProber(MultiByteCharSetProber):
def __init__(self):
super(EUCJPProber, self).__init__()
super().__init__()
self.coding_sm = CodingStateMachine(EUCJP_SM_MODEL)
self.distribution_analyzer = EUCJPDistributionAnalysis()
self.context_analyzer = EUCJPContextAnalysis()
self.reset()

def reset(self):
super(EUCJPProber, self).reset()
super().reset()
self.context_analyzer.reset()

@property
Expand Down
2 changes: 1 addition & 1 deletion chardet/euckrprober.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

class EUCKRProber(MultiByteCharSetProber):
def __init__(self):
super(EUCKRProber, self).__init__()
super().__init__()
self.coding_sm = CodingStateMachine(EUCKR_SM_MODEL)
self.distribution_analyzer = EUCKRDistributionAnalysis()
self.reset()
Expand Down
2 changes: 1 addition & 1 deletion chardet/euctwprober.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

class EUCTWProber(MultiByteCharSetProber):
def __init__(self):
super(EUCTWProber, self).__init__()
super().__init__()
self.coding_sm = CodingStateMachine(EUCTW_SM_MODEL)
self.distribution_analyzer = EUCTWDistributionAnalysis()
self.reset()
Expand Down
2 changes: 1 addition & 1 deletion chardet/gb2312prober.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

class GB2312Prober(MultiByteCharSetProber):
def __init__(self):
super(GB2312Prober, self).__init__()
super().__init__()
self.coding_sm = CodingStateMachine(GB2312_SM_MODEL)
self.distribution_analyzer = GB2312DistributionAnalysis()
self.reset()
Expand Down
2 changes: 1 addition & 1 deletion chardet/hebrewprober.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class HebrewProber(CharSetProber):
LOGICAL_HEBREW_NAME = "windows-1255"

def __init__(self):
super(HebrewProber, self).__init__()
super().__init__()
self._final_char_logical_score = None
self._final_char_visual_score = None
self._prev = None
Expand Down
4 changes: 2 additions & 2 deletions chardet/jpcntx.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
(0,4,0,3,0,3,0,3,0,3,5,5,3,3,3,3,4,3,4,3,3,3,4,4,4,3,3,3,3,4,3,5,3,3,1,3,2,4,5,5,5,5,4,3,4,5,5,3,2,2,3,3,3,3,2,3,3,1,2,3,2,4,3,3,3,4,0,4,0,2,0,4,3,2,2,1,2,0,3,0,0,4,1),
)

class JapaneseContextAnalysis(object):
class JapaneseContextAnalysis:
NUM_OF_CATEGORY = 6
DONT_KNOW = -1
ENOUGH_REL_THRESHOLD = 100
Expand Down Expand Up @@ -182,7 +182,7 @@ def get_order(self, byte_str):

class SJISContextAnalysis(JapaneseContextAnalysis):
def __init__(self):
super(SJISContextAnalysis, self).__init__()
super().__init__()
self._charset_name = "SHIFT_JIS"

@property
Expand Down
1 change: 0 additions & 1 deletion chardet/langbulgarianmodel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from chardet.sbcharsetprober import SingleByteCharSetModel

Expand Down
1 change: 0 additions & 1 deletion chardet/langgreekmodel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from chardet.sbcharsetprober import SingleByteCharSetModel

Expand Down
1 change: 0 additions & 1 deletion chardet/langhebrewmodel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from chardet.sbcharsetprober import SingleByteCharSetModel

Expand Down
1 change: 0 additions & 1 deletion chardet/langhungarianmodel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from chardet.sbcharsetprober import SingleByteCharSetModel

Expand Down
1 change: 0 additions & 1 deletion chardet/langrussianmodel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from chardet.sbcharsetprober import SingleByteCharSetModel

Expand Down
1 change: 0 additions & 1 deletion chardet/langthaimodel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from chardet.sbcharsetprober import SingleByteCharSetModel

Expand Down
1 change: 0 additions & 1 deletion chardet/langturkishmodel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from chardet.sbcharsetprober import SingleByteCharSetModel

Expand Down
2 changes: 1 addition & 1 deletion chardet/latin1prober.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@

class Latin1Prober(CharSetProber):
def __init__(self):
super(Latin1Prober, self).__init__()
super().__init__()
self._last_char_class = None
self._freq_counter = None
self.reset()
Expand Down
4 changes: 2 additions & 2 deletions chardet/mbcharsetprober.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ class MultiByteCharSetProber(CharSetProber):
"""

def __init__(self, lang_filter=None):
super(MultiByteCharSetProber, self).__init__(lang_filter=lang_filter)
super().__init__(lang_filter=lang_filter)
self.distribution_analyzer = None
self.coding_sm = None
self._last_char = [0, 0]

def reset(self):
super(MultiByteCharSetProber, self).reset()
super().reset()
if self.coding_sm:
self.coding_sm.reset()
if self.distribution_analyzer:
Expand Down
2 changes: 1 addition & 1 deletion chardet/mbcsgroupprober.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

class MBCSGroupProber(CharSetGroupProber):
def __init__(self, lang_filter=None):
super(MBCSGroupProber, self).__init__(lang_filter=lang_filter)
super().__init__(lang_filter=lang_filter)
self.probers = [
UTF8Prober(),
SJISProber(),
Expand Down
Loading

0 comments on commit 8a67090

Please sign in to comment.