roman-2.0.0/0000755000175000017500000000000012256770154011644 5ustar warp10warp10roman-2.0.0/buildout.cfg0000664000175000017500000000024112112625710014137 0ustar warp10warp10[buildout] develop = . parts = python test [python] recipe = zc.recipe.egg eggs = roman interpreter = python [test] recipe = zc.recipe.testrunner eggs = roman roman-2.0.0/setup.py0000664000175000017500000000233312112625710013345 0ustar warp10warp10from setuptools import setup setup ( name='roman', version='2.0.0', author = "Mark Pilgrim", author_email = "f8dy@diveintopython.org", description = "Integer to Roman numerals converter", long_description = open('CHANGES.txt').read(), license = "Python 2.1.1", keywords = "roman", classifiers = [ 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers', 'Programming Language :: Python', 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: Implementation :: CPython', 'Programming Language :: Python :: Implementation :: PyPy', 'License :: OSI Approved :: Python Software Foundation License', 'Programming Language :: Python', 'Natural Language :: English', 'Operating System :: OS Independent'], url = 'http://pypi.python.org/pypi/roman', package_dir={"": "src"}, py_modules=["roman"], include_package_data = True, test_suite = 'tests', zip_safe = True, ) roman-2.0.0/src/0000755000175000017500000000000012256770154012433 5ustar warp10warp10roman-2.0.0/src/tests.py0000664000175000017500000000144012112625710014134 0ustar warp10warp10import unittest import roman class TestRoman(unittest.TestCase): def test_toRoman(self): self.assertEqual(roman.toRoman(1), 'I') self.assertEqual(roman.toRoman(2013), 'MMXIII') def test_toRoman_errors(self): self.assertRaises(roman.OutOfRangeError, roman.toRoman, 100000) self.assertRaises(roman.NotIntegerError, roman.toRoman, '1') def test_fromRoman(self): self.assertEqual(roman.fromRoman('I'), 1) self.assertEqual(roman.fromRoman('MMXIII'), 2013) def test_fromRoman_errors(self): self.assertRaises( roman.InvalidRomanNumeralError, roman.fromRoman, '') self.assertRaises( roman.InvalidRomanNumeralError, roman.fromRoman, 'Q12') def test_suite(): return unittest.makeSuite(TestRoman) roman-2.0.0/src/roman.egg-info/0000755000175000017500000000000012256770154015241 5ustar warp10warp10roman-2.0.0/src/roman.egg-info/SOURCES.txt0000664000175000017500000000037412112625712017121 0ustar warp10warp10CHANGES.txt MANIFEST.in bootstrap.py buildout.cfg setup.py tox.ini src/roman.py src/tests.py src/roman.egg-info/PKG-INFO src/roman.egg-info/SOURCES.txt src/roman.egg-info/dependency_links.txt src/roman.egg-info/top_level.txt src/roman.egg-info/zip-saferoman-2.0.0/src/roman.egg-info/PKG-INFO0000664000175000017500000000244012112625712016326 0ustar warp10warp10Metadata-Version: 1.1 Name: roman Version: 2.0.0 Summary: Integer to Roman numerals converter Home-page: http://pypi.python.org/pypi/roman Author: Mark Pilgrim Author-email: f8dy@diveintopython.org License: Python 2.1.1 Description: ======= CHANGES ======= 2.0.0 (2013-02-25) ------------------ - Added Python 3.3 and PyPy support. - Added tests. 1.4.0 (2009-07-23) ------------------ - Initial PyPI release. Keywords: roman Platform: UNKNOWN Classifier: Development Status :: 5 - Production/Stable Classifier: Intended Audience :: Developers Classifier: Programming Language :: Python 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.3 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: License :: OSI Approved :: Python Software Foundation License Classifier: Programming Language :: Python Classifier: Natural Language :: English Classifier: Operating System :: OS Independent roman-2.0.0/src/roman.egg-info/top_level.txt0000664000175000017500000000000612112625712017757 0ustar warp10warp10roman roman-2.0.0/src/roman.egg-info/zip-safe0000664000175000017500000000000112112625710016657 0ustar warp10warp10 roman-2.0.0/src/roman.egg-info/dependency_links.txt0000664000175000017500000000000112112625712021277 0ustar warp10warp10 roman-2.0.0/src/roman.py0000664000175000017500000000521212112625710014107 0ustar warp10warp10"""Convert to and from Roman numerals""" __author__ = "Mark Pilgrim (f8dy@diveintopython.org)" __version__ = "1.4" __date__ = "8 August 2001" __copyright__ = """Copyright (c) 2001 Mark Pilgrim This program is part of "Dive Into Python", a free Python tutorial for experienced programmers. Visit http://diveintopython.org/ for the latest version. This program is free software; you can redistribute it and/or modify it under the terms of the Python 2.1.1 license, available at http://www.python.org/2.1.1/license.html """ import re #Define exceptions class RomanError(Exception): pass class OutOfRangeError(RomanError): pass class NotIntegerError(RomanError): pass class InvalidRomanNumeralError(RomanError): pass #Define digit mapping romanNumeralMap = (('M', 1000), ('CM', 900), ('D', 500), ('CD', 400), ('C', 100), ('XC', 90), ('L', 50), ('XL', 40), ('X', 10), ('IX', 9), ('V', 5), ('IV', 4), ('I', 1)) def toRoman(n): """convert integer to Roman numeral""" if not isinstance(n, int): raise NotIntegerError("decimals can not be converted") if not (0 < n < 5000): raise OutOfRangeError("number out of range (must be 1..4999)") result = "" for numeral, integer in romanNumeralMap: while n >= integer: result += numeral n -= integer return result #Define pattern to detect valid Roman numerals romanNumeralPattern = re.compile(""" ^ # beginning of string M{0,4} # thousands - 0 to 4 M's (CM|CD|D?C{0,3}) # hundreds - 900 (CM), 400 (CD), 0-300 (0 to 3 C's), # or 500-800 (D, followed by 0 to 3 C's) (XC|XL|L?X{0,3}) # tens - 90 (XC), 40 (XL), 0-30 (0 to 3 X's), # or 50-80 (L, followed by 0 to 3 X's) (IX|IV|V?I{0,3}) # ones - 9 (IX), 4 (IV), 0-3 (0 to 3 I's), # or 5-8 (V, followed by 0 to 3 I's) $ # end of string """ ,re.VERBOSE) def fromRoman(s): """convert Roman numeral to integer""" if not s: raise InvalidRomanNumeralError('Input can not be blank') if not romanNumeralPattern.search(s): raise InvalidRomanNumeralError('Invalid Roman numeral: %s' % s) result = 0 index = 0 for numeral, integer in romanNumeralMap: while s[index:index+len(numeral)] == numeral: result += integer index += len(numeral) return result roman-2.0.0/bootstrap.py0000664000175000017500000001311112112625710014216 0ustar warp10warp10############################################################################## # # Copyright (c) 2006 Zope Foundation and Contributors. # All Rights Reserved. # # This software is subject to the provisions of the Zope Public License, # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # FOR A PARTICULAR PURPOSE. # ############################################################################## """Bootstrap a buildout-based project Simply run this script in a directory containing a buildout.cfg. The script accepts buildout command-line options, so you can use the -c option to specify an alternate configuration file. """ import os, shutil, sys, tempfile from optparse import OptionParser tmpeggs = tempfile.mkdtemp() usage = '''\ [DESIRED PYTHON FOR BUILDOUT] bootstrap.py [options] Bootstraps a buildout-based project. Simply run this script in a directory containing a buildout.cfg, using the Python that you want bin/buildout to use. Note that by using --setup-source and --download-base to point to local resources, you can keep this script from going over the network. ''' parser = OptionParser(usage=usage) parser.add_option("-v", "--version", help="use a specific zc.buildout version") parser.add_option("-t", "--accept-buildout-test-releases", dest='accept_buildout_test_releases', action="store_true", default=False, help=("Normally, if you do not specify a --version, the " "bootstrap script and buildout gets the newest " "*final* versions of zc.buildout and its recipes and " "extensions for you. If you use this flag, " "bootstrap and buildout will get the newest releases " "even if they are alphas or betas.")) parser.add_option("-c", "--config-file", help=("Specify the path to the buildout configuration " "file to be used.")) parser.add_option("-f", "--find-links", help=("Specify a URL to search for buildout releases")) options, args = parser.parse_args() ###################################################################### # load/install distribute to_reload = False try: import pkg_resources, setuptools if not hasattr(pkg_resources, '_distribute'): to_reload = True raise ImportError except ImportError: ez = {} try: from urllib.request import urlopen except ImportError: from urllib2 import urlopen exec(urlopen('http://python-distribute.org/distribute_setup.py').read(), ez) setup_args = dict(to_dir=tmpeggs, download_delay=0, no_fake=True) ez['use_setuptools'](**setup_args) if to_reload: reload(pkg_resources) import pkg_resources # This does not (always?) update the default working set. We will # do it. for path in sys.path: if path not in pkg_resources.working_set.entries: pkg_resources.working_set.add_entry(path) ###################################################################### # Install buildout ws = pkg_resources.working_set cmd = [sys.executable, '-c', 'from setuptools.command.easy_install import main; main()', '-mZqNxd', tmpeggs] find_links = os.environ.get( 'bootstrap-testing-find-links', options.find_links or ('http://downloads.buildout.org/' if options.accept_buildout_test_releases else None) ) if find_links: cmd.extend(['-f', find_links]) distribute_path = ws.find( pkg_resources.Requirement.parse('distribute')).location requirement = 'zc.buildout' version = options.version if version is None and not options.accept_buildout_test_releases: # Figure out the most recent final version of zc.buildout. import setuptools.package_index _final_parts = '*final-', '*final' def _final_version(parsed_version): for part in parsed_version: if (part[:1] == '*') and (part not in _final_parts): return False return True index = setuptools.package_index.PackageIndex( search_path=[distribute_path]) if find_links: index.add_find_links((find_links,)) req = pkg_resources.Requirement.parse(requirement) if index.obtain(req) is not None: best = [] bestv = None for dist in index[req.project_name]: distv = dist.parsed_version if _final_version(distv): if bestv is None or distv > bestv: best = [dist] bestv = distv elif distv == bestv: best.append(dist) if best: best.sort() version = best[-1].version if version: requirement = '=='.join((requirement, version)) cmd.append(requirement) import subprocess if subprocess.call(cmd, env=dict(os.environ, PYTHONPATH=distribute_path)) != 0: raise Exception( "Failed to execute command:\n%s", repr(cmd)[1:-1]) ###################################################################### # Import and run buildout ws.add_entry(tmpeggs) ws.require(requirement) import zc.buildout.buildout if not [a for a in args if '=' not in a]: args.append('bootstrap') # if -c was provided, we push it back into args for buildout' main function if options.config_file is not None: args[0:0] = ['-c', options.config_file] zc.buildout.buildout.main(args) shutil.rmtree(tmpeggs) roman-2.0.0/PKG-INFO0000664000175000017500000000244012112625716012735 0ustar warp10warp10Metadata-Version: 1.1 Name: roman Version: 2.0.0 Summary: Integer to Roman numerals converter Home-page: http://pypi.python.org/pypi/roman Author: Mark Pilgrim Author-email: f8dy@diveintopython.org License: Python 2.1.1 Description: ======= CHANGES ======= 2.0.0 (2013-02-25) ------------------ - Added Python 3.3 and PyPy support. - Added tests. 1.4.0 (2009-07-23) ------------------ - Initial PyPI release. Keywords: roman Platform: UNKNOWN Classifier: Development Status :: 5 - Production/Stable Classifier: Intended Audience :: Developers Classifier: Programming Language :: Python 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.3 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: License :: OSI Approved :: Python Software Foundation License Classifier: Programming Language :: Python Classifier: Natural Language :: English Classifier: Operating System :: OS Independent roman-2.0.0/tox.ini0000664000175000017500000000014212112625710013142 0ustar warp10warp10[tox] envlist = py26,py27,py33,pypy [testenv] commands = python setup.py test -q deps = roman-2.0.0/CHANGES.txt0000664000175000017500000000026612112625710013447 0ustar warp10warp10======= CHANGES ======= 2.0.0 (2013-02-25) ------------------ - Added Python 3.3 and PyPy support. - Added tests. 1.4.0 (2009-07-23) ------------------ - Initial PyPI release. roman-2.0.0/setup.cfg0000664000175000017500000000007312112625716013461 0ustar warp10warp10[egg_info] tag_build = tag_date = 0 tag_svn_revision = 0 roman-2.0.0/MANIFEST.in0000664000175000017500000000017512112625710013373 0ustar warp10warp10include *.rst include *.txt include *.py include buildout.cfg include tox.ini recursive-include src * global-exclude *.pyc