Parsers for Tor version numbers.
Portions of this module are directly taken from, or derived from, twisted.python.compat, and are subject to the Twisted Matrix Labs copyright and license, in addition to the copyrights and license for the rest of this program.
SERVER_VERSIONS
= [u'0.2.2.39', u'0.2.3.24-rc', u'0.2.3.25', u'0.2.4.5-alpha', u'0.2.4.6-alpha', u'0.2.4.7-alpha', u'0.2.4.8-alpha', u'0.2.4.9-alpha', u'0.2.4.10-alpha', u'0.2.4.11-alpha', u'0.2.4.12-alpha', u'0.2.4.14-alpha', u'0.2.4.15-rc', u'0.2.4.16-rc', u'0.2.4.17-rc', u'0.2.4.18-rc', u'0.2.4.19', u'0.2.4.20', u'0.2.5.1-alpha']¶The <major>.<minor>.<micro>.<rev> version numbers for tor, taken from the ‘server-versions’ line of a consensus file
IncomparableVersions
[source]¶Bases: exceptions.TypeError
Two versions could not be compared.
InvalidVersion
[source]¶Bases: exceptions.ValueError
Invalid version string.
_comparable
(klass)[source]¶Class decorator that ensures support for the special __cmp__()
method.
On Python 2 this does nothing.
On Python 3, __eq__()
, __lt__()
, etc. methods are added to the
class, relying on __cmp__()
to implement their comparisons.
getRandomVersion
()[source]¶Get a random Tor version from server-versions
in the consensus.
Return type: | str |
---|---|
Returns: | One of SERVER_VERSIONS . |
shouldHaveOptPrefix
(version)[source]¶Returns true if descriptor lines for a Tor version should be prefixed
with 'opt '
.
In tor, up to and including, version 0.2.3.25, server-descriptors (bridge
or relay) prefixed several lines with 'opt '
. For the 0.2.3.x
series, these lines were:
protocols
fingerprint
hidden-service-dir
extra-info-digest
Parameters: | version (str) – One of SERVER_VERSIONS . |
---|---|
Return type: | bool |
Returns: | True if we should include the 'opt ' prefix; False
otherwise. |
shouldSupportHSIntroV0
(version)[source]¶Returns true if a Hidden Service is old enough to support the Hidden Service intro protocol version 0.
See generateProtocolVersionsLine()
.
Parameters: | version (str) – One of SERVER_VERSIONS . |
---|---|
Return type: | bool |
Returns: | True if we should include the intro protocol version 0;
False otherwise. |
Version
(version, package=None)[source]¶Bases: object
Holds, parses, and does comparison operations for version numbers.
Attr str major: | The major version number. |
---|---|
Attr str minor: | The minor version number. |
Attr str micro: | The micro version number. |
Attr str prerelease: | |
Sometimes another number, or alpha /rc2 /etc.,
often suffixed with a - , + , or # . |
Create a version object.
Comparisons may be computed between instances of Version
.
Note
This class was modified from the original Twisted class
(twisted.python.versions.Version) because Tor’s versioning
system uses four integers, separated by .
, so that the
prerelease
attribute, and all methods using it, can accomodate
for the idiosyncracies in Tor’s version strings. The standard
<major>.<minor>.<micro>-<prerelease>
version format will also
work just the same as it does with the unmodified Twisted class.
>>> ver = torversions.Version('0.2.5.1-alpha', 'tor')
>>> ver.base
0.2.5.1-alpha
>>> str(ver)
tor-0.2.5.1-alpha
>>> ver.micro
5
>>> ver.prerelease
1-alpha
>>> ver.package
tor
Parameters: |
|
---|
base
()[source]¶Get the base version number (with prerelease).
Return type: | str |
---|---|
Returns: | A version number, without the package/program name, and with
the prefix (if available). For example:
"0.2.5.1-alpha" . |
getPrefixedPrerelease
(separator=u'.')[source]¶Get the prerelease string, prefixed by the separator prefix
.
Parameters: | separator (str) – The separator to use between the rest of the version string and the prerelease string. |
---|---|
Return type: | str |
Returns: | The separator plus the prefix , for example
".1-alpha" . |