This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

$Release: 0.1.0 $

Useful tools for Python.



benry.rexp.rx() is a short cut to re.compile().

from benry.rexp import rx

## comping -- same as re.compile(r'pat') or re.compile(r'pat', rx.I|rx.S)
regexp = rx(r'pat')
regexp = rx(r'pat', rx.I|rx.S)

## matching -- same as re.compile(r'pat').search(string)
m = rx(r'pat').search(string)

## replacing -- same as re.compile(r'pat').sub('repl', string, count=1)
rx(r'pat').sub('repl', string, count=1)

You don’t need to use re.xxxx() functions because rx().xxxx() does same things, and has more features.

## For example you can't specify starting/ending position with re.match().
re.match(r'pat', string, re.I)

## But you can specify them with rx().match().
rx(r'pat', re.I).match(string, start_pos, end_pos)


rx.compile() (or benry.rexp.compile()) is similar to re.compile(), but the former doesn’t cache compiled pattern while the latter caches it.

This is very useful when there are a lot of regexp pattern and they are no need to cache into library.

mappings = [
    (r'^/posts$',                      'app.PostsPage'),
    (r'^/posts/new$',                  'app.PostCreatePage'),
    (r'^/posts/(?P<id>\d+)$',          'app.PostPage'),
    (r'^/posts/(?P<id>\d+)/edit$',     'app.PostUpdatePage'),
    (r'^/posts/(?P<id>\d+)/comments$', 'app.PostCommentsPage'),

## no need to cache patterns, so calls rx.compile() instead of re.compile()
from benry.rexp import rx   # or: import compile
compiled_mappings = [ (rx.compile(pat), cls) for pat, cls in mappings ]


rx.matching() (or benry.rexp.matching()) is a utility class to help you when matching to a lot of patterns.

Without rx.matching():

import re

m = re.match(r'^(\d\d\d\d)-(\d\d)-(\d\d)$', string)
if m:
    Y, M, D = m.groups()
    m = re.match(r'^(\d\d)/(\d\d)/(\d\d\d\d)$', string)
    if m:
        M, D, Y = m.groups()
        m = re.match(r'^(\d\d\d\d)/(\d\d)/(\d\d)$', string)
        if m:
            Y, M, D = m.groups()

With rx.matching():

from benry.rexp import rx

m = rx.matching(string)
if   m.match(r'^(\d\d\d\d)-(\d\d)-(\d\d)$'):
    Y, M, D = m.groups()     # or Y, M, D = m
elif m.match(r'^(\d\d)/(\d\d)/(\d\d\d\d)$'):
    M, D, Y = m.groups()     # or M, D, Y = m
elif m.match(r'^(\d\d\d\d)/(\d\d)/(\d\d)$'):
    Y, M, D = m.groups()     # or Y, M, D = m

You can get SRE_Match object by m.matched.

m = rx.matching(string)
if m.match(r'pat'):


rx.type represents class of regular expression.

import re
from benry.rexp import rx

assert rx.type is type(re.compile('x'))


class UTCDateTime

UTCDdateTime is a subclass of datetime.datetime representing UTC offset.

from benry.date_time import UTCDateTime

print(UTCDateTime.offset_minutes)      #=> 0
print(UTCDateTime.offset_timedelta)    #=> timedelta(seconds=0)
print(UTCDateTime.is_utc)              #=> True
print(UTCDateTime.is_local)            #=> False

## almost same as datetime.utcnow(), except returning UTCDateTime object.
utc_dt =

print(utc_dt.to_utc())                 # returns self.
print(utc_dt.to_local())               # returns LocalDateTime object.

class LocalDateTime

UTCDdateTime is a subclass of datetime.datetime representing local time. This class calculates offset between local time and UTC time.

from benry.date_time import LocalDateTime

print(LocalDateTime.offset_minutes)    #=> 9*60  (ex: JST timezone)
print(LocalDateTime.offset_timedelta)  #=> timedelta(seconds=9*60*60)
print(LocalDateTime.is_utc)            #=> False
print(LocalDateTime.is_local)          #=> True

## almost same as, except returning LocalDateTime object.
local_dt =

print(local_dt.to_utc())               # returns UTCDateTime object.
print(local_dt.to_local())             # returns self.
Release History

Release History


This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
benry-0.1.0.tar.gz (8.8 kB) Copy SHA256 Checksum SHA256 Source Sep 15, 2014

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting