{ "info": { "author": "makoto kuwata", "author_email": "kwa@kuwata-lab.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Console", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "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", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Utilities" ], "description": "=====\nbenry\n=====\n\n$Release: 0.1.0 $\n\n\nUseful tools for Python.\n\n\nbenry.rexp\n==========\n\n\nrx()\n----\n\n``benry.rexp.rx()`` is a short cut to ``re.compile()``. ::\n\n from benry.rexp import rx\n \n ## comping -- same as re.compile(r'pat') or re.compile(r'pat', rx.I|rx.S)\n regexp = rx(r'pat')\n regexp = rx(r'pat', rx.I|rx.S)\n \n ## matching -- same as re.compile(r'pat').search(string)\n m = rx(r'pat').search(string)\n \n ## replacing -- same as re.compile(r'pat').sub('repl', string, count=1)\n rx(r'pat').sub('repl', string, count=1)\n\nYou don't need to use ``re.xxxx()`` functions because ``rx().xxxx()`` does same things,\nand has more features. ::\n\n ## For example you can't specify starting/ending position with re.match().\n re.match(r'pat', string, re.I)\n\n ## But you can specify them with rx().match().\n rx(r'pat', re.I).match(string, start_pos, end_pos)\n\n\nrx.compile()\n------------\n\n``rx.compile()`` (or ``benry.rexp.compile()``) is similar to ``re.compile()``,\nbut the former doesn't cache compiled pattern while the latter caches it.\n\nThis is very useful when there are a lot of regexp pattern and they are\nno need to cache into library. ::\n\n mappings = [\n (r'^/posts$', 'app.PostsPage'),\n (r'^/posts/new$', 'app.PostCreatePage'),\n (r'^/posts/(?P\\d+)$', 'app.PostPage'),\n (r'^/posts/(?P\\d+)/edit$', 'app.PostUpdatePage'),\n (r'^/posts/(?P\\d+)/comments$', 'app.PostCommentsPage'),\n ]\n\n ## no need to cache patterns, so calls rx.compile() instead of re.compile()\n from benry.rexp import rx # or: import compile\n compiled_mappings = [ (rx.compile(pat), cls) for pat, cls in mappings ]\n\n\nrx.matching()\n-------------\n\n``rx.matching()`` (or ``benry.rexp.matching()``) is a utility class to help you\nwhen matching to a lot of patterns.\n\nWithout ``rx.matching()``::\n\n import re\n\n m = re.match(r'^(\\d\\d\\d\\d)-(\\d\\d)-(\\d\\d)$', string)\n if m:\n Y, M, D = m.groups()\n else:\n m = re.match(r'^(\\d\\d)/(\\d\\d)/(\\d\\d\\d\\d)$', string)\n if m:\n M, D, Y = m.groups()\n else:\n m = re.match(r'^(\\d\\d\\d\\d)/(\\d\\d)/(\\d\\d)$', string)\n if m:\n Y, M, D = m.groups()\n\nWith ``rx.matching()``::\n\n from benry.rexp import rx\n\n m = rx.matching(string)\n if m.match(r'^(\\d\\d\\d\\d)-(\\d\\d)-(\\d\\d)$'):\n Y, M, D = m.groups() # or Y, M, D = m\n elif m.match(r'^(\\d\\d)/(\\d\\d)/(\\d\\d\\d\\d)$'):\n M, D, Y = m.groups() # or M, D, Y = m\n elif m.match(r'^(\\d\\d\\d\\d)/(\\d\\d)/(\\d\\d)$'):\n Y, M, D = m.groups() # or Y, M, D = m\n\nYou can get ``SRE_Match`` object by ``m.matched``. ::\n\n m = rx.matching(string)\n if m.match(r'pat'):\n print(m.matched.pos)\n print(m.matched.endpos)\n\n\ntype\n----\n\n``rx.type`` represents class of regular expression. ::\n\n import re\n from benry.rexp import rx\n\n assert rx.type is type(re.compile('x'))\n\n\n\nbenry.date_time\n===============\n\n\nclass UTCDateTime\n-----------------\n\n``UTCDdateTime`` is a subclass of ``datetime.datetime`` representing UTC offset. ::\n\n from benry.date_time import UTCDateTime\n\n print(UTCDateTime.offset_minutes) #=> 0\n print(UTCDateTime.offset_timedelta) #=> timedelta(seconds=0)\n print(UTCDateTime.is_utc) #=> True\n print(UTCDateTime.is_local) #=> False\n\n ## almost same as datetime.utcnow(), except returning UTCDateTime object.\n utc_dt = UTCDateTime.now()\n\n print(utc_dt.to_utc()) # returns self.\n print(utc_dt.to_local()) # returns LocalDateTime object.\n\n\nclass LocalDateTime\n-------------------\n\n``UTCDdateTime`` is a subclass of ``datetime.datetime`` representing local time.\nThis class calculates offset between local time and UTC time. ::\n\n from benry.date_time import LocalDateTime\n\n print(LocalDateTime.offset_minutes) #=> 9*60 (ex: JST timezone)\n print(LocalDateTime.offset_timedelta) #=> timedelta(seconds=9*60*60)\n print(LocalDateTime.is_utc) #=> False\n print(LocalDateTime.is_local) #=> True\n\n ## almost same as datetime.now(), except returning LocalDateTime object.\n local_dt = LocalDateTime.now()\n\n print(local_dt.to_utc()) # returns UTCDateTime object.\n print(local_dt.to_local()) # returns self.", "description_content_type": null, "docs_url": null, "download_url": "https://pypi.python.org/packages/source/b/benry/benry-0.1.0.tar.gz", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://pypi.python.org/pypi/benry", "keywords": null, "license": "MIT License", "maintainer": null, "maintainer_email": null, "name": "benry", "package_url": "https://pypi.org/project/benry/", "platform": "any", "project_url": "https://pypi.org/project/benry/", "project_urls": { "Download": "https://pypi.python.org/packages/source/b/benry/benry-0.1.0.tar.gz", "Homepage": "https://pypi.python.org/pypi/benry" }, "release_url": "https://pypi.org/project/benry/0.1.0/", "requires_dist": null, "requires_python": null, "summary": "Experimental utilities for Python", "version": "0.1.0" }, "last_serial": 1224832, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "3482d409888f2b3c6c5a1b4dbf1f8548", "sha256": "a52d0049127a2a4aa65c9532ee3d67e19535cc120edf0bb1c93e7195f95f2c0b" }, "downloads": -1, "filename": "benry-0.1.0.tar.gz", "has_sig": false, "md5_digest": "3482d409888f2b3c6c5a1b4dbf1f8548", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8755, "upload_time": "2014-09-15T12:22:09", "url": "https://files.pythonhosted.org/packages/bb/7b/8db3f4057471131572aa45b2f3f32c79bd096eba2369c3f0fa9e665eaf52/benry-0.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "3482d409888f2b3c6c5a1b4dbf1f8548", "sha256": "a52d0049127a2a4aa65c9532ee3d67e19535cc120edf0bb1c93e7195f95f2c0b" }, "downloads": -1, "filename": "benry-0.1.0.tar.gz", "has_sig": false, "md5_digest": "3482d409888f2b3c6c5a1b4dbf1f8548", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8755, "upload_time": "2014-09-15T12:22:09", "url": "https://files.pythonhosted.org/packages/bb/7b/8db3f4057471131572aa45b2f3f32c79bd096eba2369c3f0fa9e665eaf52/benry-0.1.0.tar.gz" } ] }