コード例 #1
0
ファイル: util.py プロジェクト: warmunger/exchangelib
BOM = b'\xef\xbb\xbf'
BOM_LEN = len(BOM)

# XML namespaces
SOAPNS = 'http://schemas.xmlsoap.org/soap/envelope/'
MNS = 'http://schemas.microsoft.com/exchange/services/2006/messages'
TNS = 'http://schemas.microsoft.com/exchange/services/2006/types'
ENS = 'http://schemas.microsoft.com/exchange/services/2006/errors'

ns_translation = {
    's': SOAPNS,
    't': TNS,
    'm': MNS,
}
for k, v in ns_translation.items():
    _etree.register_namespace(k, v)


def is_iterable(value, generators_allowed=False):
    """
    Checks if value is a list-like object. Don't match generators and generator-like objects here by default, because
    callers don't necessarily guarantee that they only iterate the value once. Take care to not match string types and
    bytes.

    :param value: any type of object
    :param generators_allowed: if True, generators will be treated as iterable
    :return: True or False
    """
    if generators_allowed:
        if not isinstance(value, string_types +
                          (bytes, )) and hasattr(value, '__iter__'):
コード例 #2
0
# XML namespaces
SOAPNS = 'http://schemas.xmlsoap.org/soap/envelope/'
MNS = 'http://schemas.microsoft.com/exchange/services/2006/messages'
TNS = 'http://schemas.microsoft.com/exchange/services/2006/types'
ENS = 'http://schemas.microsoft.com/exchange/services/2006/errors'
AUTODISCOVER_BASE_NS = 'http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006'
AUTODISCOVER_REQUEST_NS = 'http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006'
AUTODISCOVER_RESPONSE_NS = 'http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a'

ns_translation = OrderedDict([
    ('s', SOAPNS),
    ('m', MNS),
    ('t', TNS),
])
for item in ns_translation.items():
    _etree.register_namespace(*item)


def is_iterable(value, generators_allowed=False):
    """Checks if value is a list-like object. Don't match generators and generator-like objects here by default, because
    callers don't necessarily guarantee that they only iterate the value once. Take care to not match string types and
    bytes.

    :param value: any type of object
    :param generators_allowed: if True, generators will be treated as iterable
    :return: True or False
    """
    if generators_allowed:
        if not isinstance(value, (bytes, str)) and hasattr(value, '__iter__'):
            return True
    else:
コード例 #3
0
ファイル: util.py プロジェクト: ecederstrand/exchangelib
# Regex of UTF-8 control characters that are illegal in XML 1.0 (and XML 1.1)
_ILLEGAL_XML_CHARS_RE = re.compile('[\x00-\x08\x0b\x0c\x0e-\x1F\uD800-\uDFFF\uFFFE\uFFFF]')

# XML namespaces
SOAPNS = 'http://schemas.xmlsoap.org/soap/envelope/'
MNS = 'http://schemas.microsoft.com/exchange/services/2006/messages'
TNS = 'http://schemas.microsoft.com/exchange/services/2006/types'
ENS = 'http://schemas.microsoft.com/exchange/services/2006/errors'

ns_translation = {
    's': SOAPNS,
    't': TNS,
    'm': MNS,
}
for item in ns_translation.items():
    _etree.register_namespace(*item)


def is_iterable(value, generators_allowed=False):
    """
    Checks if value is a list-like object. Don't match generators and generator-like objects here by default, because
    callers don't necessarily guarantee that they only iterate the value once. Take care to not match string types and
    bytes.

    :param value: any type of object
    :param generators_allowed: if True, generators will be treated as iterable
    :return: True or False
    """
    if generators_allowed:
        if not isinstance(value, string_types + (bytes,)) and hasattr(value, '__iter__'):
            return True