# Path: devicecloud/util.py
# def isoformat(dt):
#     """Return an ISO-8601 formatted string from the provided datetime object"""
#     if not isinstance(dt, datetime.datetime):
#         raise TypeError("Must provide datetime.datetime object to isoformat")
# 
#     if dt.tzinfo is None:
#         raise ValueError("naive datetime objects are not allowed beyond the library boundaries")
# 
#     return dt.isoformat().replace("+00:00", "Z")  # nicer to look at
# 
# def to_none_or_dt(input):
#     """Convert ``input`` to either None or a datetime object
# 
#     If the input is None, None will be returned.
#     If the input is a datetime object, it will be converted to a datetime
#     object with UTC timezone info.  If the datetime object is naive, then
#     this method will assume the object is specified according to UTC and
#     not local or some other timezone.
#     If the input to the function is a string, this method will attempt to
#     parse the input as an ISO-8601 formatted string.
# 
#     :param input: Input data (expected to be either str, None, or datetime object)
#     :return: datetime object from input or None if already None
#     :rtype: datetime or None
# 
#     """
#     if input is None:
#         return input
#     elif isinstance(input, datetime.datetime):
#         arrow_dt = arrow.Arrow.fromdatetime(input, input.tzinfo or 'utc')
#         return arrow_dt.to('utc').datetime
#     if isinstance(input, six.string_types):
#         # try to convert from ISO8601
#         return iso8601_to_dt(input)
#     else:
#         raise TypeError("Not a string, NoneType, or datetime object")


import datetime
from devicecloud.util import isoformat, to_none_or_dt
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (c) 2015-2018 Digi International Inc.

"""Module with functionality for building queries against cloud resources

This functionality is somewhat poorly documented in Device Cloud documentation
in the `Compound Queries <http://ftp1.digi.com/support/documentation/html/90002008/90002008_P/Default.htm#ProgrammingTopics/ResourceConventions.htm#CompQueries%3FTocPath%3DDevice%20Cloud%20Programming%20Guide%7CResource%20Conventions%7C_____3>`_
section.

"""



def _quoted(value):
    """Return a single-quoted and escaped (percent-encoded) version of value

    This function will also perform transforms of known data types to a representation
    that will be handled by Device Cloud.  For instance, datetime objects will be
    converted to ISO8601.

    """
    if isinstance(value, datetime.datetime):

# Path: devicecloud/util.py
# def isoformat(dt):
#     """Return an ISO-8601 formatted string from the provided datetime object"""
#     if not isinstance(dt, datetime.datetime):
#         raise TypeError("Must provide datetime.datetime object to isoformat")
# 
#     if dt.tzinfo is None:
#         raise ValueError("naive datetime objects are not allowed beyond the library boundaries")
# 
#     return dt.isoformat().replace("+00:00", "Z")  # nicer to look at
# 
# def to_none_or_dt(input):
#     """Convert ``input`` to either None or a datetime object
# 
#     If the input is None, None will be returned.
#     If the input is a datetime object, it will be converted to a datetime
#     object with UTC timezone info.  If the datetime object is naive, then
#     this method will assume the object is specified according to UTC and
#     not local or some other timezone.
#     If the input to the function is a string, this method will attempt to
#     parse the input as an ISO-8601 formatted string.
# 
#     :param input: Input data (expected to be either str, None, or datetime object)
#     :return: datetime object from input or None if already None
#     :rtype: datetime or None
# 
#     """
#     if input is None:
#         return input
#     elif isinstance(input, datetime.datetime):
#         arrow_dt = arrow.Arrow.fromdatetime(input, input.tzinfo or 'utc')
#         return arrow_dt.to('utc').datetime
#     if isinstance(input, six.string_types):
#         # try to convert from ISO8601
#         return iso8601_to_dt(input)
#     else:
#         raise TypeError("Not a string, NoneType, or datetime object")


# Path: devicecloud/conditions.py
import datetime
from devicecloud.util import isoformat, to_none_or_dt

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (c) 2015-2018 Digi International Inc.

"""Module with functionality for building queries against cloud resources

This functionality is somewhat poorly documented in Device Cloud documentation
in the `Compound Queries <http://ftp1.digi.com/support/documentation/html/90002008/90002008_P/Default.htm#ProgrammingTopics/ResourceConventions.htm#CompQueries%3FTocPath%3DDevice%20Cloud%20Programming%20Guide%7CResource%20Conventions%7C_____3>`_
section.

"""



def _quoted(value):
    """Return a single-quoted and escaped (percent-encoded) version of value

    This function will also perform transforms of known data types to a representation
    that will be handled by Device Cloud.  For instance, datetime objects will be
    converted to ISO8601.

    """
    if isinstance(value, datetime.datetime):

        value = isoformat(to_none_or_dt(value))