# Path: coolamqp/framing/base.py
# BASIC_TYPES = {u'bit': (None, None, "0", None),  # special case
#                u'octet': (1, 'B', "b'\\x00'", 1),
#                u'short': (2, 'H', "b'\\x00\\x00'", 2),
#                u'long': (4, 'I', "b'\\x00\\x00\\x00\\x00'", 4),
#                u'longlong': (
#                    8, 'Q', "b'\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00'", 8),
#                u'timestamp': (
#                    8, 'Q', "b'\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00'", 8),
#                u'table': (None, None, "b'\\x00\\x00\\x00\\x00'", 4),
#                # special case
#                u'longstr': (None, None, "b'\\x00\\x00\\x00\\x00'", 4),
#                # special case
#                u'shortstr': (None, None, "b'\\x00'", 1),  # special case
#                }
# 
# Path: coolamqp/framing/compilation/utilities.py
# def as_unicode(clbl):
#     def roll(*args, **kwargs):
#         return six.text_type(clbl(*args, **kwargs))
# 
#     return roll


import math
import six
from coolamqp.framing.base import BASIC_TYPES
from coolamqp.framing.compilation.utilities import as_unicode
def f_fmt(data, *args, **kwargs):
    for arg in args:
        op = str if kwargs.get('sane', True) else f_repr
        data = data.replace('%s', op(arg), 1)
    data = data.replace('%S', '%s')
    return data


def to_docstring(label, doc, prefix=4,
                 blank=True):  # output a full docstring section
    label = [] if label is None else [label]
    doc = [] if doc is None else [q.strip() for q in doc.split(u'\n') if
                                  len(q.strip()) > 0]
    pre = u' ' * prefix

    doc = label + doc

    if len(doc) == 0:
        return u''

    doc[0] = doc[0].capitalize()

    if len(doc) == 1:
        return doc[0]

    doc = [p for p in doc if len(p.strip()) > 0]

    if blank:
        doc = [doc[0], u''] + doc[1:]


# Path: coolamqp/framing/base.py
# BASIC_TYPES = {u'bit': (None, None, "0", None),  # special case
#                u'octet': (1, 'B', "b'\\x00'", 1),
#                u'short': (2, 'H', "b'\\x00\\x00'", 2),
#                u'long': (4, 'I', "b'\\x00\\x00\\x00\\x00'", 4),
#                u'longlong': (
#                    8, 'Q', "b'\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00'", 8),
#                u'timestamp': (
#                    8, 'Q', "b'\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00'", 8),
#                u'table': (None, None, "b'\\x00\\x00\\x00\\x00'", 4),
#                # special case
#                u'longstr': (None, None, "b'\\x00\\x00\\x00\\x00'", 4),
#                # special case
#                u'shortstr': (None, None, "b'\\x00'", 1),  # special case
#                }
# 
# Path: coolamqp/framing/compilation/utilities.py
# def as_unicode(clbl):
#     def roll(*args, **kwargs):
#         return six.text_type(clbl(*args, **kwargs))
# 
#     return roll


# Path: compile_definitions/utilities.py
import math
import six
from coolamqp.framing.base import BASIC_TYPES
from coolamqp.framing.compilation.utilities import as_unicode

def f_fmt(data, *args, **kwargs):
    for arg in args:
        op = str if kwargs.get('sane', True) else f_repr
        data = data.replace('%s', op(arg), 1)
    data = data.replace('%S', '%s')
    return data


def to_docstring(label, doc, prefix=4,
                 blank=True):  # output a full docstring section
    label = [] if label is None else [label]
    doc = [] if doc is None else [q.strip() for q in doc.split(u'\n') if
                                  len(q.strip()) > 0]
    pre = u' ' * prefix

    doc = label + doc

    if len(doc) == 0:
        return u''

    doc[0] = doc[0].capitalize()

    if len(doc) == 1:
        return doc[0]

    doc = [p for p in doc if len(p.strip()) > 0]

    if blank:
        doc = [doc[0], u''] + doc[1:]


    f = (u'\n'.join(pre + lin for lin in doc))[prefix:]