diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2016-10-11 21:12:40 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2016-10-11 21:12:40 +0300 |
commit | f53205cdf147185e7001aaf9b0d724abc14dad7f (patch) | |
tree | a924f1492c42fe9e2362e2b52cfdea03a7f5539d /vk | |
parent | README update (diff) | |
download | vk-scripts-f53205cdf147185e7001aaf9b0d724abc14dad7f.tar.gz vk-scripts-f53205cdf147185e7001aaf9b0d724abc14dad7f.zip |
revert most of the recent Pylint fixes
I know better how to name my things.
Diffstat (limited to '')
-rw-r--r-- | vk/last_seen.py | 30 | ||||
-rw-r--r-- | vk/platform.py | 20 | ||||
-rw-r--r-- | vk/tracking/db/record.py | 6 | ||||
-rw-r--r-- | vk/tracking/db/timestamp.py | 30 | ||||
-rw-r--r-- | vk/tracking/online_sessions.py | 24 | ||||
-rw-r--r-- | vk/tracking/status_tracker.py | 34 | ||||
-rw-r--r-- | vk/user.py | 32 |
7 files changed, 88 insertions, 88 deletions
diff --git a/vk/last_seen.py b/vk/last_seen.py index 1753e12..5266940 100644 --- a/vk/last_seen.py +++ b/vk/last_seen.py @@ -11,23 +11,23 @@ from numbers import Integral, Real from .platform import Platform -def _parse_time(src): - if isinstance(src, datetime): - if src.tzinfo is None or src.tzinfo.utcoffset(src) is None: - src = src.replace(tzinfo=timezone.utc) - return src - elif isinstance(src, Real) or isinstance(src, Integral): - return datetime.fromtimestamp(src, tz=timezone.utc) +def _parse_time(x): + if isinstance(x, datetime): + if x.tzinfo is None or x.tzinfo.utcoffset(x) is None: + x = x.replace(tzinfo=timezone.utc) + return x + elif isinstance(x, Real) or isinstance(x, Integral): + return datetime.fromtimestamp(x, tz=timezone.utc) else: raise TypeError() -def _parse_platform(src): - if src in Platform: - return src - if isinstance(src, str): - return Platform.from_string(src) +def _parse_platform(x): + if x in Platform: + return x + if isinstance(x, str): + return Platform.from_string(x) else: - return Platform(src) + return Platform(x) class LastSeenField(Enum): TIME = 'time' @@ -85,8 +85,8 @@ class LastSeen(MutableMapping): def get_time(self): return self[LastSeenField.TIME] - def set_time(self, timestamp): - self[LastSeenField.TIME] = timestamp + def set_time(self, time): + self[LastSeenField.TIME] = time def has_platform(self): return LastSeenField.PLATFORM in self diff --git a/vk/platform.py b/vk/platform.py index 26f20dc..fa1e665 100644 --- a/vk/platform.py +++ b/vk/platform.py @@ -16,26 +16,26 @@ class Platform(Enum): WEB = 7 @staticmethod - def from_string(src): - return Platform(int(src)) + def from_string(s): + return Platform(int(s)) def __str__(self): return str(self.value) @staticmethod - def _uppercase_first_letter(text): - match = re.search(r'\w', text) - if match is None: - return text - return text[:match.start()] + match.group().upper() + text[match.end():] + def _uppercase_first_letter(s): + m = re.search(r'\w', s) + if m is None: + return s + return s[:m.start()] + m.group().upper() + s[m.end():] def get_descr_header(self): return self._uppercase_first_letter(_PLATFORM_DESCRIPTIONS[self]) def get_descr_text(self): - descr = _PLATFORM_DESCRIPTIONS[self] - descr = descr.replace('unrecognized', 'an unrecognized') - return 'the ' + descr + s = _PLATFORM_DESCRIPTIONS[self] + s = s.replace('unrecognized', 'an unrecognized') + return 'the ' + s def get_descr_text_capitalized(self): return self._uppercase_first_letter(self.get_descr_text()) diff --git a/vk/tracking/db/record.py b/vk/tracking/db/record.py index 6c000ab..c03c3ca 100644 --- a/vk/tracking/db/record.py +++ b/vk/tracking/db/record.py @@ -38,9 +38,9 @@ class Record(MutableMapping): def __setitem__(self, field, value): if field is LastSeenField.TIME: if isinstance(value, str): - value = Timestamp.from_string(value).impl + value = Timestamp.from_string(value).dt elif isinstance(value, Timestamp): - value = value.impl + value = value.dt elif isinstance(value, datetime): pass else: @@ -78,7 +78,7 @@ class Record(MutableMapping): def _update_last_seen_field(self, last_seen, field): if field is LastSeenField.TIME: - last_seen[field] = self[field].impl + last_seen[field] = self[field].dt else: last_seen[field] = self[field] diff --git a/vk/tracking/db/timestamp.py b/vk/tracking/db/timestamp.py index 0881fb3..b2219ca 100644 --- a/vk/tracking/db/timestamp.py +++ b/vk/tracking/db/timestamp.py @@ -11,25 +11,25 @@ class Timestamp: return datetime.utcnow() @staticmethod - def _is_timezone_aware(impl): - return impl.tzinfo is not None and impl.tzinfo.utcoffset(impl) is not None + def _is_timezone_aware(dt): + return dt.tzinfo is not None and dt.tzinfo.utcoffset(dt) is not None @staticmethod - def _lose_timezone(impl): - if Timestamp._is_timezone_aware(impl): - return impl.astimezone(timezone.utc).replace(tzinfo=None) - return impl + def _lose_timezone(dt): + if Timestamp._is_timezone_aware(dt): + return dt.astimezone(timezone.utc).replace(tzinfo=None) + return dt - def __init__(self, impl=None): - if impl is None: - impl = self._new() - impl = impl.replace(microsecond=0) - impl = self._lose_timezone(impl) - self.impl = impl + def __init__(self, dt=None): + if dt is None: + dt = self._new() + dt = dt.replace(microsecond=0) + dt = self._lose_timezone(dt) + self.dt = dt @staticmethod - def from_string(src): - return Timestamp(datetime.strptime(src, '%Y-%m-%dT%H:%M:%SZ')) + def from_string(s): + return Timestamp(datetime.strptime(s, '%Y-%m-%dT%H:%M:%SZ')) def __str__(self): - return self.impl.isoformat() + 'Z' + return self.dt.isoformat() + 'Z' diff --git a/vk/tracking/online_sessions.py b/vk/tracking/online_sessions.py index 11d3196..204e1cc 100644 --- a/vk/tracking/online_sessions.py +++ b/vk/tracking/online_sessions.py @@ -99,20 +99,20 @@ class OnlineSessionEnumerator(MutableMapping): return by_hour @staticmethod - def _split_into_days(time_from, time_to): - while time_from.date() != time_to.date(): - next_day = time_from.date() + timedelta(days=1) - yield time_from.date(), next_day - time_from - time_from = next_day - yield time_to.date(), time_to - time_from + def _split_into_days(a, b): + while a.date() != b.date(): + next_day = a.date() + timedelta(days=1) + yield a.date(), next_day - a + a = next_day + yield b.date(), b - a @staticmethod - def _split_into_hours(time_from, time_to): - while time_from.date() != time_to.date() or time_from.hour != time_to.hour: - next_hour = time_from.replace(minute=0, second=0) + timedelta(hours=1) - yield time_from.hour, next_hour - time_from - time_from = next_hour - yield time_to.hour, time_to - time_from + def _split_into_hours(a, b): + while a.date() != b.date() or a.hour != b.hour: + next_hour = a.replace(minute=0, second=0) + timedelta(hours=1) + yield a.hour, next_hour - a + a = next_hour + yield b.hour, b - a def _process_database_record(self, record): return self._close_user_session(record.to_user()) diff --git a/vk/tracking/status_tracker.py b/vk/tracking/status_tracker.py index d52af6a..d47de39 100644 --- a/vk/tracking/status_tracker.py +++ b/vk/tracking/status_tracker.py @@ -27,21 +27,21 @@ class StatusTracker: self.add_status_update_handler(writer.on_status_update) self.add_connection_error_handler(writer.on_connection_error) - def add_initial_status_handler(self, handler): - self._assert_is_callback(handler) - self._on_initial_status.append(handler) + def add_initial_status_handler(self, fn): + self._assert_is_callback(fn) + self._on_initial_status.append(fn) - def add_status_update_handler(self, handler): - self._assert_is_callback(handler) - self._on_status_update.append(handler) + def add_status_update_handler(self, fn): + self._assert_is_callback(fn) + self._on_status_update.append(fn) - def add_connection_error_handler(self, handler): - self._assert_is_callback(handler) - self._on_connection_error.append(handler) + def add_connection_error_handler(self, fn): + self._assert_is_callback(fn) + self._on_connection_error.append(fn) @staticmethod - def _assert_is_callback(handler): - if not isinstance(handler, Callable): + def _assert_is_callback(fn): + if not isinstance(fn, Callable): raise TypeError() _USER_FIELDS = UserField.DOMAIN, UserField.ONLINE, UserField.LAST_SEEN, @@ -50,16 +50,16 @@ class StatusTracker: return {user.get_uid(): user for user in self._api.users_get(uids, self._USER_FIELDS)} def _notify_status(self, user): - for handler in self._on_initial_status: - handler(user) + for fn in self._on_initial_status: + fn(user) def _notify_status_update(self, user): - for handler in self._on_status_update: - handler(user) + for fn in self._on_status_update: + fn(user) def _notify_connection_error(self, e): - for handler in self._on_connection_error: - handler(e) + for fn in self._on_connection_error: + fn(e) def _query_initial_status(self, uids): while True: @@ -9,30 +9,30 @@ from enum import Enum from .last_seen import LastSeen -def _parse_last_seen(src): - if isinstance(src, LastSeen): - return src - elif isinstance(src, Mapping): - return LastSeen.from_api_response(src) +def _parse_last_seen(x): + if isinstance(x, LastSeen): + return x + elif isinstance(x, Mapping): + return LastSeen.from_api_response(x) else: raise TypeError() -def _parse_bool(src): - if isinstance(src, str): - if str(True) == src: +def _parse_bool(x): + if isinstance(x, str): + if str(True) == x: return True - elif str(False) == src: + elif str(False) == x: return False else: raise ValueError() else: - return bool(src) + return bool(x) -def _parse_hidden(src): - return _parse_bool(src) +def _parse_hidden(x): + return _parse_bool(x) -def _parse_online_flag(src): - return _parse_bool(src) +def _parse_online_flag(x): + return _parse_bool(x) class UserField(Enum): UID = 'uid' @@ -56,8 +56,8 @@ class DeactivationReason(Enum): def __str__(self): return self.value -def _parse_deactivated(src): - return DeactivationReason(src) +def _parse_deactivated(s): + return DeactivationReason(s) class User(Hashable, MutableMapping): @staticmethod |