Exemplo n.º 1
0
 def getPageFrom(self, fromPage, toPage):
     if isinstance(toPage, BasePage):
         return toPage
     elif utils.isStringLike(toPage):
         exact, isParent, isChild, isSibling, isLocal = False, False, False, False, False
         if toPage.startswith("/") or toPage.startswith(os.path.sep):
             exact = True
         elif toPage.startswith("./") or toPage.startswith("." + os.path.sep):
             isChild = True
             toPage = toPage[2:]
         elif toPage.startswith("^/") or toPage.startswith("^" + os.path.sep):
             isParent = True
             toPage = toPage[2:]
         elif toPage.startswith("-/") or toPage.startswith("-" + os.path.sep):
             isSibling = True
             toPage = toPage[2:]
         elif toPage.startswith("$/") or toPage.startswith("$" + os.path.sep):
             isLocal = True
             toPage = toPage[2:]
         if any([isParent, isChild, isSibling, isLocal]) and not fromPage:
             s = "Relative page link '%s' outside of page call context."%toPage
             raise ApplicationError(s)
         path = [i for i in os.path.normpath(toPage).split(os.path.sep) if i and i != "."]
         if not path:
             return self.root
         pname = path[-1]
         pagelist = self._pages.get(pname, None)
         if pagelist:
             match = None
             for p in pagelist:
                 if isChild:
                     if not fromPage.isDescendantOf(p):
                         continue
                 elif isParent:
                     if not p.isDescendantOf(fromPage):
                         continue
                 elif isSibling:
                     if not fromPage.isSiblingOf(p):
                         continue
                 elif isLocal:
                     values = [
                         fromPage.isDescendantOf(p),
                         p.isDescendantOf(fromPage),
                         fromPage.isSiblingOf(p)
                     ]
                     if not any(values):
                         continue
                 if p.match(path, exact):
                     if match:
                         raise ApplicationError(
                                 "Ambiguous path specification: %s."%toPage
                         )
                     match = p
             return match
         else:
             return None
     else:
         s = "Invalid argument to getPage: %s."%repr(toPage) +\
             " Must be either a string or a Page object."
         raise ApplicationError(s)
Exemplo n.º 2
0
 def _getLayoutComponent(self, attr):
     if attr in self.namespace:
         r = self.namespace[attr]
     else:
         r = model.HTMLPage._getLayoutComponent(self, attr)
     base = None
     if self.src:
         base = os.path.dirname(self.src)
     with utils.InDir(base or "."):
         if utils.isStringLike(r) and (attr not in self._verbatimComponents):
             return template.Template(self.findAttr("markup"), unicode(r))
         else:
             return r
Exemplo n.º 3
0
    def set_property(self, name, value, type=None, format=None):
        """
            name: String Atom name
            type: String Atom name
            format: 8, 16, 32
        """
        if name in PropertyMap:
            if type or format:
                raise ValueError(
                    "Over-riding default type or format for property."
                )
            type, format = PropertyMap[name]
        else:
            if None in (type, format):
                raise ValueError(
                    "Must specify type and format for unknown property."
                )

        if not utils.isSequenceLike(value):
            value = [value]

        buf = []
        for i in value:
            # We'll expand these conversions as we need them
            if format == 32:
                buf.append(struct.pack("=L", i))
            elif format == 16:
                buf.append(struct.pack("=H", i))
            elif format == 8:
                if utils.isStringLike(i):
                    # FIXME: Unicode -> bytes conversion needed here
                    buf.append(i)
                else:
                    buf.append(struct.pack("=B", i))
        buf = "".join(buf)

        length = len(buf) / (format / 8)

        # This is a real balls-up interface-wise. As I understand it, each type
        # can have a different associated size.
        #  - value is a string of bytes.
        #  - length is the length of the data in terms of the specified format.
        self.conn.conn.core.ChangeProperty(
            xcb.xproto.PropMode.Replace,
            self.wid,
            self.conn.atoms[name],
            self.conn.atoms[type],
            format,  # Format - 8, 16, 32
            length,
            buf
        )
Exemplo n.º 4
0
 def _getLayoutComponent(self, attr):
     if attr in self.namespace:
         r = self.namespace[attr]
     else:
         r = model.HTMLPage._getLayoutComponent(self, attr)
     base = None
     if self.src:
         base = os.path.dirname(self.src)
     with utils.InDir(base or "."):
         if utils.isStringLike(r) and (attr
                                       not in self._verbatimComponents):
             return template.Template(self.findAttr("markup"), unicode(r))
         else:
             return r
Exemplo n.º 5
0
 def __set__(self, obj, val):
     try:
         int(val)
     except (ValueError, TypeError):
         if self.options:
             if utils.isStringLike(val):
                 if self.options.has_key(str(val)):
                     val = self.options[str(val)]
             else:
                 cval = 0
                 for i in val:
                     cval |= self.options[str(i)]
                 val = cval
     return BitField.__set__(self, obj, self._setConversion(val))
Exemplo n.º 6
0
    def set_property(self, name, value, type=None, format=None):
        """
            name: String Atom name
            type: String Atom name
            format: 8, 16, 32
        """
        if name in PropertyMap:
            if type or format:
                raise ValueError(
                    "Over-riding default type or format for property.")
            type, format = PropertyMap[name]
        else:
            if None in (type, format):
                raise ValueError(
                    "Must specify type and format for unknown property.")

        if not utils.isSequenceLike(value):
            value = [value]

        buf = []
        for i in value:
            # We'll expand these conversions as we need them
            if format == 32:
                buf.append(struct.pack("=L", i))
            elif format == 16:
                buf.append(struct.pack("=H", i))
            elif format == 8:
                if utils.isStringLike(i):
                    # FIXME: Unicode -> bytes conversion needed here
                    buf.append(i)
                else:
                    buf.append(struct.pack("=B", i))
        buf = "".join(buf)

        length = len(buf) / (format / 8)

        # This is a real balls-up interface-wise. As I understand it, each type
        # can have a different associated size.
        #  - value is a string of bytes.
        #  - length is the length of the data in terms of the specified format.
        self.conn.conn.core.ChangeProperty(
            xcb.xproto.PropMode.Replace,
            self.wid,
            self.conn.atoms[name],
            self.conn.atoms[type],
            format,  # Format - 8, 16, 32
            length,
            buf)
Exemplo n.º 7
0
def raises(exc, obj, *args, **kwargs):
    """
        Assert that a callable raises a specified exception.

        :exc An exception class or a string. If a class, assert that an
        exception of this type is raised. If a string, assert that the string
        occurs in the string representation of the exception, based on a
        case-insenstivie match.

        :obj A callable object.

        :args Arguments to be passsed to the callable.

        :kwargs Arguments to be passed to the callable.
    """
    try:
        apply(obj, args, kwargs)
    except Exception, v:
        if utils.isStringLike(exc):
            if exc.lower() in str(v).lower():
                return
            else:
                raise AssertionError(
                    "Expected %s, but caught %s"%(
                        repr(str(exc)), v
                    )
                )
        else:
            if isinstance(v, exc):
                return
            else:
                raise AssertionError(
                    "Expected %s, but caught %s %s"%(
                        exc.__name__, v.__class__.__name__, str(v)
                    )
                )
Exemplo n.º 8
0
 def __init__(self, root, options=[]):
     if utils.isStringLike(root):
         d = DocRoot(root, options)
     else:
         d = root
     model.BaseApplication.__init__(self, d)
Exemplo n.º 9
0
 def __init__(self, root, options=[]):
     if utils.isStringLike(root):
         d = DocRoot(root, options)
     else:
         d = root
     model.BaseApplication.__init__(self, d)