1
# Copyright (c) 2012-2013 Mitch Garnaat http://garnaat.org/
2
# Copyright 2012-2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
#
4
# Licensed under the Apache License, Version 2.0 (the "License"). You
5
# may not use this file except in compliance with the License. A copy of
6
# the License is located at
7
#
8
# http://aws.amazon.com/apache2.0/
9
#
10
# or in the "license" file accompanying this file. This file is
11
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
12
# ANY KIND, either express or implied. See the License for the specific
13
# language governing permissions and limitations under the License.
14

15 6
import os
16 6
import re
17 6
import logging
18

19 6
__version__ = '1.19.5'
20

21

22 6
class NullHandler(logging.Handler):
23 6
    def emit(self, record):
24 6
        pass
25

26
# Configure default logger to do nothing
27 6
log = logging.getLogger('botocore')
28 6
log.addHandler(NullHandler())
29

30

31 6
_first_cap_regex = re.compile('(.)([A-Z][a-z]+)')
32 6
_end_cap_regex = re.compile('([a-z0-9])([A-Z])')
33
# The regex below handles the special case where some acryonym
34
# name is pluralized, e.g GatewayARNs, ListWebACLs, SomeCNAMEs.
35 6
_special_case_transform = re.compile('[A-Z]{3,}s$')
36
# Prepopulate the cache with special cases that don't match
37
# our regular transformation.
38 6
_xform_cache = {
39
    ('CreateCachediSCSIVolume', '_'): 'create_cached_iscsi_volume',
40
    ('CreateCachediSCSIVolume', '-'): 'create-cached-iscsi-volume',
41
    ('DescribeCachediSCSIVolumes', '_'): 'describe_cached_iscsi_volumes',
42
    ('DescribeCachediSCSIVolumes', '-'): 'describe-cached-iscsi-volumes',
43
    ('DescribeStorediSCSIVolumes', '_'): 'describe_stored_iscsi_volumes',
44
    ('DescribeStorediSCSIVolumes', '-'): 'describe-stored-iscsi-volumes',
45
    ('CreateStorediSCSIVolume', '_'): 'create_stored_iscsi_volume',
46
    ('CreateStorediSCSIVolume', '-'): 'create-stored-iscsi-volume',
47
    ('ListHITsForQualificationType', '_'): 'list_hits_for_qualification_type',
48
    ('ListHITsForQualificationType', '-'): 'list-hits-for-qualification-type',
49
}
50
# The items in this dict represent partial renames to apply globally to all
51
# services which might have a matching argument or operation. This way a
52
# common mis-translation can be fixed without having to call out each
53
# individual case.
54 6
ScalarTypes = ('string', 'integer', 'boolean', 'timestamp', 'float', 'double')
55

56 6
BOTOCORE_ROOT = os.path.dirname(os.path.abspath(__file__))
57

58

59
# Used to specify anonymous (unsigned) request signature
60 6
class UNSIGNED(object):
61 6
    def __copy__(self):
62 6
        return self
63

64 6
    def __deepcopy__(self, memodict):
65 6
        return self
66

67

68 6
UNSIGNED = UNSIGNED()
69

70

71 6
def xform_name(name, sep='_', _xform_cache=_xform_cache):
72
    """Convert camel case to a "pythonic" name.
73

74
    If the name contains the ``sep`` character, then it is
75
    returned unchanged.
76

77
    """
78 6
    if sep in name:
79
        # If the sep is in the name, assume that it's already
80
        # transformed and return the string unchanged.
81 6
        return name
82 6
    key = (name, sep)
83 6
    if key not in _xform_cache:
84 6
        if _special_case_transform.search(name) is not None:
85 6
            is_special = _special_case_transform.search(name)
86 6
            matched = is_special.group()
87
            # Replace something like ARNs, ACLs with _arns, _acls.
88 6
            name = name[:-len(matched)] + sep + matched.lower()
89 6
        s1 = _first_cap_regex.sub(r'\1' + sep + r'\2', name)
90 6
        transformed = _end_cap_regex.sub(r'\1' + sep + r'\2', s1).lower()
91 6
        _xform_cache[key] = transformed
92 6
    return _xform_cache[key]

Read our documentation on viewing source code .

Loading