def to36(n): if n == 0: return '0' out = '' while n != 0: n, m = divmod(IntUtils.LONG(n), 36) out = Base36.CHAR_SET[int(m)] + out return out
def __init__(self, fileName, ioMode='a', timeout=10, delay=None): """ Prepare the file locker. Specify the file to lock and optionally the maximum timeout and the _delay between each attempt to lock.""" self._isLocked = False self._lockFileName = fileName + '.lock' self._fileName = fileName self._timeout = timeout self._delay = float(IntUtils.jitter(50, 0.1)) self._ioMode = ioMode self._lockFile = None self._file = None
def __init__(self, fileName, ioMode ='a', timeout =10, delay =None): """ Prepare the file locker. Specify the file to lock and optionally the maximum timeout and the _delay between each attempt to lock.""" self._isLocked = False self._lockFileName = fileName + '.lock' self._fileName = fileName self._timeout = timeout self._delay = float(IntUtils.jitter(50, 0.1)) self._ioMode = ioMode self._lockFile = None self._file = None
def fromDict(self, value): if 'alpha' in value: self._opacity = value.get('alpha', 1.0) elif 'opacity' in value: self._opacity = value.get('opacity', 1.0) else: self._opacity = 1.0 v = value.get('color') if IntUtils.isInt(v): self._rawColor = int(v) else: self.load(v)
def createEngine(self): """ Creates the database engine for this definition """ connectArgs = {'charset':'utf8'} if self.socketPath: connectArgs['unix_socket'] = str(self.socketPath) if self.useSSL: connectArgs['ssl'] = self.sslConnectArgs return create_engine( self.url, echo=False, poolclass=QueuePool, echo_pool=True, pool_size=10, max_overflow=20, pool_timeout=30, pool_recycle=IntUtils.jitter(1800), connect_args=connectArgs )
def _setColor(self, sourceColor, normalized =False): bendCount = None cls = self.__class__ # COLOR VALUE DICT if isinstance(sourceColor, dict) and 'color' in sourceColor: self.fromDict(sourceColor) # INTEGER COLOR elif IntUtils.isInt(sourceColor): self._rawColor = int(sourceColor) # FLOAT LUMA COLOR elif isinstance(sourceColor, float): self._rawColor = cls.lumaToInt(sourceColor) # RGB, HSV, OR HSL DICT COLOR elif isinstance(sourceColor, dict): for key in ['a', 'alpha', 'o', 'opacity']: if key in sourceColor: self._opacity = float(sourceColor[key]) break if 'l' in sourceColor: self._rawColor = cls.hslToInt(sourceColor, normalized) if 'h' in sourceColor or 's' in sourceColor or 'v' in sourceColor: self._rawColor = cls.hsvToInt(sourceColor, normalized) else: self._rawColor = cls.rgbToInt(sourceColor, normalized) # RGB TUPLE OR LIST COLOR elif isinstance(sourceColor, tuple) or isinstance(sourceColor, list): r = sourceColor[0] g = sourceColor[1] b = sourceColor[2] factor = 255.0 if normalized else 1.0 c = {'r':round(factor*r), 'g':round(factor*g), 'b':round(factor*b)} self._rawColor = cls.rgbToInt(c) if len(sourceColor) > 3: self._opacity = float(sourceColor[3]) # STRING-BASED COLORS elif StringUtils.isStringType(sourceColor): bendCount = cls.getBendCount(sourceColor) sourceColor = sourceColor.rstrip('+-') if cls.isHexColor(sourceColor): self._rawColor = cls.hexToInt(sourceColor) else: self._rawColor = self._parseUnknownColorString(sourceColor) if self._rawColor is None: self._rawColor = 0 # IF ALL ELSE FAILS: BLACK! else: self._rawColor = 0 # CLEAR THE COLOR CACHE self._unCache() # IF STRING COLOR BEND if bendCount: self.bend(bendCount)