# Path: pyisis/lib/util.py
# def as_string (cobj):
# def cast_as (bufptr, ctype):
# def copy_as (s, ctype):
# def copy_cobj (s, ctype):
# def memcpy (dst, src):
#     def _chr3 (val):
#     def buffer3 (val, off=None, sz=None):
#     def tlvrdb (val):
#     def buffer3 (val, off=None, l=None):
#     def stringify3 (b):
# def debug_exception ():
#     def __init__ (self):
#     def elapsed (self):
#     def __str__ (self):
#     def __init__ (self, lifetime):
#     def reset (self, lifetime):
#     def expire_at (self):
#     def timeleft (self):
#     def __init__ (self):
#     def __enter__ (self):
#     def __exit__ (self, *args):
#     def held (self):
#     def acquire (self, blocking=True):
#     def release (self):
# def debug_after (count=1):
#     def __enter__ (self):
#     def __exit__ (self, *args):
# class CPUTimer (object):
# class Lifetime (object):
# class QueryLock (object):
# class NoLock (object):


from ctypes import sizeof
from pyisis.bstr import bchr, memspan                       # pylint: disable=E0611
from pyisis.lib.util import stringify3, tlvrdb, xrange3
import logbook
import pyisis.clns as clns
import pyisis.lib.debug as debug
import pyisis.pdu as pdu
import pyisis.lib.timers as timers
import pyisis.tlv as tlv
import pyisis.lib.util as util
        # Complete the LSP and update the DB.
        tlvstart = self.get_tlv_start(lsp, buf)
        tlvspace = memspan(tlvstart, tlvview)
        lsp.pdu_len = sizeof(lsp) + tlvspace
        pdubuf = memoryview(buf)
        pdubuf = pdubuf[:lsp.pdu_len]

        # XXX cast_as doesn't like bytearray or a memoryview of it, copy into string
        # pdubuf = stringify3(pdubuf)

        # Re-get the start using new sized buffer.
        tlvstart = self.get_tlv_start(lsp, pdubuf)
        tlvs = tlv.parse_tlvs(tlvstart, debug.is_dbg(lsp))

        uproc = self.inst.update[self.lindex]
        uproc.update_own_lsp(pdubuf, tlvs)

        segment = get_lsp_number(lsp)
        self.segments[segment] = uproc.get_lsp_segment(stringify3(lsp.lspid))

    def close_lsp (self, lsp, buf, tlvview):
        segnum = get_lsp_number(lsp)
        tlvstart = self.get_tlv_start(lsp, buf)

        # We only introduce empty LSPs for segment 0
        if memspan(tlvstart, tlvview) > 0 or segnum == 0:
            self.update_lsp_db(lsp, buf, tlvview)
            segnum += 1

        # Purge any newly unsupported.

# Path: pyisis/lib/util.py
# def as_string (cobj):
# def cast_as (bufptr, ctype):
# def copy_as (s, ctype):
# def copy_cobj (s, ctype):
# def memcpy (dst, src):
#     def _chr3 (val):
#     def buffer3 (val, off=None, sz=None):
#     def tlvrdb (val):
#     def buffer3 (val, off=None, l=None):
#     def stringify3 (b):
# def debug_exception ():
#     def __init__ (self):
#     def elapsed (self):
#     def __str__ (self):
#     def __init__ (self, lifetime):
#     def reset (self, lifetime):
#     def expire_at (self):
#     def timeleft (self):
#     def __init__ (self):
#     def __enter__ (self):
#     def __exit__ (self, *args):
#     def held (self):
#     def acquire (self, blocking=True):
#     def release (self):
# def debug_after (count=1):
#     def __enter__ (self):
#     def __exit__ (self, *args):
# class CPUTimer (object):
# class Lifetime (object):
# class QueryLock (object):
# class NoLock (object):


# Path: pyisis/lsp.py
from ctypes import sizeof
from pyisis.bstr import bchr, memspan                       # pylint: disable=E0611
from pyisis.lib.util import stringify3, tlvrdb, xrange3
import logbook
import pyisis.clns as clns
import pyisis.lib.debug as debug
import pyisis.pdu as pdu
import pyisis.lib.timers as timers
import pyisis.tlv as tlv
import pyisis.lib.util as util

        # Complete the LSP and update the DB.
        tlvstart = self.get_tlv_start(lsp, buf)
        tlvspace = memspan(tlvstart, tlvview)
        lsp.pdu_len = sizeof(lsp) + tlvspace
        pdubuf = memoryview(buf)
        pdubuf = pdubuf[:lsp.pdu_len]

        # XXX cast_as doesn't like bytearray or a memoryview of it, copy into string
        # pdubuf = stringify3(pdubuf)

        # Re-get the start using new sized buffer.
        tlvstart = self.get_tlv_start(lsp, pdubuf)
        tlvs = tlv.parse_tlvs(tlvstart, debug.is_dbg(lsp))

        uproc = self.inst.update[self.lindex]
        uproc.update_own_lsp(pdubuf, tlvs)

        segment = get_lsp_number(lsp)
        self.segments[segment] = uproc.get_lsp_segment(stringify3(lsp.lspid))

    def close_lsp (self, lsp, buf, tlvview):
        segnum = get_lsp_number(lsp)
        tlvstart = self.get_tlv_start(lsp, buf)

        # We only introduce empty LSPs for segment 0
        if memspan(tlvstart, tlvview) > 0 or segnum == 0:
            self.update_lsp_db(lsp, buf, tlvview)
            segnum += 1

        # Purge any newly unsupported.

        for i in xrange3(segnum, 256):