Empties `doc_string` field on any nested protobuf messages
183614
def strip_doc_string(proto):  # type: (google.protobuf.message.Message) -> None
    
    assert isinstance(proto, google.protobuf.message.Message)
    for descriptor in proto.DESCRIPTOR.fields:
        if descriptor.name == 'doc_string':
            proto.ClearField(descriptor.name)
        elif descriptor.type == descriptor.TYPE_MESSAGE:
            if descriptor.label == descriptor.LABEL_REPEATED:
                for x in getattr(proto, descriptor.name):
                    strip_doc_string(x)
            elif proto.HasField(descriptor.name):
                strip_doc_string(getattr(proto, descriptor.name))
779013
def _ExtractSymbols(desc_proto, package):
  

  message_name = '.'.join((package, desc_proto.name))
  yield message_name
  for nested_type in desc_proto.nested_type:
    for symbol in _ExtractSymbols(nested_type, message_name):
      yield symbol
  for enum_type in desc_proto.enum_type:
    yield '.'.join((message_name, enum_type.name))
173021
def MessageToJson(message, include_fields=None):
    """"""
    result = _ProtoJsonApiTools.Get().encode_message(message)
    return _IncludeFields(result, message, include_fields)
79392
function empty() {
  return {
    language: null,
    extendedLanguageSubtags: [],
    script: null,
    region: null,
    variants: [],
    extensions: [],
    privateuse: [],
    irregular: null,
    regular: null
  }
}
265116
private static boolean isEmpty(MsgNode msg) {
    for (SoyNode child : msg.getChildren()) {
      if (child instanceof RawTextNode && ((RawTextNode) child).getRawText().isEmpty()) {
        continue;
      }
      return false;
    }
    return true;
  }
1183357
def send_empty(self, message):
        
        host, port = message.destination
        key_token = hash(str(host) + str(port) + str(message.token))
        if key_token in self._relations and message.type == defines.Types["RST"]:
            del self._relations[key_token]
        return message
403730
def _clear_ignore(endpoint_props):
    '''
    
    '''
    return dict(
        (prop_name, prop_val)
        for prop_name, prop_val in six.iteritems(endpoint_props)
        if prop_name not in _DO_NOT_COMPARE_FIELDS and prop_val is not None
    )
1062944
def fromstring(cls, ptb_string, namespace='ptb', precedence=False,
                  ignore_traces=True):
        """"""
        temp = tempfile.NamedTemporaryFile(delete=False)
        temp.write(ptb_string)
        temp.close()
        ptb_docgraph = cls(ptb_filepath=temp.name, namespace=namespace,
                           precedence=precedence, ignore_traces=ignore_traces)
        os.unlink(temp.name)
        return ptb_docgraph
1163145
private void appendMutableGetters(JMessage message, JField field) throws GeneratorException {
        if (field.field().getDescriptor() instanceof PPrimitive ||
            field.type() == PType.ENUM) {
            // The other fields will have ordinary non-mutable getters.
            appendGetter(field);
            return;
        }

        BlockCommentBuilder comment = new BlockCommentBuilder(writer);
        comment.commentRaw("Get the builder for the contained <code>" + field.name() + "</code> message field.");
        if (field.hasComment()) {
            comment.paragraph()
                   .comment(field.comment());
        }
        comment.newline()
               .return_("The field message builder");
        if (JAnnotation.isDeprecated(field)) {
            String reason = field.field().getAnnotationValue(ThriftAnnotation.DEPRECATED);
            if (reason != null && reason.trim().length() > 0) {
                comment.deprecated_(reason);
            }
        }
        comment.finish();
        if (JAnnotation.isDeprecated(field)) {
            writer.appendln(JAnnotation.DEPRECATED);
        }
        writer.appendln(JAnnotation.NON_NULL);
        switch (field.type()) {
            case MESSAGE: {
                writer.formatln("public %s._Builder %s() {", field.instanceType(), field.mutable())
                      .begin();

                if (message.isUnion()) {
                    writer.formatln("if (%s != _Field.%s) {", UNION_FIELD, field.fieldEnum())
                          .formatln("    %s();", field.resetter())
                          .appendln('}')
                          .formatln("%s = _Field.%s;", UNION_FIELD, field.fieldEnum());
                    writer.appendln("modified = true;");
                } else {
                    writer.formatln("optionals.set(%d);", field.index());
                    writer.formatln("modified.set(%d);", field.index());
                }

                writer.newline()
                      .formatln("if (%s != null) {", field.member())
                      .formatln("    %s_builder = %s.mutate();", field.member(), field.member())
                      .formatln("    %s = null;", field.member())
                      .formatln("} else if (%s_builder == null) {", field.member())
                      .formatln("    %s_builder = %s.builder();", field.member(), field.instanceType())
                      .appendln('}')
                      .formatln("return %s_builder;", field.member());

                writer.end()
                      .appendln('}')
                      .newline();

                // Also add "normal" getter for the message field, which will
                // return the message or the builder dependent on which is set.
                // It will not change the state of the builder.
                comment = new BlockCommentBuilder(writer);
                if (field.hasComment()) {
                    comment.comment(field.comment())
                           .newline();
                }
                comment.return_("The field value");
                if (JAnnotation.isDeprecated(field)) {
                    String reason = field.field().getAnnotationValue(ThriftAnnotation.DEPRECATED);
                    if (reason != null && reason.trim().length() > 0) {
                        comment.deprecated_(reason);
                    }
                }
                comment.finish();
                if (JAnnotation.isDeprecated(field)) {
                    writer.appendln(JAnnotation.DEPRECATED);
                }
                writer.formatln("public %s %s() {", field.instanceType(), field.getter())
                      .begin();

                if (message.isUnion()) {
                    writer.formatln("if (%s != _Field.%s) {", UNION_FIELD, field.fieldEnum())
                          .formatln("    return null;")
                          .appendln('}');
                }

                writer.newline()
                      .formatln("if (%s_builder != null) {", field.member())
                      .formatln("    return %s_builder.build();", field.member())
                      .appendln('}')
                      .formatln("return %s;", field.member());

                writer.end()
                      .appendln('}')
                      .newline();
                break;
            }
            case SET:
            case LIST:
            case MAP:
                comment = new BlockCommentBuilder(writer);
                if (field.hasComment()) {
                    comment.comment(field.comment())
                           .newline();
                }
                comment.return_("The mutable <code>" + field.name() + "</code> container");
                if (JAnnotation.isDeprecated(field)) {
                    String reason = field.field().getAnnotationValue(ThriftAnnotation.DEPRECATED);
                    if (reason != null && reason.trim().length() > 0) {
                        comment.deprecated_(reason);
                    }
                }
                comment.finish();
                if (JAnnotation.isDeprecated(field)) {
                    writer.appendln(JAnnotation.DEPRECATED);
                }
                writer.formatln("public %s %s() {", field.fieldType(), field.mutable())
                      .begin();

                if (message.isUnion()) {
                    writer.formatln("if (%s != _Field.%s) {", UNION_FIELD, field.fieldEnum())
                          .formatln("    %s();", field.resetter())
                          .appendln('}')
                          .formatln("%s = _Field.%s;", UNION_FIELD, field.fieldEnum());
                    writer.appendln("modified = true;");
                } else {
                    writer.formatln("optionals.set(%d);", field.index());
                    writer.formatln("modified.set(%d);", field.index());
                }
                writer.newline()
                      .formatln("if (%s == null) {", field.member())
                      .formatln("    %s = new %s<>();", field.member(), field.builderMutableType())
                      .formatln("} else if (!(%s instanceof %s)) {", field.member(), field.builderMutableType())
                      .formatln("    %s = new %s<>(%s);", field.member(), field.builderMutableType(), field.member())
                      .appendln("}");

                writer.formatln("return %s;", field.member());

                writer.end()
                      .appendln('}')
                      .newline();
                break;
            default:
                throw new GeneratorException("Unexpected field type: " + field.type());
        }
    }
1251358
def _EncodeUnknownFields(message):
    """"""
    source = _UNRECOGNIZED_FIELD_MAPPINGS.get(type(message))
    if source is None:
        return message
    # CopyProtoMessage uses _ProtoJsonApiTools, which uses this message. Use
    # the vanilla protojson-based copy function to avoid infinite recursion.
    result = _CopyProtoMessageVanillaProtoJson(message)
    pairs_field = message.field_by_name(source)
    if not isinstance(pairs_field, messages.MessageField):
        raise exceptions.InvalidUserInputError(
            'Invalid pairs field %s' % pairs_field)
    pairs_type = pairs_field.message_type
    value_field = pairs_type.field_by_name('value')
    value_variant = value_field.variant
    pairs = getattr(message, source)
    codec = _ProtoJsonApiTools.Get()
    for pair in pairs:
        encoded_value = codec.encode_field(value_field, pair.value)
        result.set_unrecognized_field(pair.key, encoded_value, value_variant)
    setattr(result, source, [])
    return result
298843
def traverse(proto_file):
    
    def _collapse_comments(comments):
        return '\n'.join(
            [c.strip() for c in (comments["leading_comments"] + comments["trailing_comments"]).split('\n')])

    def _traverse(package, items, tree):
        for item_index, item in enumerate(items):
            item = convert_protodef_to_editable(item)
            if item_index in tree:
                comments = tree[item_index]
                if "leading_comments" in comments or "trailing_comments" in comments:
                    item.comment = _collapse_comments(comments)
                    del comments["leading_comments"]
                    del comments["trailing_comments"]
                if item.kind is EnumDescriptorProto:
                    if 2 in comments: # value in EnumDescriptorProto
                        for k in comments[2]:
                            value_comment = comments[2][k]
                            if value_comment != {}:
                                item.value[k].comment = _collapse_comments(value_comment)
                elif item.kind is DescriptorProto:
                    if 2 in comments: # field in DescriptorProto
                        for k in comments[2]:
                            field_comment = comments[2][k]
                            if field_comment != {}:
                                item.field[k].comment = _collapse_comments(field_comment)
                elif item.kind is ServiceDescriptorProto:
                    if 2 in comments: # method in ServiceDescriptorProto
                        for k in comments[2]:
                            method_comment = comments[2][k]
                            if method_comment != {}:
                                item.method[k].comment = _collapse_comments(method_comment)
                else:
                    raise Exception, item.kind

            yield item, package

            if item.kind is DescriptorProto:
                for enum in item.enum_type:
                    yield enum, package

                for nested in item.nested_type:
                    nested_package = package + "." + item.name

                    for nested_item, np in _traverse(nested_package, [nested], tree[item_index]):
                        yield nested_item, np

    tree = collections.defaultdict(collections.defaultdict)
    for loc in proto_file.source_code_info.location:
        if loc.leading_comments or loc.trailing_comments:
            place = tree
            for p in loc.path:
                if not place.has_key(p):
                    place[p] = collections.defaultdict(collections.defaultdict)
                place = place[p]
            place["leading_comments"] = loc.leading_comments
            place["trailing_comments"] = loc.trailing_comments
    
    # Only message, services, enums, extensions, options
    if set(tree.keys()).difference(set([4, 5, 6, 7, 8])) != set():
        raise Exception, tree

    return {"types":
        list(itertools.chain(
            _traverse(proto_file.package, proto_file.service, tree[6]), # 6 is service_type in FileDescriptorProto
            _traverse(proto_file.package, proto_file.enum_type, tree[5]), # 5 is enum_type in FileDescriptorProto
            _traverse(proto_file.package, proto_file.message_type, tree[4]), # 4 is message_type in FileDescriptorProto
        )),
        "file": ["".join(x.leading_detached_comments) for x in proto_file.source_code_info.location if len(x.leading_detached_comments) > 0]
    }
406744
def dump_all(documents, stream=None, Dumper=Dumper,
        default_style=None, default_flow_style=None,
        canonical=None, indent=None, width=None,
        allow_unicode=None, line_break=None,
        encoding='utf-8', explicit_start=None, explicit_end=None,
        version=None, tags=None):
    
    getvalue = None
    if stream is None:
        if encoding is None:
            from StringIO import StringIO
        else:
            from cStringIO import StringIO
        stream = StringIO()
        getvalue = stream.getvalue
    dumper = Dumper(stream, default_style=default_style,
            default_flow_style=default_flow_style,
            canonical=canonical, indent=indent, width=width,
            allow_unicode=allow_unicode, line_break=line_break,
            encoding=encoding, version=version, tags=tags,
            explicit_start=explicit_start, explicit_end=explicit_end)
    try:
        dumper.open()
        for data in documents:
            dumper.represent(data)
        dumper.close()
    finally:
        dumper.dispose()
    if getvalue:
        return getvalue()
1199868
def remove_empties(variable):
    """"""
    import h5py
    for key, val in variable.attrs.items():
        if isinstance(val, h5py._hl.base.Empty):
            variable.attrs.pop(key)

    return variable
684214
def emptyElement(self, name, attrs):
        """"""
        attr = ' '.join('%s=%s' % (n, quoteattr(scientificformat(v)))
                        for n, v in sorted(attrs.items()))
        self._write('<%s %s/>' % (name, attr))
197606
def _clean_fields(self, omit_fields, sparse_fields, next_level_omits):
        
        sparse = len(sparse_fields) > 0
        to_remove = []

        if not sparse and len(omit_fields) == 0:
            return

        for field_name in self.fields:
            is_present = self._should_field_exist(
                field_name, omit_fields, sparse_fields, next_level_omits
            )

            if not is_present:
                to_remove.append(field_name)

        for remove_field in to_remove:
            self.fields.pop(remove_field)
1105517
private String enrichMarkdown(String message, JsonNode entitiesNode, JsonNode mediaNode) throws InvalidInputException {

    TreeMap<Integer, JsonNode> entities = new TreeMap<>();
    TreeMap<Integer, JsonNode> media = new TreeMap<>();

    if (entitiesNode != null) {
      validateEntities(entitiesNode);
      for (JsonNode node : entitiesNode.findParents(INDEX_START)) {
        entities.put(node.get(INDEX_START).intValue(), node);
      }
    }

    if (mediaNode != null) {
      validateMedia(mediaNode);
      for (JsonNode node : mediaNode.findParents(INDEX)) {
        media.put(node.get(INDEX).intValue(), node.get(TEXT));
      }
    }

    // If entity indices are outside the message, pad the message to the necessary length
    int lastIndex = Math.max((!entities.isEmpty()) ? entities.lastKey() : 0, (!media.isEmpty()) ? media.lastKey() : 0);
    if (message.length() <= lastIndex) {
      message = StringUtils.rightPad(message, lastIndex + 1);
    }

    StringBuilder output = new StringBuilder();

    for (int i = 0; i < message.length(); i++) {
      char c = message.charAt(i);

      if (entities.containsKey(i)) {
        JsonNode entity = entities.get(i);
        String entityType = entity.get(TYPE).asText().toUpperCase();
        String id = entity.get(ID).asText();

        output.append(ENTITY_DELIMITER);
        output.append(entityType).append(FIELD_DELIMITER);
        output.append(id);
        output.append(ENTITY_DELIMITER);

        // We explicitly check the entity indices above, but make double sure that we don't get into an infinite loop here
        int endIndex = entity.get(INDEX_END).intValue() - 1;
        i = Math.max(endIndex, i);

      } else if (media.containsKey(i)) {
        JsonNode table = media.get(i);

        output.append(ENTITY_DELIMITER);
        output.append(TABLE).append(FIELD_DELIMITER);
        for (JsonNode row : table) {
          for (JsonNode cell : row) {
            String text = cell.asText();
            output.append(text).append(RECORD_DELIMITER);
          }
          output.append(GROUP_DELIMITER);
        }
        output.append(ENTITY_DELIMITER);
        output.append(c);
      } else {
        output.append(c);
      }
    }

    return output.toString();
  }
396509
def _clear_empty_values(args):
    '''
    
    '''
    result = {}
    for param in args:
        if args[param] is not None:
            result[param] = args[param]
    return result