Python Standard Library Interfaces

The zope.interface.common package provides interfaces for objects distributed as part of the Python standard library. Importing these modules (usually) has the effect of making the standard library objects implement the correct interface.

zope.interface.common.interface

Interfaces for standard python exceptions

interface zope.interface.common.interfaces.IException[source]

Interface for Exception

interface zope.interface.common.interfaces.IStandardError[source]

Extends: zope.interface.common.interfaces.IException

Interface for StandardError (no longer existing.)

interface zope.interface.common.interfaces.IWarning[source]

Extends: zope.interface.common.interfaces.IException

Interface for Warning

interface zope.interface.common.interfaces.ISyntaxError[source]

Extends: zope.interface.common.interfaces.IStandardError

Interface for SyntaxError

interface zope.interface.common.interfaces.ILookupError[source]

Extends: zope.interface.common.interfaces.IStandardError

Interface for LookupError

interface zope.interface.common.interfaces.IValueError[source]

Extends: zope.interface.common.interfaces.IStandardError

Interface for ValueError

interface zope.interface.common.interfaces.IRuntimeError[source]

Extends: zope.interface.common.interfaces.IStandardError

Interface for RuntimeError

interface zope.interface.common.interfaces.IArithmeticError[source]

Extends: zope.interface.common.interfaces.IStandardError

Interface for ArithmeticError

interface zope.interface.common.interfaces.IAssertionError[source]

Extends: zope.interface.common.interfaces.IStandardError

Interface for AssertionError

interface zope.interface.common.interfaces.IAttributeError[source]

Extends: zope.interface.common.interfaces.IStandardError

Interface for AttributeError

interface zope.interface.common.interfaces.IDeprecationWarning[source]

Extends: zope.interface.common.interfaces.IWarning

Interface for DeprecationWarning

interface zope.interface.common.interfaces.IEOFError[source]

Extends: zope.interface.common.interfaces.IStandardError

Interface for EOFError

interface zope.interface.common.interfaces.IEnvironmentError[source]

Extends: zope.interface.common.interfaces.IStandardError

Interface for EnvironmentError

interface zope.interface.common.interfaces.IFloatingPointError[source]

Extends: zope.interface.common.interfaces.IArithmeticError

Interface for FloatingPointError

interface zope.interface.common.interfaces.IIOError[source]

Extends: zope.interface.common.interfaces.IEnvironmentError

Interface for IOError

interface zope.interface.common.interfaces.IImportError[source]

Extends: zope.interface.common.interfaces.IStandardError

Interface for ImportError

interface zope.interface.common.interfaces.IIndentationError[source]

Extends: zope.interface.common.interfaces.ISyntaxError

Interface for IndentationError

interface zope.interface.common.interfaces.IIndexError[source]

Extends: zope.interface.common.interfaces.ILookupError

Interface for IndexError

interface zope.interface.common.interfaces.IKeyError[source]

Extends: zope.interface.common.interfaces.ILookupError

Interface for KeyError

interface zope.interface.common.interfaces.IKeyboardInterrupt[source]

Extends: zope.interface.common.interfaces.IStandardError

Interface for KeyboardInterrupt

interface zope.interface.common.interfaces.IMemoryError[source]

Extends: zope.interface.common.interfaces.IStandardError

Interface for MemoryError

interface zope.interface.common.interfaces.INameError[source]

Extends: zope.interface.common.interfaces.IStandardError

Interface for NameError

interface zope.interface.common.interfaces.INotImplementedError[source]

Extends: zope.interface.common.interfaces.IRuntimeError

Interface for NotImplementedError

interface zope.interface.common.interfaces.IOSError[source]

Extends: zope.interface.common.interfaces.IEnvironmentError

Interface for OSError

interface zope.interface.common.interfaces.IOverflowError[source]

Extends: zope.interface.common.interfaces.IArithmeticError

Interface for ArithmeticError

interface zope.interface.common.interfaces.IOverflowWarning[source]

Extends: zope.interface.common.interfaces.IWarning

Deprecated, no standard class implements this.

This was the interface for OverflowWarning prior to Python 2.5, but that class was removed for all versions after that.

interface zope.interface.common.interfaces.IReferenceError[source]

Extends: zope.interface.common.interfaces.IStandardError

Interface for ReferenceError

interface zope.interface.common.interfaces.IRuntimeWarning[source]

Extends: zope.interface.common.interfaces.IWarning

Interface for RuntimeWarning

interface zope.interface.common.interfaces.IStopIteration[source]

Extends: zope.interface.common.interfaces.IException

Interface for StopIteration

interface zope.interface.common.interfaces.ISyntaxWarning[source]

Extends: zope.interface.common.interfaces.IWarning

Interface for SyntaxWarning

interface zope.interface.common.interfaces.ISystemError[source]

Extends: zope.interface.common.interfaces.IStandardError

Interface for SystemError

interface zope.interface.common.interfaces.ISystemExit[source]

Extends: zope.interface.common.interfaces.IException

Interface for SystemExit

interface zope.interface.common.interfaces.ITabError[source]

Extends: zope.interface.common.interfaces.IIndentationError

Interface for TabError

interface zope.interface.common.interfaces.ITypeError[source]

Extends: zope.interface.common.interfaces.IStandardError

Interface for TypeError

interface zope.interface.common.interfaces.IUnboundLocalError[source]

Extends: zope.interface.common.interfaces.INameError

Interface for UnboundLocalError

interface zope.interface.common.interfaces.IUnicodeError[source]

Extends: zope.interface.common.interfaces.IValueError

Interface for UnicodeError

interface zope.interface.common.interfaces.IUserWarning[source]

Extends: zope.interface.common.interfaces.IWarning

Interface for UserWarning

interface zope.interface.common.interfaces.IZeroDivisionError[source]

Extends: zope.interface.common.interfaces.IArithmeticError

Interface for ZeroDivisionError

zope.interface.common.idatetime

Datetime interfaces.

This module is called idatetime because if it were called datetime the import of the real datetime would fail.

interface zope.interface.common.idatetime.ITimeDeltaClass[source]

This is the timedelta class interface.

This is symbolic; this module does not make datetime.timedelta provide this interface.

min

The most negative timedelta object

max

The most positive timedelta object

resolution

The smallest difference between non-equal timedelta objects

interface zope.interface.common.idatetime.ITimeDelta[source]

Extends: zope.interface.common.idatetime.ITimeDeltaClass

Represent the difference between two datetime objects.

Implemented by datetime.timedelta.

Supported operators:

  • add, subtract timedelta

  • unary plus, minus, abs

  • compare to timedelta

  • multiply, divide by int/long

In addition, datetime supports subtraction of two datetime objects returning a timedelta, and addition or subtraction of a datetime and a timedelta giving a datetime.

Representation: (days, seconds, microseconds).

days

Days between -999999999 and 999999999 inclusive

seconds

Seconds between 0 and 86399 inclusive

microseconds

Microseconds between 0 and 999999 inclusive

interface zope.interface.common.idatetime.IDateClass[source]

This is the date class interface.

This is symbolic; this module does not make datetime.date provide this interface.

min

The earliest representable date

max

The latest representable date

resolution

The smallest difference between non-equal date objects

today()

Return the current local time.

This is equivalent to date.fromtimestamp(time.time())

fromtimestamp(timestamp)

Return the local date from a POSIX timestamp (like time.time())

This may raise ValueError, if the timestamp is out of the range of values supported by the platform C localtime() function. It’s common for this to be restricted to years from 1970 through 2038. Note that on non-POSIX systems that include leap seconds in their notion of a timestamp, leap seconds are ignored by fromtimestamp.

fromordinal(ordinal)

Return the date corresponding to the proleptic Gregorian ordinal.

January 1 of year 1 has ordinal 1. ValueError is raised unless 1 <= ordinal <= date.max.toordinal().

For any date d, date.fromordinal(d.toordinal()) == d.

interface zope.interface.common.idatetime.IDate[source]

Extends: zope.interface.common.idatetime.IDateClass

Represents a date (year, month and day) in an idealized calendar.

Implemented by datetime.date.

Operators:

__repr__, __str__ __cmp__, __hash__ __add__, __radd__, __sub__ (add/radd only with timedelta arg)

year

Between MINYEAR and MAXYEAR inclusive.

month

Between 1 and 12 inclusive

day

Between 1 and the number of days in the given month of the given year.

replace(year, month, day)

Return a date with the same value.

Except for those members given new values by whichever keyword arguments are specified. For example, if d == date(2002, 12, 31), then d.replace(day=26) == date(2000, 12, 26).

timetuple()

Return a 9-element tuple of the form returned by time.localtime.

The hours, minutes and seconds are 0, and the DST flag is -1. d.timetuple() is equivalent to (d.year, d.month, d.day, 0, 0, 0, d.weekday(), d.toordinal() - date(d.year, 1, 1).toordinal() + 1, -1)

toordinal()

Return the proleptic Gregorian ordinal of the date

January 1 of year 1 has ordinal 1. For any date object d, date.fromordinal(d.toordinal()) == d.

weekday()

Return the day of the week as an integer.

Monday is 0 and Sunday is 6. For example, date(2002, 12, 4).weekday() == 2, a Wednesday.

See also

isoweekday.

isoweekday()

Return the day of the week as an integer.

Monday is 1 and Sunday is 7. For example, date(2002, 12, 4).isoweekday() == 3, a Wednesday.

See also

weekday, isocalendar.

isocalendar()

Return a 3-tuple, (ISO year, ISO week number, ISO weekday).

The ISO calendar is a widely used variant of the Gregorian calendar. See http://www.phys.uu.nl/~vgent/calendar/isocalendar.htm for a good explanation.

The ISO year consists of 52 or 53 full weeks, and where a week starts on a Monday and ends on a Sunday. The first week of an ISO year is the first (Gregorian) calendar week of a year containing a Thursday. This is called week number 1, and the ISO year of that Thursday is the same as its Gregorian year.

For example, 2004 begins on a Thursday, so the first week of ISO year 2004 begins on Monday, 29 Dec 2003 and ends on Sunday, 4 Jan 2004, so that date(2003, 12, 29).isocalendar() == (2004, 1, 1) and date(2004, 1, 4).isocalendar() == (2004, 1, 7).

isoformat()

Return a string representing the date in ISO 8601 format.

This is ‘YYYY-MM-DD’. For example, date(2002, 12, 4).isoformat() == '2002-12-04'.

__str__()

For a date d, str(d) is equivalent to d.isoformat().

ctime()

Return a string representing the date.

For example date(2002, 12, 4).ctime() == ‘Wed Dec 4 00:00:00 2002’. d.ctime() is equivalent to time.ctime(time.mktime(d.timetuple())) on platforms where the native C ctime() function (which time.ctime invokes, but which date.ctime() does not invoke) conforms to the C standard.

strftime(format)

Return a string representing the date.

Controlled by an explicit format string. Format codes referring to hours, minutes or seconds will see 0 values.

interface zope.interface.common.idatetime.IDateTimeClass[source]

This is the datetime class interface.

This is symbolic; this module does not make datetime.datetime provide this interface.

min

The earliest representable datetime

max

The latest representable datetime

resolution

The smallest possible difference between non-equal datetime objects

today()

Return the current local datetime, with tzinfo None.

This is equivalent to datetime.fromtimestamp(time.time()).

See also

now, fromtimestamp.

now(tz=None)

Return the current local date and time.

If optional argument tz is None or not specified, this is like today, but, if possible, supplies more precision than can be gotten from going through a time.time timestamp (for example, this may be possible on platforms supplying the C gettimeofday() function).

Else tz must be an instance of a class tzinfo subclass, and the current date and time are converted to tz’s time zone. In this case the result is equivalent to tz.fromutc(datetime.utcnow().replace(tzinfo=tz)).

See also

today, utcnow.

utcnow()

Return the current UTC date and time, with tzinfo None.

This is like now, but returns the current UTC date and time, as a naive datetime object.

See also

now.

fromtimestamp(timestamp, tz=None)

Return the local date and time corresponding to the POSIX timestamp.

Same as is returned by time.time(). If optional argument tz is None or not specified, the timestamp is converted to the platform’s local date and time, and the returned datetime object is naive.

Else tz must be an instance of a class tzinfo subclass, and the timestamp is converted to tz’s time zone. In this case the result is equivalent to tz.fromutc(datetime.utcfromtimestamp(timestamp).replace(tzinfo=tz)).

fromtimestamp() may raise ValueError, if the timestamp is out of the range of values supported by the platform C localtime() or gmtime() functions. It’s common for this to be restricted to years in 1970 through 2038. Note that on non-POSIX systems that include leap seconds in their notion of a timestamp, leap seconds are ignored by fromtimestamp(), and then it’s possible to have two timestamps differing by a second that yield identical datetime objects.

See also

utcfromtimestamp.

utcfromtimestamp(timestamp)

Return the UTC datetime from the POSIX timestamp with tzinfo None.

This may raise ValueError, if the timestamp is out of the range of values supported by the platform C gmtime() function. It’s common for this to be restricted to years in 1970 through 2038.

See also

fromtimestamp.

fromordinal(ordinal)

Return the datetime from the proleptic Gregorian ordinal.

January 1 of year 1 has ordinal 1. ValueError is raised unless 1 <= ordinal <= datetime.max.toordinal(). The hour, minute, second and microsecond of the result are all 0, and tzinfo is None.

combine(date, time)

Return a new datetime object.

Its date members are equal to the given date object’s, and whose time and tzinfo members are equal to the given time object’s. For any datetime object d, d == datetime.combine(d.date(), d.timetz()). If date is a datetime object, its time and tzinfo members are ignored.

interface zope.interface.common.idatetime.IDateTime[source]

Extends: zope.interface.common.idatetime.IDate, zope.interface.common.idatetime.IDateTimeClass

Object contains all the information from a date object and a time object.

Implemented by datetime.datetime.

year

Year between MINYEAR and MAXYEAR inclusive

month

Month between 1 and 12 inclusive

day

Day between 1 and the number of days in the given month of the year

hour

Hour in range(24)

minute

Minute in range(60)

second

Second in range(60)

microsecond

Microsecond in range(1000000)

tzinfo

The object passed as the tzinfo argument to the datetime constructor or None if none was passed

date()

Return date object with same year, month and day.

time()

Return time object with same hour, minute, second, microsecond.

tzinfo is None.

See also

Method timetz().

timetz()

Return time object with same hour, minute, second, microsecond, and tzinfo.

See also

Method time().

replace(year, month, day, hour, minute, second, microsecond, tzinfo)

Return a datetime with the same members, except for those members given new values by whichever keyword arguments are specified.

Note that tzinfo=None can be specified to create a naive datetime from an aware datetime with no conversion of date and time members.

astimezone(tz)

Return a datetime object with new tzinfo member tz, adjusting the date and time members so the result is the same UTC time as self, but in tz’s local time.

tz must be an instance of a tzinfo subclass, and its utcoffset() and dst() methods must not return None. self must be aware (self.tzinfo must not be None, and self.utcoffset() must not return None).

If self.tzinfo is tz, self.astimezone(tz) is equal to self: no adjustment of date or time members is performed. Else the result is local time in time zone tz, representing the same UTC time as self:

after astz = dt.astimezone(tz), astz - astz.utcoffset()

will usually have the same date and time members as dt - dt.utcoffset(). The discussion of class datetime.tzinfo explains the cases at Daylight Saving Time transition boundaries where this cannot be achieved (an issue only if tz models both standard and daylight time).

If you merely want to attach a time zone object tz to a datetime dt without adjustment of date and time members, use dt.replace(tzinfo=tz). If you merely want to remove the time zone object from an aware datetime dt without conversion of date and time members, use dt.replace(tzinfo=None).

Note that the default tzinfo.fromutc method can be overridden in a tzinfo subclass to effect the result returned by astimezone.

utcoffset()

Return the timezone offset in minutes east of UTC (negative west of UTC).

dst()

Return 0 if DST is not in effect, or the DST offset (in minutes eastward) if DST is in effect.

tzname()

Return the timezone name.

timetuple()

Return a 9-element tuple of the form returned by time.localtime.

utctimetuple()

Return UTC time tuple compatilble with time.gmtime.

toordinal()

Return the proleptic Gregorian ordinal of the date.

The same as self.date().toordinal().

weekday()

Return the day of the week as an integer.

Monday is 0 and Sunday is 6. The same as self.date().weekday(). See also isoweekday().

isoweekday()

Return the day of the week as an integer.

Monday is 1 and Sunday is 7. The same as self.date().isoweekday.

See also

weekday, isocalendar.

isocalendar()

Return a 3-tuple, (ISO year, ISO week number, ISO weekday).

The same as self.date().isocalendar().

isoformat(sep='T')

Return a string representing the date and time in ISO 8601 format.

YYYY-MM-DDTHH:MM:SS.mmmmmm or YYYY-MM-DDTHH:MM:SS if microsecond is 0

If utcoffset does not return None, a 6-character string is appended, giving the UTC offset in (signed) hours and minutes:

YYYY-MM-DDTHH:MM:SS.mmmmmm+HH:MM or YYYY-MM-DDTHH:MM:SS+HH:MM if microsecond is 0.

The optional argument sep (default ‘T’) is a one-character separator, placed between the date and time portions of the result.

__str__()

For a datetime instance d, str(d) is equivalent to d.isoformat(' ').

ctime()

Return a string representing the date and time.

datetime(2002, 12, 4, 20, 30, 40).ctime() == 'Wed Dec 4 20:30:40 2002'. d.ctime() is equivalent to time.ctime(time.mktime(d.timetuple())) on platforms where the native C ctime() function (which time.ctime invokes, but which datetime.ctime does not invoke) conforms to the C standard.

strftime(format)

Return a string representing the date and time.

This is controlled by an explicit format string.

interface zope.interface.common.idatetime.ITimeClass[source]

This is the time class interface.

This is symbolic; this module does not make datetime.time provide this interface.

min

The earliest representable time

max

The latest representable time

resolution

The smallest possible difference between non-equal time objects

interface zope.interface.common.idatetime.ITime[source]

Extends: zope.interface.common.idatetime.ITimeClass

Represent time with time zone.

Implemented by datetime.time.

Operators:

__repr__, __str__ __cmp__, __hash__

hour

Hour in range(24)

minute

Minute in range(60)

second

Second in range(60)

microsecond

Microsecond in range(1000000)

tzinfo

The object passed as the tzinfo argument to the time constructor or None if none was passed.

replace(hour, minute, second, microsecond, tzinfo)

Return a time with the same value.

Except for those members given new values by whichever keyword arguments are specified. Note that tzinfo=None can be specified to create a naive time from an aware time, without conversion of the time members.

isoformat()

Return a string representing the time in ISO 8601 format.

That is HH:MM:SS.mmmmmm or, if self.microsecond is 0, HH:MM:SS If utcoffset() does not return None, a 6-character string is appended, giving the UTC offset in (signed) hours and minutes: HH:MM:SS.mmmmmm+HH:MM or, if self.microsecond is 0, HH:MM:SS+HH:MM

__str__()

For a time t, str(t) is equivalent to t.isoformat().

strftime(format)

Return a string representing the time.

This is controlled by an explicit format string.

utcoffset()

Return the timezone offset in minutes east of UTC (negative west of UTC).

If tzinfo is None, returns None, else returns self.tzinfo.utcoffset(None), and raises an exception if the latter doesn’t return None or a timedelta object representing a whole number of minutes with magnitude less than one day.

dst()

Return 0 if DST is not in effect, or the DST offset (in minutes eastward) if DST is in effect.

If tzinfo is None, returns None, else returns self.tzinfo.dst(None), and raises an exception if the latter doesn’t return None, or a timedelta object representing a whole number of minutes with magnitude less than one day.

tzname()

Return the timezone name.

If tzinfo is None, returns None, else returns self.tzinfo.tzname(None), or raises an exception if the latter doesn’t return None or a string object.

interface zope.interface.common.idatetime.ITZInfo[source]

Time zone info class.

utcoffset(dt)

Return offset of local time from UTC, in minutes east of UTC.

If local time is west of UTC, this should be negative. Note that this is intended to be the total offset from UTC; for example, if a tzinfo object represents both time zone and DST adjustments, utcoffset() should return their sum. If the UTC offset isn’t known, return None. Else the value returned must be a timedelta object specifying a whole number of minutes in the range -1439 to 1439 inclusive (1440 = 24*60; the magnitude of the offset must be less than one day).

dst(dt)

Return the daylight saving time (DST) adjustment, in minutes east of UTC, or None if DST information isn’t known.

tzname(dt)

Return the time zone name corresponding to the datetime object as a string.

fromutc(dt)

Return an equivalent datetime in self’s local time.

zope.interface.common.collections

Interface definitions paralleling the abstract base classes defined in collections.abc.

After this module is imported, the standard library types will declare that they implement the appropriate interface. While most standard library types will properly implement that interface (that is, verifyObject(ISequence, list())) will pass, for example), a few might not:

  • memoryview doesn’t feature all the defined methods of ISequence such as count; it is still declared to provide ISequence though.

  • collections.deque.pop doesn’t accept the index argument of collections.abc.MutableSequence.pop

  • range.index does not accept the start and stop arguments.

New in version 5.0.0.

interface zope.interface.common.collections.IAsyncGenerator[source]

Extends: zope.interface.common.collections.IAsyncIterator

Interface for the ABC collections.abc.AsyncGenerator.

Known implementations are:

  • async_generator

__anext__()

Return the next item from the asynchronous generator. When exhausted, raise StopAsyncIteration.

asend(value)

Send a value into the asynchronous generator. Return next yielded value or raise StopAsyncIteration.

athrow(typ, val=None, tb=None)

Raise an exception in the asynchronous generator. Return next yielded value or raise StopAsyncIteration.

aclose()

Raise GeneratorExit inside coroutine.

interface zope.interface.common.collections.IAsyncIterable[source]

Extends: zope.interface.common.ABCInterface

Interface for the ABC collections.abc.AsyncIterable.

__aiter__()
interface zope.interface.common.collections.IAsyncIterator[source]

Extends: zope.interface.common.collections.IAsyncIterable

Interface for the ABC collections.abc.AsyncIterator.

__anext__()

Return the next item or raise StopAsyncIteration when exhausted.

__aiter__()
interface zope.interface.common.collections.IAwaitable[source]

Extends: zope.interface.common.ABCInterface

Interface for the ABC collections.abc.Awaitable.

__await__()
interface zope.interface.common.collections.ICollection[source]

Extends: zope.interface.common.collections.ISized, zope.interface.common.collections.IIterable, zope.interface.common.collections.IContainer

Interface for the ABC collections.abc.Collection.

interface zope.interface.common.collections.IContainer[source]

Extends: zope.interface.common.ABCInterface

Interface for the ABC collections.abc.Container.

The following methods are optional:
  • __contains__

    Optional method. If not provided, the interpreter will use __iter__ or the old __getitem__ protocol to implement in.

interface zope.interface.common.collections.ICoroutine[source]

Extends: zope.interface.common.collections.IAwaitable

Interface for the ABC collections.abc.Coroutine.

Known implementations are:

  • coroutine

send(value)

Send a value into the coroutine. Return next yielded value or raise StopIteration.

throw(typ, val=None, tb=None)

Raise an exception in the coroutine. Return next yielded value or raise StopIteration.

close()

Raise GeneratorExit inside coroutine.

interface zope.interface.common.collections.IGenerator[source]

Extends: zope.interface.common.collections.IIterator

Interface for the ABC collections.abc.Generator.

Known implementations are:

  • generator

__next__()

Return the next item from the generator. When exhausted, raise StopIteration.

send(value)

Send a value into the generator. Return next yielded value or raise StopIteration.

throw(typ, val=None, tb=None)

Raise an exception in the generator. Return next yielded value or raise StopIteration.

close()

Raise GeneratorExit inside generator.

interface zope.interface.common.collections.IHashable[source]

Extends: zope.interface.common.ABCInterface

Interface for the ABC collections.abc.Hashable.

__hash__()
interface zope.interface.common.collections.IItemsView[source]

Extends: zope.interface.common.collections.IMappingView, zope.interface.common.collections.ISet

Interface for the ABC collections.abc.ItemsView.

Known implementations are:

  • dict_items

__contains__(item)
__iter__()
interface zope.interface.common.collections.IIterable[source]

Extends: zope.interface.common.ABCInterface

Interface for the ABC collections.abc.Iterable.

The following methods are optional:
  • __iter__

    Optional method. If not provided, the interpreter will implement iter using the old __getitem__ protocol.

Known implementations are:

interface zope.interface.common.collections.IIterator[source]

Extends: zope.interface.common.collections.IIterable

Interface for the ABC collections.abc.Iterator.

Known implementations are:

  • bytearray_iterator

  • bytes_iterator

  • dict_itemiterator

  • dict_keyiterator

  • dict_valueiterator

  • list_iterator

  • list_reverseiterator

  • longrange_iterator

  • range_iterator

  • set_iterator

  • str_ascii_iterator

  • tuple_iterator

  • zip

__next__()

Return the next item from the iterator. When exhausted, raise StopIteration

__iter__()
interface zope.interface.common.collections.IKeysView[source]

Extends: zope.interface.common.collections.IMappingView, zope.interface.common.collections.ISet

Interface for the ABC collections.abc.KeysView.

Known implementations are:

  • dict_keys

__contains__(key)
__iter__()
interface zope.interface.common.collections.IMapping[source]

Extends: zope.interface.common.collections.ICollection

Interface for the ABC collections.abc.Mapping.

A Mapping is a generic container for associating key/value

Known implementations are:

  • collections.OrderedDict

  • dict

  • jinja2.runtime.Context

  • mappingproxy

  • requests.structures.CaseInsensitiveDict

  • urllib3._collections.HTTPHeaderDict

__getitem__(key)
get(key, default=None)

D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.

__contains__(key)
keys()

D.keys() -> a set-like object providing a view on D’s keys

items()

D.items() -> a set-like object providing a view on D’s items

values()

D.values() -> an object providing a view on D’s values

__eq__(other)
interface zope.interface.common.collections.IMappingView[source]

Extends: zope.interface.common.collections.ISized

Interface for the ABC collections.abc.MappingView.

__init__(mapping)
__len__()
interface zope.interface.common.collections.IMutableMapping[source]

Extends: zope.interface.common.collections.IMapping

Interface for the ABC collections.abc.MutableMapping.

A MutableMapping is a generic container for associating

Known implementations are:

__setitem__(key, value)
__delitem__(key)
pop(key, default=<object object at 0x7fed313ac150>)

D.pop(k[,d]) -> v, remove specified key and return the corresponding value. If key is not found, d is returned if given, otherwise KeyError is raised.

popitem()

D.popitem() -> (k, v), remove and return some (key, value) pair as a 2-tuple; but raise KeyError if D is empty.

clear()

D.clear() -> None. Remove all items from D.

update(other=(), **kwds)

D.update([E, ]**F) -> None. Update D from mapping/iterable E and F. If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v

setdefault(key, default=None)

D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D

interface zope.interface.common.collections.IMutableSequence[source]

Extends: zope.interface.common.collections.ISequence

Interface for the ABC collections.abc.MutableSequence.

All the operations on a read-write sequence.

Known implementations are:

__setitem__(index, value)
__delitem__(index)
insert(index, value)

S.insert(index, value) – insert value before index

append(value)

S.append(value) – append value to the end of the sequence

clear()

S.clear() -> None – remove all items from S

reverse()

S.reverse() – reverse IN PLACE

extend(values)

S.extend(iterable) – extend sequence by appending elements from the iterable

pop(index=-1)

S.pop([index]) -> item – remove and return item at index (default last). Raise IndexError if list is empty or index is out of range.

remove(value)

S.remove(value) – remove first occurrence of value. Raise ValueError if the value is not present.

__iadd__(values)
interface zope.interface.common.collections.IMutableSet[source]

Extends: zope.interface.common.collections.ISet

Interface for the ABC collections.abc.MutableSet.

A mutable set is a finite, iterable container.

Known implementations are:

  • _weakrefset.WeakSet

  • set

add(value)

Add an element.

discard(value)

Remove an element. Do not raise an exception if absent.

remove(value)

Remove an element. If not a member, raise a KeyError.

pop()

Return the popped value. Raise KeyError if empty.

clear()

This is slow (creates N new iterators!) but effective.

__ior__(it)
__iand__(it)
__ixor__(it)
__isub__(it)
interface zope.interface.common.collections.IReversible[source]

Extends: zope.interface.common.collections.IIterable

Interface for the ABC collections.abc.Reversible.

The following methods are optional:
  • __reversed__

    Optional method. If this isn’t present, the interpreter will use __len__ and __getitem__ to implement the reversed builtin.

interface zope.interface.common.collections.ISequence[source]

Extends: zope.interface.common.collections.IReversible, zope.interface.common.collections.ICollection

Interface for the ABC collections.abc.Sequence.

All the operations on a read-only sequence.

The following methods are optional:
  • __reversed__

    Optional method. If this isn’t present, the interpreter will use __len__ and __getitem__ to implement the reversed builtin.

-__iter__

Optional method. If not provided, the interpreter will implement iter using the old __getitem__ protocol.

Known implementations are:

__getitem__(index)
__contains__(value)
index(value, start=0, stop=None)

S.index(value, [start, [stop]]) -> integer – return first index of value. Raises ValueError if the value is not present.

Supporting start and stop arguments is optional, but recommended.

count(value)

S.count(value) -> integer – return number of occurrences of value

interface zope.interface.common.collections.ISet[source]

Extends: zope.interface.common.collections.ICollection

Interface for the ABC collections.abc.Set.

A set is a finite, iterable container.

Known implementations are:

__le__(other)
__lt__(other)
__gt__(other)
__ge__(other)
__eq__(other)
__and__(other)
isdisjoint(other)

Return True if two sets have a null intersection.

__or__(other)
__sub__(other)
__xor__(other)
interface zope.interface.common.collections.ISized[source]

Extends: zope.interface.common.ABCInterface

Interface for the ABC collections.abc.Sized.

__len__()
interface zope.interface.common.collections.IValuesView[source]

Extends: zope.interface.common.collections.IMappingView, zope.interface.common.collections.ICollection

Interface for the ABC collections.abc.ValuesView.

The following methods are optional:
  • __contains__

    Optional method. If not provided, the interpreter will use __iter__ or the old __len__ and __getitem__ protocol to implement in.

Known implementations are:

  • dict_values

__iter__()

zope.interface.common.numbers

Interface definitions paralleling the abstract base classes defined in numbers.

After this module is imported, the standard library types will declare that they implement the appropriate interface.

New in version 5.0.0.

interface zope.interface.common.numbers.INumber[source]

Extends: zope.interface.common.ABCInterface

Interface for the ABC numbers.Number.

All numbers inherit from this class.

Known implementations are:

interface zope.interface.common.numbers.IComplex[source]

Extends: zope.interface.common.numbers.INumber

Interface for the ABC numbers.Complex.

Complex defines the operations that work on the builtin complex type.

The following methods are optional:
  • __complex__

    Rarely implemented, even in builtin types.

Known implementations are:

__bool__()

True if self != 0. Called for bool(self).

__add__(other)

self + other

__neg__()

-self

__pos__()

+self

__sub__(other)

self - other

__mul__(other)

self * other

__truediv__(other)

self / other: Should promote to float when necessary.

__pow__(exponent)

self**exponent; should promote to float or complex when necessary.

__abs__()

Returns the Real distance from 0. Called for abs(self).

conjugate()

(x+y*i).conjugate() returns (x-y*i).

__eq__(other)

self == other

interface zope.interface.common.numbers.IReal[source]

Extends: zope.interface.common.numbers.IComplex

Interface for the ABC numbers.Real.

To Complex, Real adds the operations that work on real numbers.

The following methods are optional:
  • __complex__

    Rarely implemented, even in builtin types.

-__floor__

Rarely implemented, even in builtin types.

-__ceil__

Rarely implemented, even in builtin types.

Known implementations are:

__float__()

Any Real can be converted to a native float object.

Called for float(self).

__trunc__()

trunc(self): Truncates self to an Integral.

Returns an Integral i such that:
  • i>0 iff self>0;

  • abs(i) <= abs(self);

  • for any Integral j satisfying the first two conditions, abs(i) >= abs(j) [i.e. i has “maximal” abs among those].

i.e. “truncate towards 0”.

__divmod__(other)

divmod(self, other): The pair (self // other, self % other).

Sometimes this can be computed faster than the pair of operations.

__floordiv__(other)

self // other: The floor() of self/other.

__mod__(other)

self % other

__lt__(other)

self < other

< on Reals defines a total ordering, except perhaps for NaN.

__le__(other)

self <= other

conjugate()

Conjugate is a no-op for Reals.

interface zope.interface.common.numbers.IRational[source]

Extends: zope.interface.common.numbers.IReal

Interface for the ABC numbers.Rational.

.numerator and .denominator should be in lowest terms.

__float__()

float(self) = self.numerator / self.denominator

It’s important that this conversion use the integer’s “true” division rather than casting one side to float before dividing so that ratios of huge integers convert without overflowing.

interface zope.interface.common.numbers.IIntegral[source]

Extends: zope.interface.common.numbers.IRational

Interface for the ABC numbers.Integral.

Integral adds methods that work on integral numbers.

Known implementations are:

__int__()

int(self)

__index__()

Called whenever an index is needed, such as in slicing

__pow__(exponent, modulus=None)

self ** exponent % modulus, but maybe faster.

Accept the modulus argument if you want to support the 3-argument version of pow(). Raise a TypeError if exponent < 0 or any argument isn’t Integral. Otherwise, just implement the 2-argument version described in Complex.

__lshift__(other)

self << other

__and__(other)

self & other

__xor__(other)

self ^ other

__or__(other)

self | other

__invert__()

~self

__float__()

float(self) == float(int(self))

zope.interface.common.builtins

Interface definitions for builtin types.

After this module is imported, the standard library types will declare that they implement the appropriate interface.

New in version 5.0.0.

interface zope.interface.common.builtins.IList[source]

Extends: zope.interface.common.collections.IMutableSequence

Interface for list

sort(key=None, reverse=False)

Sort the list in place and return None.

key and reverse must be passed by name only.

interface zope.interface.common.builtins.ITuple[source]

Extends: zope.interface.common.collections.ISequence

Interface for tuple

interface zope.interface.common.builtins.ITextString[source]

Extends: zope.interface.common.collections.ISequence

Interface for text (“unicode”) strings.

This is str

interface zope.interface.common.builtins.IByteString[source]

Extends: zope.interface.common.collections.IByteString

Interface for immutable byte strings.

On all Python versions this is bytes.

Unlike zope.interface.common.collections.IByteString (the parent of this interface) this does not include bytearray.

interface zope.interface.common.builtins.INativeString[source]

Extends: zope.interface.common.builtins.ITextString

Interface for native strings.

On all Python versions, this is str. Tt extends ITextString.

interface zope.interface.common.builtins.IBool[source]

Extends: zope.interface.common.numbers.IIntegral

Interface for bool

interface zope.interface.common.builtins.IDict[source]

Extends: zope.interface.common.collections.IMutableMapping

Interface for dict

interface zope.interface.common.builtins.IFile[source]

Extends: zope.interface.common.io.IIOBase

Interface for file.

It is recommended to use the interfaces from zope.interface.common.io instead of this interface.

On Python 3, there is no single implementation of this interface; depending on the arguments, the open() builtin can return many different classes that implement different interfaces from zope.interface.common.io.

zope.interface.common.io

Interface definitions paralleling the abstract base classes defined in io.

After this module is imported, the standard library types will declare that they implement the appropriate interface.

New in version 5.0.0.

interface zope.interface.common.io.IIOBase[source]

Extends: zope.interface.common.ABCInterface

Interface for the ABC io.IOBase.

The abstract base class for all I/O classes.

interface zope.interface.common.io.IRawIOBase[source]

Extends: zope.interface.common.io.IIOBase

Interface for the ABC io.RawIOBase.

Base class for raw binary I/O.

Known implementations are:

interface zope.interface.common.io.IBufferedIOBase[source]

Extends: zope.interface.common.io.IIOBase

Interface for the ABC io.BufferedIOBase.

Base class for buffered IO objects.

Known implementations are:

interface zope.interface.common.io.ITextIOBase[source]

Extends: zope.interface.common.io.IIOBase

Interface for the ABC io.TextIOBase.

Base class for text I/O.

Known implementations are:

zope.interface.common.mapping

Mapping Interfaces.

Importing this module does not mark any standard classes as implementing any of these interfaces.

While this module is not deprecated, new code should generally use zope.interface.common.collections, specifically IMapping and IMutableMapping. This module is occasionally useful for its extremely fine grained breakdown of interfaces.

The standard library dict and collections.UserDict implement IMutableMapping, but do not implement any of the interfaces in this module.

interface zope.interface.common.mapping.IItemMapping[source]

Simplest readable mapping object

__getitem__(key)

Get a value for a key

A KeyError is raised if there is no value for the key.

interface zope.interface.common.mapping.IReadMapping[source]

Extends: zope.interface.common.collections.IContainer, zope.interface.common.mapping.IItemMapping

Basic mapping interface.

Changed in version 5.0.0: Extend IContainer

get(key, default=None)

Get a value for a key

The default is returned if there is no value for the key.

__contains__(key)

Tell if a key exists in the mapping.

interface zope.interface.common.mapping.IWriteMapping[source]

Mapping methods for changing data

__delitem__(key)

Delete a value from the mapping using the key.

__setitem__(key, value)

Set a new item in the mapping.

interface zope.interface.common.mapping.IEnumerableMapping[source]

Extends: zope.interface.common.collections.ISized, zope.interface.common.mapping.IReadMapping

Mapping objects whose items can be enumerated.

Changed in version 5.0.0: Extend ISized

keys()

Return the keys of the mapping object.

__iter__()

Return an iterator for the keys of the mapping object.

values()

Return the values of the mapping object.

items()

Return the items of the mapping object.

interface zope.interface.common.mapping.IMapping[source]

Extends: zope.interface.common.mapping.IWriteMapping, zope.interface.common.mapping.IEnumerableMapping

Simple mapping interface

interface zope.interface.common.mapping.IIterableMapping[source]

Extends: zope.interface.common.mapping.IEnumerableMapping

A mapping that has distinct methods for iterating without copying.

interface zope.interface.common.mapping.IClonableMapping[source]

Something that can produce a copy of itself.

This is available in dict.

copy()

return copy of dict

interface zope.interface.common.mapping.IExtendedReadMapping[source]

Extends: zope.interface.common.mapping.IIterableMapping

Something with a particular method equivalent to __contains__.

On Python 2, dict provided the has_key method, but it was removed in Python 3.

interface zope.interface.common.mapping.IExtendedWriteMapping[source]

Extends: zope.interface.common.mapping.IWriteMapping

Additional mutation methods.

These are all provided by dict.

clear()

delete all items

update(d)

Update D from E: for k in E.keys(): D[k] = E[k]

setdefault(key, default=None)

D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D

pop(k, default=None)

pop(k[,default]) -> value

Remove specified key and return the corresponding value.

If key is not found, default is returned if given, otherwise KeyError is raised. Note that default must not be passed by name.

popitem()

remove and return some (key, value) pair as a 2-tuple; but raise KeyError if mapping is empty

interface zope.interface.common.mapping.IFullMapping[source]

Extends: zope.interface.common.collections.IMutableMapping, zope.interface.common.mapping.IExtendedReadMapping, zope.interface.common.mapping.IExtendedWriteMapping, zope.interface.common.mapping.IClonableMapping, zope.interface.common.mapping.IMapping

Full mapping interface.

Most uses of this interface should instead use IMutableMapping (one of the bases of this interface). The required methods are the same.

Changed in version 5.0.0: Extend IMutableMapping

zope.interface.common.sequence

Sequence Interfaces

Importing this module does not mark any standard classes as implementing any of these interfaces.

While this module is not deprecated, new code should generally use zope.interface.common.collections, specifically ISequence and IMutableSequence. This module is occasionally useful for its fine-grained breakdown of interfaces.

The standard library list, tuple and collections.UserList, among others, implement ISequence or IMutableSequence but do not implement any of the interfaces in this module.

interface zope.interface.common.sequence.IMinimalSequence[source]

Extends: zope.interface.common.collections.IIterable

Most basic sequence interface.

All sequences are iterable. This requires at least one of the following:

  • a __getitem__() method that takes a single argument; integer values starting at 0 must be supported, and IndexError should be raised for the first index for which there is no value, or

  • an __iter__() method that returns an iterator as defined in the Python documentation (http://docs.python.org/lib/typeiter.html).

__getitem__(index)

x.__getitem__(index) <==> x[index]

Declaring this interface does not specify whether __getitem__ supports slice objects.

interface zope.interface.common.sequence.IFiniteSequence[source]

Extends: zope.interface.common.collections.ISized, zope.interface.common.sequence.IMinimalSequence

A sequence of bound size.

Changed in version 5.0.0: Extend ISized

interface zope.interface.common.sequence.IReadSequence[source]

Extends: zope.interface.common.collections.IContainer, zope.interface.common.sequence.IFiniteSequence

read interface shared by tuple and list

This interface is similar to ISequence, but requires that all instances be totally ordered. Most users should prefer ISequence.

Changed in version 5.0.0: Extend IContainer

__contains__(item)

x.__contains__(item) <==> item in x

__lt__(other)

x.__lt__(other) <==> x < other

__le__(other)

x.__le__(other) <==> x <= other

__eq__(other)

x.__eq__(other) <==> x == other

__ne__(other)

x.__ne__(other) <==> x != other

__gt__(other)

x.__gt__(other) <==> x > other

__ge__(other)

x.__ge__(other) <==> x >= other

__add__(other)

x.__add__(other) <==> x + other

__mul__(n)

x.__mul__(n) <==> x * n

__rmul__(n)

x.__rmul__(n) <==> n * x

interface zope.interface.common.sequence.IExtendedReadSequence[source]

Extends: zope.interface.common.sequence.IReadSequence

Full read interface for lists

count(item)

Return number of occurrences of value

index(item, *args)

index(value, [start, [stop]]) -> int

Return first index of value

interface zope.interface.common.sequence.IUniqueMemberWriteSequence[source]

The write contract for a sequence that may enforce unique members

__setitem__(index, item)

x.__setitem__(index, item) <==> x[index] = item

Declaring this interface does not specify whether __setitem__ supports slice objects.

__delitem__(index)

x.__delitem__(index) <==> del x[index]

Declaring this interface does not specify whether __delitem__ supports slice objects.

__iadd__(y)

x.__iadd__(y) <==> x += y

append(item)

Append item to end

insert(index, item)

Insert item before index

pop(index=-1)

Remove and return item at index (default last)

remove(item)

Remove first occurrence of value

reverse()

Reverse IN PLACE

sort(cmpfunc=None)

Stable sort IN PLACE; cmpfunc(x, y) -> -1, 0, 1

extend(iterable)

Extend list by appending elements from the iterable

interface zope.interface.common.sequence.IWriteSequence[source]

Extends: zope.interface.common.sequence.IUniqueMemberWriteSequence

Full write contract for sequences

__imul__(n)

x.__imul__(n) <==> x *= n

interface zope.interface.common.sequence.ISequence[source]

Extends: zope.interface.common.sequence.IReadSequence, zope.interface.common.sequence.IWriteSequence

Full sequence contract.

New code should prefer IMutableSequence.

Compared to that interface, which is implemented by list (IList), among others, this interface is missing the following methods:

  • clear

  • count

  • index

This interface adds the following methods:

  • sort