Skip to content

Commit

Permalink
Fixed errors and few warnings
Browse files Browse the repository at this point in the history
- see pylintrc file diff
  • Loading branch information
rsb-23 committed Jan 14, 2025
1 parent 7cc72c1 commit 1d863b4
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 61 deletions.
11 changes: 0 additions & 11 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,15 @@ max-statements = 95
[MESSAGES CONTROL]
disable=
I,
# E
no-member,
possibly-used-before-assignment,
undefined-variable,
# W
arguments-differ,
attribute-defined-outside-init,
broad-exception-caught,
deprecated-module,
fixme,
keyword-arg-before-vararg,
logging-format-interpolation,
pointless-statement,
pointless-string-statement,
protected-access,
raise-missing-from,
redefined-builtin,
redefined-outer-name,
undefined-loop-variable,
unnecessary-pass,
unspecified-encoding,
unused-argument,
unused-variable,
Expand Down
12 changes: 6 additions & 6 deletions tests/test_icalendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import re

import dateutil
import pytest

import vobject

Expand Down Expand Up @@ -390,7 +391,7 @@ def test_pytz_timezone_serializing():
try:
import pytz
except ImportError:
return self.skipTest("pytz not installed") # NOQA
pytest.skip("pytz not installed")

# Avoid conflicting cached tzinfo from other tests
def unregister_tzid(tzid):
Expand Down Expand Up @@ -541,23 +542,22 @@ def test_includes_dst_offset():
assert vobject.icalendar.includes_dst_offset(tz, dt)

# Leaving DST: 2024-11-03 02:00:00 reverts to 01:00
pass


def test_omits_dst_offset():

# Check dateutil, pytz, and zoneinfo (3.9+) tzinfo instances
timezones = []
_timezones = []
if "dateutil" in globals():
tz = dateutil.tz.gettz("US/Eastern")
assert tz is not None
timezones.append(tz)
_timezones.append(tz)
if "zoneinfo" in globals():
tz = zoneinfo.ZoneInfo("US/Eastern")
assert tz is not None
timezones.append(tz)
_timezones.append(tz)

for tz in timezones:
for tz in _timezones:
dt = datetime.datetime(2020, 1, 1)
assert vobject.icalendar.omits_dst_offset(tz, dt)

Expand Down
47 changes: 21 additions & 26 deletions vobject/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class VBase(object):

def __init__(self, group=None, *args, **kwds):
super(VBase, self).__init__(*args, **kwds)
self.name = None
self.group = group
self.behavior = None
self.parentBehavior = None
Expand Down Expand Up @@ -136,7 +137,7 @@ def autoBehavior(self, cascade=False):
behavior = getBehavior(self.name, knownChildTup[2])
if behavior is not None:
self.setBehavior(behavior, cascade)
if isinstance(self, ContentLine) and self.encoded:
if isinstance(self, ContentLine) and self.encoded: # pylint:disable=e1101
self.behavior.decode(self)
elif isinstance(self, ContentLine):
self.behavior = parentBehavior.defaultBehavior
Expand Down Expand Up @@ -212,16 +213,10 @@ def transformFromNative(self):
return self

def transformChildrenToNative(self):
"""
Recursively replace children with their native representation.
"""
pass
"""Recursively replace children with their native representation."""

def transformChildrenFromNative(self, clearBehavior=True):
"""
Recursively transform native children to vanilla representations.
"""
pass
"""Recursively transform native children to vanilla representations."""

def serialize(self, buf=None, lineLength=75, validate=True, behavior=None, *args, **kwargs):
"""
Expand Down Expand Up @@ -947,28 +942,28 @@ def dquoteEscape(param):
return param


def foldOneLine(outbuf, input, lineLength=75):
def foldOneLine(outbuf, input_, lineLength=75):
"""
Folding line procedure that ensures multi-byte utf-8 sequences are not
broken across lines
TO-DO: This all seems odd. Is it still needed, especially in python3?
"""
if len(input) < lineLength:
if len(input_) < lineLength:
# Optimize for unfolded line case
try:
outbuf.write(bytes(input, "UTF-8"))
outbuf.write(bytes(input_, "UTF-8"))
except Exception:
# fall back on py2 syntax
outbuf.write(input)
outbuf.write(input_)

else:
# Look for valid utf8 range and write that out
start = 0
written = 0
counter = 0 # counts line size in bytes
decoded = to_unicode(input)
length = len(to_basestring(input))
decoded = to_unicode(input_)
length = len(to_basestring(input_))
while written < length:
s = decoded[start] # take one char
size = len(to_basestring(s)) # calculate it's size in bytes
Expand Down Expand Up @@ -1163,7 +1158,7 @@ def readOne(stream, validate=False, transform=True, ignoreUnreadable=False, allo
__behaviorRegistry = {}


def registerBehavior(behavior, name=None, default=False, id=None):
def registerBehavior(behavior, name=None, default=False, id_=None):
"""
Register the given behavior.
Expand All @@ -1172,40 +1167,40 @@ def registerBehavior(behavior, name=None, default=False, id=None):
"""
if not name:
name = behavior.name.upper()
if id is None:
id = behavior.versionString
if id_ is None:
id_ = behavior.versionString
if name in __behaviorRegistry:
if default:
__behaviorRegistry[name].insert(0, (id, behavior))
__behaviorRegistry[name].insert(0, (id_, behavior))
else:
__behaviorRegistry[name].append((id, behavior))
__behaviorRegistry[name].append((id_, behavior))
else:
__behaviorRegistry[name] = [(id, behavior)]
__behaviorRegistry[name] = [(id_, behavior)]


def getBehavior(name, id=None):
def getBehavior(name, id_=None):
"""
Return a matching behavior if it exists, or None.
If id is None, return the default for name.
"""
name = name.upper()
if name in __behaviorRegistry:
if id:
if id_:
for n, behavior in __behaviorRegistry[name]:
if n == id:
if n == id_:
return behavior

return __behaviorRegistry[name][0][1]
return None


def newFromBehavior(name, id=None):
def newFromBehavior(name, id_=None):
"""
Given a name, return a behaviored ContentLine or Component.
"""
name = name.upper()
behavior = getBehavior(name, id)
behavior = getBehavior(name, id_)
if behavior is None:
raise VObjectError("No behavior found named {0!s}".format(name))
if behavior.isComponent:
Expand Down
1 change: 0 additions & 1 deletion vobject/behavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ def transformFromNative(cls, obj):
@classmethod
def generateImplicitParameters(cls, obj):
"""Generate any required information that don't yet exist."""
pass

@classmethod
def serialize(cls, obj, buf, lineLength, validate=True, *args, **kwargs):
Expand Down
3 changes: 2 additions & 1 deletion vobject/hcalendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class HCalendar(VCalendar2_0):
name = "HCALENDAR"

@classmethod
def serialize(cls, obj, buf=None, lineLength=None, validate=True):
def serialize(cls, obj, buf=None, lineLength=None, validate=True, *args, **kwargs):
"""
Serialize iCalendar to HTML using the hCalendar microformat (http://microformats.org/wiki/hcalendar)
"""
Expand Down Expand Up @@ -76,6 +76,7 @@ def out(s):
# DTSTART
dtstart = event.getChildValue("dtstart")
if dtstart:
machine = timeformat = ""
if type(dtstart) is date:
timeformat = "%A, %B %e"
machine = "%Y%m%d"
Expand Down
16 changes: 8 additions & 8 deletions vobject/icalendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,19 @@ def getTzid(tzid, smart=True):
"""
Return the tzid if it exists, or None.
"""
tz = __tzidMap.get(toUnicode(tzid))
if smart and tzid and not tz:
_tz = __tzidMap.get(toUnicode(tzid))
if smart and tzid and not _tz:
try:
from pytz import UnknownTimeZoneError, timezone

try:
tz = timezone(tzid)
registerTzid(toUnicode(tzid), tz)
_tz = timezone(tzid)
registerTzid(toUnicode(tzid), _tz)
except UnknownTimeZoneError as e:
logging.error("Unknown Timezone: %r", e.args[0])
except ImportError as e:
logging.error(e)
return tz
return _tz


utc = tz.tzutc()
Expand Down Expand Up @@ -1015,7 +1015,7 @@ def findTzids(obj, table):
obj.add(TimezoneComponent(tzinfo=getTzid(tzid)))

@classmethod
def serialize(cls, obj, buf, lineLength, validate=True):
def serialize(cls, obj, buf, lineLength, validate=True, *args, **kwargs):
"""
Set implicit parameters, do encoding, return unicode string.
Expand Down Expand Up @@ -1622,8 +1622,8 @@ def transformFromNative(cls, obj):
transformed = []
for tup in obj.value:
transformed.append(periodToString(tup, cls.forceUTC))
if len(transformed) > 0:
tzid = TimezoneComponent.registerTzinfo(tup[0].tzinfo)
if transformed:
tzid = TimezoneComponent.registerTzinfo(tup[0].tzinfo) # pylint:disable=W0631
if not cls.forceUTC and tzid is not None:
obj.tzid_param = tzid

Expand Down
12 changes: 4 additions & 8 deletions vobject/ics_diff.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
from __future__ import print_function
"""
Compare VTODOs and VEVENTs in two iCalendar sources.
"""

from optparse import OptionParser

import vobject

"""
Compare VTODOs and VEVENTs in two iCalendar sources.
"""


def getSortKey(component):
def getUID(component):
Expand Down Expand Up @@ -183,7 +181,6 @@ def prettyDiff(leftObj, rightObj):
if right is not None:
right.prettyPrint()
print(">>>>>>>>>>>>>>>")
print


def main():
Expand Down Expand Up @@ -217,8 +214,7 @@ def getOptions():

(cmdline_options, args) = parser.parse_args()
if len(args) < 2:
print("error: too few arguments given")
print
print("error: too few arguments given\n")
print(parser.format_help())
return False, False

Expand Down

0 comments on commit 1d863b4

Please sign in to comment.