Serialize Nodes and attributes
14295
def serialize(self, *fields):
        
        if fields:
            if not set(fields).issubset(self.data_nodes):
                raise SchemaError('Invalid field for serialization: {}'.format(set(fields).difference(self.data_nodes)))

            return OrderedDict([(k, getattr(self, k)) for k in fields])

        return OrderedDict([(k, getattr(self, k)) for k in self.data_nodes])
1366464
public function serializeAttributes()
    {
        foreach ($this->attributes as $attribute) {
            if (isset($this->oldAttributes[$attribute])) {
                $this->owner->setOldAttribute($attribute, $this->oldAttributes[$attribute]);
            }
            if (is_array($this->owner->{$attribute}) && count($this->owner->{$attribute}) > 0) {
                $this->owner->$attribute = serialize($this->owner->{$attribute});
                if ($this->encode) {
                    $this->owner->{$attribute} = base64_encode($this->owner->{$attribute});
                }
            } elseif (empty($this->owner->{$attribute})) {
                $this->owner->{$attribute} = null;
            } else {
                throw new \Exception('Can’t serialize attribute "' . $attribute . '" of "' . $this->owner->className() . '".');
            }
        }
    }
1212451
def serialize(self):
        """"""
        # Serialize fields to a dict
        data = {}
        for field_name in self:
            value = self._values.get(field_name)
            field = self.fields.get(field_name)
            if value is not None:
                if field.all:
                    value = [field.serialize(v) for v in value]
                else:
                    value = field.serialize(value)
            # Skip empty fields unless field.null
            if not field.null and ((field.all and value == []) or (not field.all and value in {None, ''})):
                continue
            data[field.name] = value
        return data
1191431
public function serializeSchema()
    {
        $schemaPrefix = $this->getPrefixFromNamespace($this->XMLSchemaVersion);
        $xml = '';
        // imports
        if (sizeof($this->imports) > 0) {
            foreach ($this->imports as $ns => $list) {
                foreach ($list as $ii) {
                    if ($ii['location'] != '') {
                        $xml .= " <$schemaPrefix:import location=\"" . $ii['location'] . '" namespace="' . $ns . "\" />\n";
                    } else {
                        $xml .= " <$schemaPrefix:import namespace=\"" . $ns . "\" />\n";
                    }
                }
            }
        }
        // complex types
        foreach ($this->complexTypes as $typeName => $attrs) {
            $contentStr = '';
            // serialize child elements
            if (isset($attrs['elements']) && (count($attrs['elements']) > 0)) {
                foreach ($attrs['elements'] as $element => $eParts) {
                    if (isset($eParts['ref'])) {
                        $contentStr .= "   <$schemaPrefix:element ref=\"$element\"/>\n";
                    } else {
                        $contentStr .= "   <$schemaPrefix:element name=\"$element\" type=\"" . $this->contractQName($eParts['type']) . "\"";
                        foreach ($eParts as $aName => $aValue) {
                            // handle, e.g., abstract, default, form, minOccurs, maxOccurs, nillable
                            if ($aName != 'name' && $aName != 'type') {
                                $contentStr .= " $aName=\"$aValue\"";
                            }
                        }
                        $contentStr .= "/>\n";
                    }
                }
                // compositor wraps elements
                if (isset($attrs['compositor']) && ($attrs['compositor'] != '')) {
                    $contentStr = "  <$schemaPrefix:$attrs[compositor]>\n" . $contentStr . "  </$schemaPrefix:$attrs[compositor]>\n";
                }
            }
            // attributes
            if (isset($attrs['attrs']) && (count($attrs['attrs']) >= 1)) {
                foreach ($attrs['attrs'] as $attr => $aParts) {
                    $contentStr .= "    <$schemaPrefix:attribute";
                    foreach ($aParts as $a => $v) {
                        if ($a == 'ref' || $a == 'type') {
                            $contentStr .= " $a=\"" . $this->contractQName($v) . '"';
                        } elseif ($a == 'http://schemas.xmlsoap.org/wsdl/:arrayType') {
                            $this->usedNamespaces['wsdl'] = $this->namespaces['wsdl'];
                            $contentStr .= ' wsdl:arrayType="' . $this->contractQName($v) . '"';
                        } else {
                            $contentStr .= " $a=\"$v\"";
                        }
                    }
                    $contentStr .= "/>\n";
                }
            }
            // if restriction
            if (isset($attrs['restrictionBase']) && $attrs['restrictionBase'] != '') {
                $contentStr = "   <$schemaPrefix:restriction base=\"" . $this->contractQName($attrs['restrictionBase']) . "\">\n" . $contentStr . "   </$schemaPrefix:restriction>\n";
                // complex or simple content
                if ((isset($attrs['elements']) && count($attrs['elements']) > 0) || (isset($attrs['attrs']) && count($attrs['attrs']) > 0)) {
                    $contentStr = "  <$schemaPrefix:complexContent>\n" . $contentStr . "  </$schemaPrefix:complexContent>\n";
                }
            }
            // finalize complex type
            if ($contentStr != '') {
                $contentStr = " <$schemaPrefix:complexType name=\"$typeName\">\n" . $contentStr . " </$schemaPrefix:complexType>\n";
            } else {
                $contentStr = " <$schemaPrefix:complexType name=\"$typeName\"/>\n";
            }
            $xml .= $contentStr;
        }
        // simple types
        if (isset($this->simpleTypes) && count($this->simpleTypes) > 0) {
            foreach ($this->simpleTypes as $typeName => $eParts) {
                $xml .= " <$schemaPrefix:simpleType name=\"$typeName\">\n  <$schemaPrefix:restriction base=\"" . $this->contractQName($eParts['type']) . "\">\n";
                if (isset($eParts['enumeration'])) {
                    foreach ($eParts['enumeration'] as $e) {
                        $xml .= "  <$schemaPrefix:enumeration value=\"$e\"/>\n";
                    }
                }
                $xml .= "  </$schemaPrefix:restriction>\n </$schemaPrefix:simpleType>";
            }
        }
        // elements
        if (isset($this->elements) && count($this->elements) > 0) {
            foreach ($this->elements as $element => $eParts) {
                $xml .= " <$schemaPrefix:element name=\"$element\" type=\"" . $this->contractQName($eParts['type']) . "\"/>\n";
            }
        }
        // attributes
        if (isset($this->attributes) && count($this->attributes) > 0) {
            foreach ($this->attributes as $attr => $aParts) {
                $xml .= " <$schemaPrefix:attribute name=\"$attr\" type=\"" . $this->contractQName($aParts['type']) . "\"\n/>";
            }
        }
        // finish 'er up
        $attr = '';
        foreach ($this->schemaInfo as $k => $v) {
            if ($k == 'elementFormDefault' || $k == 'attributeFormDefault') {
                $attr .= " $k=\"$v\"";
            }
        }
        $el = "<$schemaPrefix:schema$attr targetNamespace=\"$this->schemaTargetNamespace\"\n";
        foreach (array_diff($this->usedNamespaces, $this->enclosingNamespaces) as $nsp => $ns) {
            $el .= " xmlns:$nsp=\"$ns\"";
        }
        $xml = $el . ">\n" . $xml . "</$schemaPrefix:schema>\n";
        return $xml;
    }
201251
def do_serialize(self, line):
        """"""
        opts = self.SERIALIZE_OPTS

        if not self.current:
            self._help_noontology()
            return

        line = line.split()
        g = self.current['graph']

        if not line:
            line = ['turtle']

        if line[0] not in opts:
            self.help_serialize()
            return

        elif self.currentEntity:
            self.currentEntity['object'].printSerialize(line[0])

        else:
            self._print(g.rdf_source(format=line[0]))
1358341
function toJSON(node) {
  node = node || this;

  var obj = {
    nodeType: node.nodeType
  };

  if (node.tagName) {
    obj.name = node.tagName.toLowerCase();
  } else if (node.nodeName) {
    obj.name = node.nodeName.toLowerCase();
  }
  if (node.nodeValue) {
    obj.nodeValue = node.nodeValue;
  }
  var attrs = node.attributes;

  if (attrs) {
    var length = attrs.length;

    obj.props = {};
    for (var i = 0; i < length; i++) {
      var attr = attrs[i];

      obj.props[attr.nodeName] = attr.nodeValue;
    }
  }
  var childNodes = node.childNodes;

  if (childNodes) {
    var _length = childNodes.length;

    obj.children = [];
    for (var _i = 0; _i < _length; _i++) {
      obj.children.push(toJSON(childNodes[_i]));
    }
  }
  return obj;
}
140956
def _serialize(self, value, attr, obj, **kwargs):
        """"""
        ret = self._validated(value)
        return (
            self._to_string(ret)
            if (self.as_string and ret not in (None, missing_))
            else ret
        )
1012022
def _serialize(self, convert_to_key_and_value, ignore_missing=False):
        

        serialized = {}
        properties = self._get_property_names(self)

        def get_property_detail(name):
            p = [p for p in self._property_details if p.name == name]
            return None if len(p) == 0 else p[0]

        for p in properties:
            pd = get_property_detail(p)
            value = self._property_to_field(p, pd)
            field_name = p if not pd else pd.to_field_name()

            if value is None or (ignore_missing and not value) or (pd and pd.unsent):
                continue
            else:
                key, value = convert_to_key_and_value(field_name, value, pd)
                if key:
                    serialized[key] = value

        return serialized
950114
function serialize(queryParams) {
  return Object.keys(queryParams)
    .filter(key => queryParams[key] !== undefined)
    .map(key => arrayToStr(key, queryParams[key]))
    .join('&');
}
350331
def get_nodes(self, request, *args, **kwargs):
        
        # ListSerializerMixin.list returns a serializer object
        return (self.list(request, *args, **kwargs)).data
1064709
def _serialize(self, value, key, obj):
        
        param_values = {}
        for name, attr_tpl in iteritems(self.params):
            attr_name = _tpl(str(attr_tpl))
            if attr_name:
                attribute_value = _get_value(obj, attr_name, default=missing)
                if attribute_value is None:
                    return None
                if attribute_value is not missing:
                    param_values[name] = attribute_value
                else:
                    raise AttributeError(
                        "{attr_name!r} is not a valid "
                        "attribute of {obj!r}".format(attr_name=attr_name, obj=obj)
                    )
            else:
                param_values[name] = attr_tpl
        return url_for(self.endpoint, **param_values)
260324
def _WriteAttributes(self):
    """"""
    # If the object is not opened for writing we do not need to flush it to the
    # data_store.
    if "w" not in self.mode:
      return

    if self.urn is None:
      raise ValueError("Storing of anonymous AFF4 objects not supported.")

    to_set = {}
    for attribute_name, value_array in iteritems(self.new_attributes):
      to_set_list = to_set.setdefault(attribute_name, [])
      for value in value_array:
        to_set_list.append((value.SerializeToDataStore(), value.age))

    if self._dirty:
      # We determine this object has a new version only if any of the versioned
      # attributes have changed. Non-versioned attributes do not represent a new
      # object version. The type of an object is versioned and represents a
      # version point in the life of the object.
      if self._new_version:
        to_set[self.Schema.TYPE] = [
            (utils.SmartUnicode(self.__class__.__name__),
             rdfvalue.RDFDatetime.Now())
        ]

      # We only update indexes if the schema does not forbid it and we are not
      # sure that the object already exists.
      add_child_index = self.Schema.ADD_CHILD_INDEX
      if self.object_exists:
        add_child_index = False

      # Write the attributes to the Factory cache.
      FACTORY.SetAttributes(
          self.urn,
          to_set,
          self._to_delete,
          add_child_index=add_child_index,
          mutation_pool=self.mutation_pool)
768602
function attributeData(node) {
    var store = {}
    $.each(node.attributes || emptyArray, function(i, attr){
      if (attr.name.indexOf('data-') == 0)
        store[camelize(attr.name.replace('data-', ''))] =
          $.zepto.deserializeValue(attr.value)
    })
    return store
  }
179935
void serializeNode(OutputArchive oa, StringBuilder path) throws IOException {
        String pathString = path.toString();
        DataNode node = getNode(pathString);
        if (node == null) {
            return;
        }
        String children[] = null;
        synchronized (node) {
            scount++;
            oa.writeString(pathString, "path");
            oa.writeRecord(node, "node");
            Set<String> childs = node.getChildren();
            if (childs != null) {
                children = childs.toArray(new String[childs.size()]);
            }
        }
        path.append('/');
        int off = path.length();
        if (children != null) {
            for (String child : children) {
                // since this is single buffer being resused
                // we need
                // to truncate the previous bytes of string.
                path.delete(off, Integer.MAX_VALUE);
                path.append(child);
                serializeNode(oa, path);
            }
        }
    }
795221
def serialize_tags
      serialized = {}
      tags.each do |tag|
        serialized[tag.id] = tag.serialize_base
      end
      serialized
    end
380014
def serialize(self):
        
        expects = [exp.serialize() for exp in self.expects]
        converted_dict = {
            'id': self.id,
            'name': self.pretty_name,
            'raw_name': self.name,
            'doc': self.doc,
            'error': self.error,
            'skipped': self.skipped,
            'skip_reason': self.skip_reason,
            'execute_kwargs': self.safe_execute_kwargs,
            'metadata': self.metadata,
            'start': self.start_time,
            'end': self.end_time,
            'expects': expects,
            'success': self.success
        }
        return remove_empty_entries_from_dict(converted_dict)
188470
function Serialize (elem) {
  if (!(this instanceof Serialize))
    return new Serialize(elem)

  if (!elem || elem.nodeType !== Node.ELEMENT_NODE)
    throw TypeError('Serialize can only serialize element nodes.')

  var text = ''

  this.length = 0
  this.markups = []
  this.type = elem.nodeName.toLowerCase()

  // Automatically update the length when setting the text.
  Object.defineProperty(this, 'text', {
    configurable: true,
    enumerable: true,
    get: function () {
      return text
    },
    set: function (newText) {
      this.length = newText.length
      text = newText
    }
  })

  convert(elem, this)
}