Exemplo n.º 1
0
    def __new__(cls,
                name=None,
                params=None,
                children=(),
                doc=None,
                parent=None,
                _parent=None,
                _factory_fields=None):
        doc = doc if doc is not None else default_doc
        children = children if type(children) == vector_type else\
                   pvector(wrap_children(params["id"], doc, children))
        for key, value in (params or {}).items():
            if type(value) == Ex:
                value = Expr(scope=doc,
                             path=(params["id"], [key])).set_value(value)
                params[key] = value

        self = PClass.__new__(cls,
            name=name,
            params=params if isinstance(params, map_type) or\
                             isinstance(params, PClass)\
                             else pmap(params),
            children=children,
            doc=doc,
            _parent=wrap2(parent, doc) if parent is not None else _parent)
        return self
Exemplo n.º 2
0
 def __new__(cls, hostname=None, **kwargs):
     if "uuid" not in kwargs:
         # To be removed in https://clusterhq.atlassian.net/browse/FLOC-1795
         warn("UUID is required, this is for backwards compat with existing"
              " tests only. If you see this in production code that's "
              "a bug.", DeprecationWarning, stacklevel=2)
         kwargs["uuid"] = ip_to_uuid(hostname)
     return PClass.__new__(cls, **kwargs)
Exemplo n.º 3
0
 def __new__(cls, hostname=None, **kwargs):
     if "uuid" not in kwargs:
         # To be removed in https://clusterhq.atlassian.net/browse/FLOC-1795
         warn("UUID is required, this is for backwards compat with existing"
              " tests only. If you see this in production code that's "
              "a bug.", DeprecationWarning, stacklevel=2)
         kwargs["uuid"] = ip_to_uuid(hostname)
     return PClass.__new__(cls, **kwargs)
Exemplo n.º 4
0
 def __new__(cls, node, doc, dict_=pmap(), order=None, **kwargs):
     order = pvector(sorted(dict_.keys())) if order is None else order
     if type(dict_) != map_type:
         dict_ = pmap(dict_)
     assert (len(dict_) == len(order))
     return PClass.__new__(cls,
                           node=node,
                           doc=doc,
                           order=order,
                           dict_=dict_,
                           **kwargs)
Exemplo n.º 5
0
    def __new__(cls, file):
        unicodeFile = False
        if PY3:
            try:
                file.write(b"")
            except TypeError:
                unicodeFile = True

        if unicodeFile:
            # On Python 3 native json module outputs unicode:
            _dumps = pyjson.dumps
            _linebreak = u"\n"
        else:
            _dumps = fast_json.dumps
            _linebreak = b"\n"
        return PClass.__new__(
            cls, file=file, _dumps=_dumps, _linebreak=_linebreak)
Exemplo n.º 6
0
    def __new__(cls, file, encoder=EliotJSONEncoder):
        if isinstance(file, IOBase) and not file.writable():
            raise RuntimeError("Given file {} is not writeable.")

        unicodeFile = False
        try:
            file.write(b"")
        except TypeError:
            unicodeFile = True

        if unicodeFile:
            # On Python 3 native json module outputs unicode:
            _dumps = pyjson.dumps
            _linebreak = "\n"
        else:
            _dumps = bytesjson.dumps
            _linebreak = b"\n"
        return PClass.__new__(
            cls, file=file, _dumps=_dumps, _linebreak=_linebreak, encoder=encoder
        )
Exemplo n.º 7
0
    def __new__(cls, file, encoder=EliotJSONEncoder):
        if isinstance(file, IOBase) and not file.writable():
            raise RuntimeError("Given file {} is not writeable.")

        unicodeFile = False
        try:
            file.write(b"")
        except TypeError:
            unicodeFile = True

        if unicodeFile:
            # On Python 3 native json module outputs unicode:
            _dumps = pyjson.dumps
            _linebreak = "\n"
        else:
            _dumps = bytesjson.dumps
            _linebreak = b"\n"
        return PClass.__new__(cls,
                              file=file,
                              _dumps=_dumps,
                              _linebreak=_linebreak,
                              encoder=encoder)
Exemplo n.º 8
0
 def __new__(cls, startMessage, endMessage, children):
     return PClass.__new__(cls,
                           startMessage=startMessage,
                           endMessage=endMessage,
                           children=children)
Exemplo n.º 9
0
 def __new__(cls, message):
     return PClass.__new__(cls, message=message)
Exemplo n.º 10
0
 def change(self, **kwargs):
     new_node = PClass.set(self, **kwargs)
     if new_node.doc is not None:
         new_node.doc[new_node.node + ".transforms"] = new_node
         new_node.doc.dirty.add(new_node.node)
     return new_node
Exemplo n.º 11
0
 def remove(self, key):
     return PClass.set(self,
                       dict_=self.dict_.remove(key),
                       order=self.order.remove(key))
Exemplo n.º 12
0
 def set(self, key, value):
     return PClass.set(self, dict_=self.dict_.set(key, value),
                       order=self.order.append(key)\
                       if key not in self.dict_ else self.order)
Exemplo n.º 13
0
 def __new__(cls, startMessage, endMessage, children):
     return PClass.__new__(cls, startMessage=startMessage,
                           endMessage=endMessage, children=children)
Exemplo n.º 14
0
 def __new__(cls, message):
     return PClass.__new__(cls, message=message)
Exemplo n.º 15
0
def _serialize_with_omit(self, format=None):
    return {
        key: value
        for (key, value) in PClass.serialize(self, format).iteritems()
        if value is not omit
    }
Exemplo n.º 16
0
 def __eq__(self, other):
     if type(other) == Ex:
         if self.expr is not None and self.expr.calc == "reeval":
             return self.expr == other
     return PClass.__eq__(self, other)