How to use the scour.Unit.NONE function in scour

To help you get started, we’ve selected a few scour examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nhooey / svg-scour / scour.py View on Github external
def __init__(self, str):
		try: # simple unitless and no scientific notation
			self.value = float(str)
			if int(self.value) == self.value: 
				self.value = int(self.value)
			self.units = Unit.NONE
		except ValueError:
			# we know that the length string has an exponent, a unit, both or is invalid

			# parse out number, exponent and unit
			self.value = 0
			unitBegin = 0
			scinum = scinumber.match(str)
			if scinum != None:
				# this will always match, no need to check it
				numMatch = number.match(str)
				expMatch = sciExponent.search(str, numMatch.start(0))
				self.value = (float(numMatch.group(0)) *
					10 ** float(expMatch.group(1)))
				unitBegin = expMatch.end(1)
			else:
				# unit or invalid
github nhooey / svg-scour / scour.py View on Github external
def get(unitstr):
		if unitstr is None: return Unit.NONE
		try:
			return Unit.s2u[unitstr]
		except KeyError:
			return Unit.INVALID
github nhooey / svg-scour / scour.py View on Github external
if node.getAttribute('fy') != '':
		if node.getAttribute('fy') == node.getAttribute('cy'):
			node.removeAttribute('fy')
			num += 1

	# cx: 50%
	if node.getAttribute('cx') != '':
		cx = SVGLength(node.getAttribute('cx'))
		if (cx.value == 50 and cx.units == Unit.PCT) or (cx.value == 0.5 and cx.units == Unit.NONE):
			node.removeAttribute('cx')
			num += 1

	# cy: 50%
	if node.getAttribute('cy') != '':
		cy = SVGLength(node.getAttribute('cy'))
		if (cy.value == 50 and cy.units == Unit.PCT) or (cy.value == 0.5 and cy.units == Unit.NONE):
			node.removeAttribute('cy')
			num += 1

	# r: 50%
	if node.getAttribute('r') != '':
		r = SVGLength(node.getAttribute('r'))
		if (r.value == 50 and r.units == Unit.PCT) or (r.value == 0.5 and r.units == Unit.NONE):
			node.removeAttribute('r')
			num += 1
	
	# Summarily get rid of some more attributes
	attributes = [node.attributes.item(i).nodeName 
				  for i in range(node.attributes.length)]
	for attribute in attributes:
		if attribute not in tainted:
			if attribute in default_attributes.keys():