Exemple #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
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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
        )
Exemple #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)
Exemple #8
0
 def __new__(cls, startMessage, endMessage, children):
     return PClass.__new__(cls,
                           startMessage=startMessage,
                           endMessage=endMessage,
                           children=children)
Exemple #9
0
 def __new__(cls, message):
     return PClass.__new__(cls, message=message)
Exemple #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
Exemple #11
0
 def remove(self, key):
     return PClass.set(self,
                       dict_=self.dict_.remove(key),
                       order=self.order.remove(key))
Exemple #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)
Exemple #13
0
 def __new__(cls, startMessage, endMessage, children):
     return PClass.__new__(cls, startMessage=startMessage,
                           endMessage=endMessage, children=children)
Exemple #14
0
 def __new__(cls, message):
     return PClass.__new__(cls, message=message)
Exemple #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
    }
Exemple #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)