PK}mHG8Âqb formatist.py""" A Python library to convert from older `%` style format strings, to newer `{}` style. """ import re __all__ = [ 'convert', ] def convert(fmtstr): """Convert %-style format specifiers in `fmtstr` to {}-style specifiers >>> convert("Hello %(name)s. It's %(temp).1f C") "Hello {name!s:}. It's {temp:>.1f} C" """ oldFormatString = fmtstr matches = re.finditer(r"(%)(\((?P.*?)\))" r"(?P[ #0\-\+])?" r"(?P(\*|\d*))" r"(?P\.(\*|\d*))?" r"(?P[diouxXeEfFgGcrs%])", oldFormatString) result = [] previousEnd = 0 for match in matches: result.append(oldFormatString[previousEnd:match.start()]) conv = match.group("conversion") if conv in 'sr': bang = "!" + conv colon = ":" else: bang = "" fill = match.group("flags") or "" align = ">" sign = "" sharp = "" zero = "" width = match.group("minimum") or "" comma = "" precision = match.group("precision") or "" ctype = conv colon = ":" + (fill + align + sign + sharp + zero + width + comma + precision + ctype) result.append("{" + match.group("name") + bang + colon + "}") previousEnd = match.end() result.append(oldFormatString[previousEnd:]) return ''.join(result) PKÒJGÃm³\pp)formatist-0.0.2.dist-info/DESCRIPTION.rstformatist ========= .. image:: https://travis-ci.org/moreati/formatist.svg?branch=master :target: https://travis-ci.org/moreati/formatist A Python library to convert from older `%` style format strings, to newer `{}` style. .. code:: python >>> import formatist >>> greeting = "Hello %(name)s. It's %(temp).1f C" >>> print(greeting % {'name': 'Alice', 'temp': 23.45678}) Hello Alice. It's 23.5 C >>> greeting2 = formatist.convert(greeting) >>> print(greeting2) Hello {name!s:}. It's {temp:>.1f} C >>> print(greeting2.format(name='Alice', temp=23.45678)) Hello Alice. It's 23.5 C PKÒJGd‘ ãµµ'formatist-0.0.2.dist-info/metadata.json{"classifiers": ["Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.2", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5"], "extensions": {"python.details": {"contacts": [{"email": "glyph@twistedmatrix.com", "name": "Glyph", "role": "author"}], "document_names": {"description": "DESCRIPTION.rst"}, "project_urls": {"Home": "https://github.com/moreati/formatist"}}}, "generator": "bdist_wheel (0.24.0)", "keywords": ["string", "format", "pep3101", "percent", "braces"], "license": "MIT", "metadata_version": "2.0", "name": "formatist", "summary": "Converts %-style format strings to newer {}-style", "version": "0.0.2"}PKÒJG`HXÌ 'formatist-0.0.2.dist-info/top_level.txtformatist PKÒJG‡3onnformatist-0.0.2.dist-info/WHEELWheel-Version: 1.0 Generator: bdist_wheel (0.24.0) Root-Is-Purelib: true Tag: py2-none-any Tag: py3-none-any PKÒJGñš5øªª"formatist-0.0.2.dist-info/METADATAMetadata-Version: 2.0 Name: formatist Version: 0.0.2 Summary: Converts %-style format strings to newer {}-style Home-page: https://github.com/moreati/formatist Author: Glyph Author-email: glyph@twistedmatrix.com License: MIT Keywords: string format pep3101 percent braces Platform: UNKNOWN Classifier: Development Status :: 3 - Alpha Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: MIT License Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.2 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 formatist ========= .. image:: https://travis-ci.org/moreati/formatist.svg?branch=master :target: https://travis-ci.org/moreati/formatist A Python library to convert from older `%` style format strings, to newer `{}` style. .. code:: python >>> import formatist >>> greeting = "Hello %(name)s. It's %(temp).1f C" >>> print(greeting % {'name': 'Alice', 'temp': 23.45678}) Hello Alice. It's 23.5 C >>> greeting2 = formatist.convert(greeting) >>> print(greeting2) Hello {name!s:}. It's {temp:>.1f} C >>> print(greeting2.format(name='Alice', temp=23.45678)) Hello Alice. It's 23.5 C PKÒJGÏ©{?? formatist-0.0.2.dist-info/RECORDformatist.py,sha256=LhEnUAYfhR0l1pLMQh5QGpH4nFim6NODUAWzGiRM46E,1566 formatist-0.0.2.dist-info/WHEEL,sha256=AvR0WeTpDaxT645bl5FQxUK6NPsTls2ttpcGJg3j1Xg,110 formatist-0.0.2.dist-info/RECORD,, formatist-0.0.2.dist-info/METADATA,sha256=QTE4NwoDNCXD4FVmgmnd9lGK-bFlpZfgs4rig816bjU,1450 formatist-0.0.2.dist-info/top_level.txt,sha256=HEPoUXq9PNRdfFKnSqgjOqI6YfORepv85WgNuGtjfBA,10 formatist-0.0.2.dist-info/DESCRIPTION.rst,sha256=NdclQJ8yO8LJzxuKLLzIYSftaFoo13Qx4o-UclyoyCc,624 formatist-0.0.2.dist-info/metadata.json,sha256=VxUxNyDbM35JrXUiKy-oSFUvMquGAl0tUwKqWizwiak,949 PK}mHG8Âqb formatist.pyPKÒJGÃm³\pp)Hformatist-0.0.2.dist-info/DESCRIPTION.rstPKÒJGd‘ ãµµ'ÿformatist-0.0.2.dist-info/metadata.jsonPKÒJG`HXÌ 'ù formatist-0.0.2.dist-info/top_level.txtPKÒJG‡3onnH formatist-0.0.2.dist-info/WHEELPKÒJGñš5øªª"ó formatist-0.0.2.dist-info/METADATAPKÒJGÏ©{?? Ýformatist-0.0.2.dist-info/RECORDPK&Z