{ "info": { "author": "Hai Vu", "author_email": "haivu2004@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Environment :: Console", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "argparse_actions\n================\n\nThis module implements some reusable custom actions to use with the argparse module.\n\n\nExamples\n--------\n\nThe following example, taken from *samples/folder\\_actions.py* demonstrates the use of a custom action to verify the existence of a folder, specified from the command line::\n\n\timport argparse\n\timport argparse_actions\n\n\tif __name__ == '__main__':\n\t parser = argparse.ArgumentParser(description='Custom Actions')\n\t parser.add_argument('directory', \n\t\t \taction=argparse_actions.FolderExistsAction)\n \n\t try:\n\t args = parser.parse_args()\n\t print 'Directory exists: {0}'.format(args.directory)\n\t except argparse_actions.NonFolderError as e:\n\t print 'Directory does not exist'\n\t print e\n\nIn the next example from *samples/proper\\_ip.py*, we use the *ProperIpFormatAction* custom action to verify if an IP address from command line is properly formatted::\n\n\n\timport argparse\n\timport argparse_actions\n\t\n\tif __name__ == '__main__':\n\t parser = argparse.ArgumentParser(description='Custom Actions')\n\t parser.add_argument('ip', \n\t\t\t action=argparse_actions.ProperIpFormatAction)\n\t \n\t try:\n\t args = parser.parse_args()\n\t print 'IP is properly formatted: {0}'.format(args.ip)\n\t except argparse_actions.InvalidIp as e:\n\t print 'IP is invalid: {0}'.format(e.ip)\n\t # This will display similar output:\n\t # print e \n\nExtending the Custom Actions\n----------------------------\n\nIf you find a custom action that almost do what you want, you can\n\n1. Write your own from scratch\n2. Submit an enhancement request\n3. Extend the existing custom action\n\nI am not commenting on option 1--it is your choice. For option 2, I will be gladly to accept any reasonable request, but sometimes life happens and I might not response quickly enough. That leaves you with the third option of extending the custom action yourself. Don't worry, it is not that hard. In the next example, I will take the *ProperIpFormatAction* custom action and extend it to include 'localhost' as one of the proper IP format::\n\n\n\timport argparse\n\timport argparse_actions\n\t\n\tclass IpAndLocalhostAction(argparse_actions.ProperIpFormatAction):\n\t def __call__(self, parser, namespace, values, option_string=None):\n\t # Do our check: allow for 'localhost'\n\t if values == 'localhost':\n\t setattr(namespace, self.dest, values)\n\t else:\n\t # Super class to perform its check\n\t parent = super(IpAndLocalhostAction, self)\n\t parent.__call__(parser, namespace, values, option_string)\n\t\n\tif __name__ == '__main__':\n\t parser = argparse.ArgumentParser(description='Custom Actions')\n\t parser.add_argument('ip', action=IpAndLocalhostAction)\n\t \n\t try:\n\t args = parser.parse_args()\n\t print 'IP is valid: {0}'.format(args.ip)\n\t except argparse_actions.InvalidIp as e:\n\t print e \n\nDiscussion: \n\n* The first step is to create a new class (*IpAndLocalhostAction*), based on an existing custom action (*argparse_actions.ProperIpFormatAction*, which is really a class itself)\n* Define the function *\\_\\_call\\_\\_* to override the base custom action with your own logic.\n\n\nMore Ideas\n----------\n\nHere are a few ideas I have in mind, which I might implement:\n\n* Extend *ProperIpFormatAction* to determine if and IP...\n\t- Is reachable\n\t- Provides some services such as HTTP or FTP\n\t- Belongs to a particular list, such as the banned IP list\n* Extend *FolderExistsAction* to determine if the folder is...\n\t- Writable\n\t- Empty\n\t- A symbolic link", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://pypi.python.org/pypi/argparse_actions/", "keywords": null, "license": "LICENSE.txt", "maintainer": null, "maintainer_email": null, "name": "argparse_actions", "package_url": "https://pypi.org/project/argparse_actions/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/argparse_actions/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://pypi.python.org/pypi/argparse_actions/" }, "release_url": "https://pypi.org/project/argparse_actions/0.4.4/", "requires_dist": null, "requires_python": null, "summary": "Custom actions for argparse package", "version": "0.4.4" }, "last_serial": 1784417, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "41e8cfbe373da42876c56407c5c1cf6e", "sha256": "977c99047b0b8587f23d5b909f1bc4ec34ad36e8e78be42cea7c67c02ce2a177" }, "downloads": -1, "filename": "argparse_actions-0.1.0.tar.gz", "has_sig": false, "md5_digest": "41e8cfbe373da42876c56407c5c1cf6e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 840, "upload_time": "2013-05-29T04:22:11", "url": "https://files.pythonhosted.org/packages/1d/25/c458903869353c314b586183641aab18673f13197d804d038aac0bc04c1d/argparse_actions-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "b2fc6247f12d5964d5307d04d4d5990e", "sha256": "d04e1e2dee7244b0ada8479a74a664e05d8c1a09066d43cbb9d75e291da88a30" }, "downloads": -1, "filename": "argparse_actions-0.1.1.tar.gz", "has_sig": false, "md5_digest": "b2fc6247f12d5964d5307d04d4d5990e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1244, "upload_time": "2013-05-29T04:29:04", "url": "https://files.pythonhosted.org/packages/8c/0b/696c775b662918e674056b3447d692ec5ea4db828bd44c795bedd82e46d6/argparse_actions-0.1.1.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "7c5619223fc64c26493b8752282eeafe", "sha256": "c9d5f55e30b4c0427d840946d9aa9d3e02e45736e6258d3e44deef9e03eadf3d" }, "downloads": -1, "filename": "argparse_actions-0.2.0.tar.gz", "has_sig": false, "md5_digest": "7c5619223fc64c26493b8752282eeafe", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1779, "upload_time": "2013-05-30T05:00:11", "url": "https://files.pythonhosted.org/packages/77/c2/9b98702e4e7735abefbfa4d1836074bcdb4c3773db481ef04d17598ef17b/argparse_actions-0.2.0.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "5ff392713d96cea630db82a6517e6333", "sha256": "ab743a6b58602103b6f81578c80b62fa274e889b02af4a93156fd170b69f48df" }, "downloads": -1, "filename": "argparse_actions-0.3.0.tar.gz", "has_sig": false, "md5_digest": "5ff392713d96cea630db82a6517e6333", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2102, "upload_time": "2013-05-31T00:20:04", "url": "https://files.pythonhosted.org/packages/78/6e/d2141245a1aceb434736b51092dca843be2a42abc8d238fb2f8e44b88c25/argparse_actions-0.3.0.tar.gz" } ], "0.4.0": [ { "comment_text": "", "digests": { "md5": "608ede56d79e1db89d773658ca70c498", "sha256": "dd5e86ba7f004c1f07228fa48cd0576577535ea892ab4641416b07afb666eb6a" }, "downloads": -1, "filename": "argparse_actions-0.4.0.tar.gz", "has_sig": false, "md5_digest": "608ede56d79e1db89d773658ca70c498", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3765, "upload_time": "2013-05-31T05:05:47", "url": "https://files.pythonhosted.org/packages/c6/58/3729f142dd1f87e8cf11d753a97ab6033aae1884f929b5ccb5a695559122/argparse_actions-0.4.0.tar.gz" } ], "0.4.1": [ { "comment_text": "", "digests": { "md5": "13ae18b51f041da89653a57303bb387c", "sha256": "8c2f2522c06bdfe0fdcd59d9fa5a9f0e386cd9b45c9d12e5257e74a6f6577028" }, "downloads": -1, "filename": "argparse_actions-0.4.1.tar.gz", "has_sig": false, "md5_digest": "13ae18b51f041da89653a57303bb387c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4384, "upload_time": "2013-06-05T12:59:22", "url": "https://files.pythonhosted.org/packages/70/81/309a32d3d1b980bcc5066cdd6e50603b42fe37fe0b93d50709341a018600/argparse_actions-0.4.1.tar.gz" } ], "0.4.2": [ { "comment_text": "", "digests": { "md5": "6b80e4e2827623008d3fd551b44a4eb7", "sha256": "18128341264ec75f912f744e4181c1c56de35a967fd532168c53f389b03f741e" }, "downloads": -1, "filename": "argparse_actions-0.4.2.tar.gz", "has_sig": false, "md5_digest": "6b80e4e2827623008d3fd551b44a4eb7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5488, "upload_time": "2013-06-07T01:02:26", "url": "https://files.pythonhosted.org/packages/a2/af/a66feb04489b791dfbaf6c91e220623b5a0e6a467536aca33dcb9ac33bcf/argparse_actions-0.4.2.tar.gz" } ], "0.4.3": [ { "comment_text": "", "digests": { "md5": "09505c7d0a571998ab25fd96bb675cf4", "sha256": "f9ee365dfb6651b130cd207cc88a075f5008133c008a497772b1d35bca4de36d" }, "downloads": -1, "filename": "argparse_actions-0.4.3.tar.gz", "has_sig": false, "md5_digest": "09505c7d0a571998ab25fd96bb675cf4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5510, "upload_time": "2013-06-07T02:23:42", "url": "https://files.pythonhosted.org/packages/1e/2f/2e773b407e201ee3a5ccf95df270c15da06f9dd15b67f2df18b36cb73d8b/argparse_actions-0.4.3.tar.gz" } ], "0.4.4": [ { "comment_text": "", "digests": { "md5": "903037c49151f72f2f25f17addeb7f7a", "sha256": "3498869af6ca3ea6720e4f8d80d1665a82f9895a7a1b0295334718dea042968e" }, "downloads": -1, "filename": "argparse_actions-0.4.4.tar.gz", "has_sig": false, "md5_digest": "903037c49151f72f2f25f17addeb7f7a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5540, "upload_time": "2013-06-10T02:33:17", "url": "https://files.pythonhosted.org/packages/f8/e7/eb9caffa8198f783eca2f6e19775a4fdbdba8ce88b39790e0afc4adfef18/argparse_actions-0.4.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "903037c49151f72f2f25f17addeb7f7a", "sha256": "3498869af6ca3ea6720e4f8d80d1665a82f9895a7a1b0295334718dea042968e" }, "downloads": -1, "filename": "argparse_actions-0.4.4.tar.gz", "has_sig": false, "md5_digest": "903037c49151f72f2f25f17addeb7f7a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5540, "upload_time": "2013-06-10T02:33:17", "url": "https://files.pythonhosted.org/packages/f8/e7/eb9caffa8198f783eca2f6e19775a4fdbdba8ce88b39790e0afc4adfef18/argparse_actions-0.4.4.tar.gz" } ] }