~ubuntu-branches/ubuntu/trusty/python-happybase/trusty

« back to all changes in this revision

Viewing changes to happybase/util.py

  • Committer: Package Import Robot
  • Author(s): Thomas Goirand
  • Date: 2013-05-30 13:56:42 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20130530135642-tveld2y1dbkhmuv3
Tags: 0.6-1
* New upstream release (Closes: #712971).
* Ran wrap-and-sort.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 
7
7
import re
8
8
 
9
 
__all__ = ['thrift_attrs', 'thrift_type_to_dict']
10
 
 
11
9
CAPITALS = re.compile('([A-Z])')
12
10
 
13
11
 
14
12
def camel_case_to_pep8(name):
15
 
    """Converts a camel cased name to PEP8 style."""
 
13
    """Convert a camel cased name to PEP8 style."""
16
14
    converted = CAPITALS.sub(lambda m: '_' + m.groups()[0].lower(), name)
17
15
    if converted[0] == '_':
18
16
        return converted[1:]
21
19
 
22
20
 
23
21
def pep8_to_camel_case(name, initial=False):
24
 
    """Converts a PEP8 style name to camel case."""
 
22
    """Convert a PEP8 style name to camel case."""
25
23
    chunks = name.split('_')
26
24
    converted = [s[0].upper() + s[1:].lower() for s in chunks]
27
25
    if initial:
31
29
 
32
30
 
33
31
def thrift_attrs(obj_or_cls):
34
 
    """Obtains Thrift data type attribute names for an instance or class."""
 
32
    """Obtain Thrift data type attribute names for an instance or class."""
35
33
    return [v[2] for v in obj_or_cls.thrift_spec[1:]]
36
34
 
37
35
 
38
36
def thrift_type_to_dict(obj):
39
 
    """Converts a Thrift data type to a regular dictionary."""
 
37
    """Convert a Thrift data type to a regular dictionary."""
40
38
    return dict((camel_case_to_pep8(attr), getattr(obj, attr))
41
39
                for attr in thrift_attrs(obj))
42
40
 
43
41
 
44
42
def str_increment(s):
45
 
    """
46
 
    Returns the shortest string that sorts after the given string when compared
47
 
    using regular string comparison semantics.
 
43
    """Increment and truncate a byte string (for sorting purposes)
 
44
 
 
45
    This functions returns the shortest string that sorts after the given
 
46
    string when compared using regular string comparison semantics.
48
47
 
49
48
    This function increments the last byte that is smaller than ``0xFF``, and
50
49
    drops everything after it. If the string only contains ``0xFF`` bytes,