Beispiel #1
0
def methods(parent):
    m = [
        'std::wstring format(LogRecord record) const',
        'std::wstring formatTime(LogRecord record) const',
        'std::wstring formatTime(LogRecord record, std::wstring datefmt) const',
        'std::wstring formatException(boost::python::tuple exc) const'
        ]
    list(map(lambda m: method(m, parent=parent), m))
Beispiel #2
0
def methods(parent):
    methods = [
        ("void setLevel(Level l)", "Sets the threshold for this logger."),
        (
            "bool isEnabledFor(Level l) const",
            "Indicates if a message of severity ``lvl`` would be processed by this logger.",
        ),
        ("Level getEffectiveLevel() const", "Indicates the effective level for this logger."),
        ("void log(Level lvl, std::wstring msg) const", "Logs a message with level ``lvl`` on this logger."),
        ("void addFilter(Filter f)", "Adds the specified filter ``filt`` to this logger."),
        ("void removeFilter(Filter f)", "Removes the specified filter ``filt`` from this logger."),
        (
            "bool filter(LogRecord r) const",
            "Applies this logger's filters to the record and returns a true value if the record is to be processed.",
        ),
        ("void addHandler(Handler h)", "Adds the specified handler ``hdlr`` to this logger."),
        ("void removeHandler(Handler h)", "Removes the specified handler hdlr from this logger."),
        (
            "void handle(LogRecord r) const",
            "Handles a record by passing it to all handlers associated with this logger and its ancestors (until a false value of propagate is found).",
        ),
        (
            "void exception(std::wstring msg) const",
            """Logs a message with level ``ERROR`` on this logger.

            Exception info is added to the logging message. This method
            should only be called from an exception handler.""",
        ),
    ]

    for lvl in ["debug", "info", "warning", "error", "critical"]:
        methods.append(
            (
                "void {0}(std::wstring msg) const".format(lvl),
                "Logs a message with level ``{0}`` on this logger.".format(lvl.upper()),
            )
        )

    for m in methods:
        docstring = """\\rst
                     {0}
                     \\endrst""".format(
            m[1]
        )
        method(m[0], parent=parent, doc=docstring)
Beispiel #3
0
def methods(parent):
    m = [
        'void debug(std::wstring msg) const',
        'void info(std::wstring msg) const',
        'void warning(std::wstring msg) const',
        'void error(std::wstring msg) const',
        'void critical(std::wstring msg) const',
        'void log(Level l, std::wstring msg) const',
        'void process(std::wstring msg, boost::python::dict kwargs) const',
        ]
    list(map(lambda m: method(m, parent=parent), m))
Beispiel #4
0
def methods(parent):
    m = [
        ('void setLevel(Level level)',
         'Set the logging level of this handler.'),
        ('void setFormatter(Formatter f)',
         'Set the formatter for this handler.'),
        ('void addFilter(Filter f)',
         'Add the specified filter to this handler.'),
        ('void removeFilter(Filter f)',
         'Remove the specified filter from this handler.'),
        ('void flush() const',
         'Ensure all logging output has been flushed.'),
        ('void close()',
         'Tidy up any resources used by the handler.')
        ]
    list(map(lambda m: method(m[0], parent=parent, doc=m[1]), m))

    Method(
        name='emit',
        signature=[('LogRecord', 'r')],
        const=True,
        virtual=True,
        parent=parent,
        doc='Do whatever it takes to actually log the specified logging record.')
Beispiel #5
0
def date_class(parent):
    cls = Class(name='Date',
                wrapped_class='datetime.date',
                parent=parent)

    Constructor(
        signature=[('unsigned int', 'year'),
                   ('unsigned int', 'month'),
                   ('unsigned int', 'day')],
        parent=cls)

    class_method('Date today()', parent=cls)
    class_method('Date fromtimestamp(double timestamp)', parent=cls)
    class_method('Date fromordinal(unsigned int ordinal)', parent=cls)

    ClassProperty(
        name='min',
        type='Date',
        read_only=True,
        parent=cls)

    ClassProperty(
        name='max',
        type='Date',
        read_only=True,
        parent=cls)

    ClassProperty(
        name='resolution',
        type='TimeDelta',
        read_only=True,
        parent=cls)

    Property(
        name='year',
        type='unsigned int',
        read_only=True,
        parent=cls)

    Property(
        name='month',
        type='unsigned int',
        read_only=True,
        parent=cls)

    Property(
        name='day',
        type='unsigned int',
        read_only=True,
        parent=cls)

    Method(
        name='_replace',
        python_name='replace',
        return_type='Date',
        signature=[('unsigned int', 'year'),
                   ('unsigned int', 'month'),
                   ('unsigned int', 'day')],
        const=True,
        parent=cls)

    InlineFunction(
        code=replace_method,
        parent=cls)

    for m in [
        'tm timetuple() const',
        'unsigned int toordinal() const',
        'int weekday() const',
        'int isoweekday() const',
        'boost::tuple<int, int, int> isocalendar() const',
        'std::string isoformat() const',
        'std::string ctime() const',
        'std::wstring strftime(std::wstring fmt) const']:
        method(m, parent=cls)

    InlineFunction(
        code=equality_operator,
        parent=cls)
Beispiel #6
0
def definition(env):
    t = tunit()
    ns = Namespace('ackward', 'logging', parent=t)

    cls = Class(name='LogRecord',
                wrapped_class='logging.LogRecord',
                parent=ns,
                doc=log_record_doc)

    Constructor(
        signature=[
            ('std::wstring', 'name'),
            ('Level', 'lvl'),
            ('std::wstring', 'pathname'),
            ('int', 'lineno'),
            ('std::wstring', 'msg'),
            ('boost::python::tuple', 'args'),
            ('boost::python::object', 'exc_info', 'boost::python::object()'),
        ],
        parent=cls,
        doc='Create a new LogRecord.')

    method('std::wstring getMessage() const',
           parent=cls,
           doc=get_message_doc)

    properties = [
        ('args', 'boost::python::tuple'),
        ('asctime', 'std::wstring',
         'Only exists after the LogRecord is emitted.'),
        ('created', 'float'),
        ('exc_info', 'boost::python::tuple',
         'Will be "None" if there is not exception info.'),
        ('filename', 'std::wstring'),
        ('funcName', 'std::wstring',
         'Will be "None" prior to being emitted.'),
        ('levelname', 'std::wstring'),
        ('levelno', 'int'),
        ('lineno', 'int'),
        ('module', 'std::wstring'),
        ('msecs', 'float'),
        ('message', 'std::wstring',
         'Will be "None" prior to being emitted.'),
        ('msg', 'std::wstring'),
        ('name', 'std::wstring'),
        ('pathname', 'std::wstring'),
        ('process', 'int'),
        ('processName', 'std::wstring'),
        ('relativeCreated', 'float'),
        ('thread', 'unsigned long'),
        ('threadName', 'std::wstring')
    ]

    if env['PYTHON_VERSION'] == 3:
        properties.append(
            ('stack_info', 'boost::python::object'))

    for prop in properties:
        if len(prop) == 3:
            prop_name,prop_type,doc = prop
        else:
            prop_name,prop_type,doc = prop + (None,)
        Property(prop_name,
                 prop_type,
                 read_only=True,
                 parent=cls,
                 doc=doc)

    return t
Beispiel #7
0
def definition(env):
    t = tunit()
    ns = Namespace('ackward', 're', parent=t)
    cls =  Class(name='RegexObject',
                 wrapped_class='_sre.SRE_Pattern',
                 parent=ns)

    method('MatchObject match(std::wstring s) const',
           parent=cls)
    method('MatchObject match(std::wstring s, int pos)',
           parent=cls)
    method('MatchObject match(std::wstring s, int pos, int endpos)',
           parent=cls)

    method('MatchObject search(std::wstring s) const',
           parent=cls)
    method('MatchObject search(std::wstring s, int pos)',
           parent=cls)
    method('MatchObject search(std::wstring s, int pos, int endpos)',
           parent=cls)

    method('boost::python::list split(std::wstring s) const',
           parent=cls)
    method('boost::python::list split(std::wstring s, int maxsplit) const',
           parent=cls)

# RegexObject.findall(string[, pos[, endpos]])
#     Identical to the findall() function, using the compiled pattern.

# RegexObject.finditer(string[, pos[, endpos]])
#     Identical to the finditer() function, using the compiled pattern.

# RegexObject.sub(repl, string[, count=0])
#     Identical to the sub() function, using the compiled pattern.

# RegexObject.subn(repl, string[, count=0])
#     Identical to the subn() function, using the compiled pattern.

# RegexObject.flags
#     The flags argument used when the RE object was compiled, or 0 if no flags were provided.

# RegexObject.groups
#     The number of capturing groups in the pattern.

# RegexObject.groupindex
#     A dictionary mapping any symbolic group names defined by (?P<id>) to group numbers. The dictionary is empty if no symbolic groups were used in the pattern.

# RegexObject.pattern
#     The pattern string from which the RE object was compiled.

    return t
Beispiel #8
0
def queueClass(env, qtype, parent):
    cls = Class(name=qtype,
                wrapped_class='{0}.{1}'.format(modname(env), qtype),
                parent=parent,
                doc=queue_doc.format(qtype))

    method('unsigned int qsize() const',
           parent=cls).doc = qsize_doc
    # method('bool empty() const')

    # put
    InlineFunction('''
template <typename T>
void put(const T& t) {
  try { obj().attr("put")(t); }
  TRANSLATE_PYTHON_EXCEPTION()
}''',
    parent=cls).doc = put_doc.format('')

    InlineFunction('''
template <typename T>
void put(const T& t, bool block) {
  try { obj().attr("put")(t, block); }
  TRANSLATE_PYTHON_EXCEPTION()
}''',
    parent=cls).doc = put_doc.format(
        '@param block Whether to block until the queue has space.')

    InlineFunction('''
template <typename T>
void put(const T& t, bool block, unsigned int timeout) {
  try { obj().attr("put")(t, block, timeout); }
  TRANSLATE_PYTHON_EXCEPTION()
}''',
    parent=cls).doc = put_doc.format(
        '''@param block Whether to block until the queue has space.
        @param timeout How long to wait for queue to have space.''')

        # get
    InlineFunction('''
template <typename T>
T get() {
  try { return boost::python::extract<T>(obj().attr("get")()); }
  TRANSLATE_PYTHON_EXCEPTION()
}''',
    parent=cls).doc = get_doc.format('')

    InlineFunction('''
template <typename T>
T get(bool block) {
  try { return boost::python::extract<T>(obj().attr("get")(block)); }
  TRANSLATE_PYTHON_EXCEPTION()
}''',
    parent=cls).doc = get_doc.format(
        '@param block Whether to block until there\'s an item in the queue.')

    InlineFunction('''
template <typename T>
T get(bool block, unsigned int timeout) {
  try { return boost::python::extract<T>(obj().attr("get")(block, timeout)); }
  TRANSLATE_PYTHON_EXCEPTION()
}''',
    parent=cls).doc = get_doc.format(
        '''@param block Whether to block until there\'s an item in the queue.
        @param timeout How long to wait until there's an item in the queue.''')

    method('bool full() const',
           parent=cls).doc = 'Return True if the queue is full, False otherwise.'
    method('void task_done()',
           parent=cls).doc = 'Indicate that a formerly enqueued task is complete.'
    method('void join()',
           parent=cls).doc = 'Blocks until all items in the queue have been gotten and processed.'
Beispiel #9
0
def definition(env):
    t = tunit()
    ns = Namespace('ackward', 're', parent=t)
    cls = Class(name='MatchObject',
                wrapped_class='_sre.SRE_Match',
                parent=ns)

    method('std::wstring expand(std::wstring tmpl) const',
           parent=cls)

    # TODO
    # MatchObject.group([group1, ...])

    method('boost::python::tuple groups() const',
           parent=cls)
    method('boost::python::tuple groups(boost::python::object dflt) const',
           parent=cls)

    method('boost::python::dict groupdict() const',
           parent=cls)
    method('boost::python::dict groupdict(boost::python::object dflt) const',
           parent=cls)

    # MatchObject.start([group])
    # MatchObject.end([group])

#     Return the indices of the start and end of the substring matched by group; group defaults to zero (meaning the whole matched substring). Return -1 if group exists but did not contribute to the match. For a match object m, and a group g that did contribute to the match, the substring matched by group g (equivalent to m.group(g)) is

#     m.string[m.start(g):m.end(g)]

#     Note that m.start(group) will equal m.end(group) if group matched a null string. For example, after m = re.search('b(c?)', 'cba'), m.start(0) is 1, m.end(0) is 2, m.start(1) and m.end(1) are both 2, and m.start(2) raises an IndexError exception.

#     An example that will remove remove_this from email addresses:

#     >>> email = "tony@tiremove_thisger.net"
#     >>> m = re.search("remove_this", email)
#     >>> email[:m.start()] + email[m.end():]
#     '*****@*****.**'

# MatchObject.span([group])
#     For MatchObject m, return the 2-tuple (m.start(group), m.end(group)). Note that if group did not contribute to the match, this is (-1, -1). group defaults to zero, the entire match.

# MatchObject.pos
#     The value of pos which was passed to the search() or match() method of the RegexObject. This is the index into the string at which the RE engine started looking for a match.

# MatchObject.endpos
#     The value of endpos which was passed to the search() or match() method of the RegexObject. This is the index into the string beyond which the RE engine will not go.

# MatchObject.lastindex
#     The integer index of the last matched capturing group, or None if no group was matched at all. For example, the expressions (a)b, ((a)(b)), and ((ab)) will have lastindex == 1 if applied to the string 'ab', while the expression (a)(b) will have lastindex == 2, if applied to the same string.

# MatchObject.lastgroup
#     The name of the last matched capturing group, or None if the group didnt have a name, or if no group was matched at all.

# MatchObject.re
#     The regular expression object whose match() or search() method produced this MatchObject instance.

# MatchObject.string
#     The string passed to match() or search().

    return t
Beispiel #10
0
def time_class(parent):
    cls = Class(name='Time',
                wrapped_class='datetime.time',
                parent=parent)

    Constructor(
        signature=[('unsigned int', 'hour'),
                   ('unsigned int', 'minute', '0'),
                   ('unsigned int', 'second', '0'),
                   ('unsigned int', 'microsecond', '0'),
                   #[, tzinfo]]]])
               ],
        parent=cls)

    ClassProperty(
        name='min',
        type='Time',
        read_only=True,
        parent=cls)

    ClassProperty(
        name='max',
        type='Time',
        read_only=True,
        parent=cls)

    ClassProperty(
        name='resolution',
        type='TimeDelta',
        read_only=True,
        parent=cls)

    Property(
        name='hour',
        type='unsigned int',
        read_only=True,
        parent=cls)

    Property(
        name='minute',
        type='unsigned int',
        read_only=True,
        parent=cls)

    Property(
        name='second',
        type='unsigned int',
        read_only=True,
        parent=cls)

    Property(
        name='microsecond',
        type='unsigned int',
        read_only=True,
        parent=cls)

    #     # TODO:
    #     # time.tzinfo
    #     # The object passed as the tzinfo argument to the time
    #     # constructor, or None if none was passed.

    # # Instance methods:

    Method(
        name='_replace',
        python_name='replace',
        signature=[('unsigned int', 'hour'),
                   ('unsigned int', 'minute'),
                   ('unsigned int', 'second'),
                   ('unsigned int', 'microsecond')],
        return_type='Time',
        const=True,
        parent=cls)

    InlineFunction(
        code=replace_method,
        parent=cls)

    method('std::string isoformat() const', parent=cls)
    method('std::wstring strftime(std::wstring fmt) const', parent=cls)

        # # time.strftime(format)
        # # Return a string representing the time, controlled by an explicit format string. See section strftime() Behavior.
        # # time.utcoffset()
        # # If tzinfo is None, returns None, else returns self.tzinfo.utcoffset(None), and raises an exception if the latter doesn't return None or a timedelta object representing a whole number of minutes with magnitude less than one day.
        # # time.dst()
        # # If tzinfo is None, returns None, else returns self.tzinfo.dst(None), and raises an exception if the latter doesn't return None, or a timedelta object representing a whole number of minutes with magnitude less than one day.
        # # time.tzname()
        # # If tzinfo is None, returns None, else returns self.tzinfo.tzname(None), or raises an exception if the latter doesn't return None or a string object.

#     return c

    InlineFunction(
        code=lt_operator,
        parent=cls)

    InlineFunction(
        code=eq_operator,
        parent=cls)