Package tdi :: Module _version
[frames] | no frames]

Source Code for Module tdi._version

  1  # -*- coding: ascii -*- 
  2  r""" 
  3  :Copyright: 
  4   
  5   Copyright 2006 - 2015 
  6   Andr\xe9 Malo or his licensors, as applicable 
  7   
  8  :License: 
  9   
 10   Licensed under the Apache License, Version 2.0 (the "License"); 
 11   you may not use this file except in compliance with the License. 
 12   You may obtain a copy of the License at 
 13   
 14       http://www.apache.org/licenses/LICENSE-2.0 
 15   
 16   Unless required by applicable law or agreed to in writing, software 
 17   distributed under the License is distributed on an "AS IS" BASIS, 
 18   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 19   See the License for the specific language governing permissions and 
 20   limitations under the License. 
 21   
 22  ======================== 
 23   Version Representation 
 24  ======================== 
 25   
 26  Version representation. 
 27  """ 
 28  if __doc__: 
 29      # pylint: disable = redefined-builtin 
 30      __doc__ = __doc__.encode('ascii').decode('unicode_escape') 
 31  __author__ = r"Andr\xe9 Malo".encode('ascii').decode('unicode_escape') 
 32  __docformat__ = "restructuredtext en" 
 33   
 34   
35 -class Version(tuple):
36 """ 37 Container representing the package version 38 39 :IVariables: 40 `major` : ``int`` 41 The major version number 42 43 `minor` : ``int`` 44 The minor version number 45 46 `patch` : ``int`` 47 The patch level version number 48 49 `is_dev` : ``bool`` 50 Is it a development version? 51 52 `revision` : ``int`` 53 Internal revision 54 """ 55 _str = "(unknown)" 56
57 - def __new__(cls, versionstring, is_dev, revision):
58 """ 59 Construction 60 61 :Parameters: 62 `versionstring` : ``str`` 63 The numbered version string (like ``"1.1.0"``) 64 It should contain at least three dot separated numbers 65 66 `is_dev` : ``bool`` 67 Is it a development version? 68 69 `revision` : ``int`` 70 Internal revision 71 72 :Return: New version instance 73 :Rtype: `version` 74 """ 75 # pylint: disable = unused-argument 76 77 tup = [] 78 versionstring = versionstring.strip() 79 isuni = isinstance(versionstring, unicode) 80 strs = [] 81 if versionstring: 82 for item in versionstring.split('.'): 83 try: 84 item = int(item) 85 strs.append(str(item)) 86 except ValueError: 87 if isuni: 88 strs.append(item.encode('utf-8')) 89 else: 90 try: 91 item = item.decode('ascii') 92 strs.append(item.encode('ascii')) 93 except UnicodeError: 94 try: 95 item = item.decode('utf-8') 96 strs.append(item.encode('utf-8')) 97 except UnicodeError: 98 strs.append(item) 99 item = item.decode('latin-1') 100 tup.append(item) 101 while len(tup) < 3: 102 tup.append(0) 103 self = tuple.__new__(cls, tup) 104 self._str = ".".join(strs) # pylint: disable = protected-access 105 return self
106
107 - def __init__(self, versionstring, is_dev, revision):
108 """ 109 Initialization 110 111 :Parameters: 112 `versionstring` : ``str`` 113 The numbered version string (like ``1.1.0``) 114 It should contain at least three dot separated numbers 115 116 `is_dev` : ``bool`` 117 Is it a development version? 118 119 `revision` : ``int`` 120 Internal revision 121 """ 122 # pylint: disable = unused-argument 123 124 super(Version, self).__init__() 125 self.major, self.minor, self.patch = self[:3] 126 self.is_dev = bool(is_dev) 127 self.revision = int(revision)
128
129 - def __repr__(self):
130 """ 131 Create a development string representation 132 133 :Return: The string representation 134 :Rtype: ``str`` 135 """ 136 return "%s.%s(%r, is_dev=%r, revision=%r)" % ( 137 self.__class__.__module__, 138 self.__class__.__name__, 139 self._str, 140 self.is_dev, 141 self.revision, 142 )
143
144 - def __str__(self):
145 """ 146 Create a version like string representation 147 148 :Return: The string representation 149 :Rtype: ``str`` 150 """ 151 return "%s%s" % ( 152 self._str, 153 ("", "-dev-r%d" % self.revision)[self.is_dev], 154 )
155
156 - def __unicode__(self):
157 """ 158 Create a version like unicode representation 159 160 :Return: The unicode representation 161 :Rtype: ``unicode`` 162 """ 163 return u"%s%s" % ( 164 u".".join(map(unicode, self)), 165 (u"", u"-dev-r%d" % self.revision)[self.is_dev], 166 )
167