Design a query based on the given WMIObject to extract a tag.

        Returns: tag or TagQueryUniquenessFailure exception.
518429
def _get_tag_query_tag(self, sampler, wmi_obj, tag_query):
        
        self.log.debug(
            u"`tag_queries` parameter found."
            " wmi_object={wmi_obj} - query={tag_query}".format(wmi_obj=wmi_obj, tag_query=tag_query)
        )

        # Extract query information
        target_class, target_property, filters = self._format_tag_query(sampler, wmi_obj, tag_query)

        # Create a specific sampler
        tag_query_sampler = WMISampler(self.log, target_class, [target_property], filters=filters, **sampler.connection)

        tag_query_sampler.sample()

        # Extract tag
        self._raise_on_invalid_tag_query_result(tag_query_sampler, wmi_obj, tag_query)

        link_value = str(tag_query_sampler[0][target_property]).lower()

        tag = "{tag_name}:{tag_value}".format(tag_name=target_property.lower(), tag_value="_".join(link_value.split()))

        self.log.debug(u"Extracted `tag_queries` tag: '{tag}'".format(tag=tag))
        return tag
1141090
def find_by_tag(self, tag) -> Dict[str, Set[Parameter]]:
        
        return self.tags[tag]
798138
def by_tag_id(self,tag_id):
		'''

		'''
		query = meta.Session.query(TagSemanticTag).filter(TagSemanticTag.tag_id==tag_id)
		return query.first()
763141
private ITag readTagHeader() throws UnsupportedDataTypeException {
        // previous tag size (4 bytes) + flv tag header size (11 bytes)
        fillBuffer(15);
        // previous tag's size
        int previousTagSize = in.getInt();
        // start of the flv tag
        byte dataType = in.get();
        if (log.isTraceEnabled()) {
            log.trace("Bits: {}", Integer.toBinaryString(dataType));
        }
        dataType = (byte) (dataType & 31);
        byte filter = (byte) ((dataType & 63) >> 5);
        byte reserved = (byte) ((dataType & 127) >> 6);
        log.debug("Reserved: {}, Filter: {}, Datatype: {}", reserved, filter, dataType);
        switch (dataType) {
            case 8: // audio
                log.debug("Found audio");
                break;
            case 9: // video
                log.debug("Found video");
                break;
            case 15: // special fms undocumented type?
            case 18: // meta / script data
                log.debug("Found meta/script data");
                break;
            default:
                log.debug("Invalid data type detected ({}), reading ahead\n current position: {} limit: {}", dataType, in.position(), in.limit());
                throw new UnsupportedDataTypeException("Invalid data type detected (" + dataType + ")");
        }
        int bodySize = IOUtils.readUnsignedMediumInt(in);
        int timestamp = IOUtils.readExtendedMediumInt(in);
        int streamId = IOUtils.readUnsignedMediumInt(in);
        if (log.isDebugEnabled()) {
            log.debug("Data type: {} timestamp: {} stream id: {} body size: {} previous tag size: {}", new Object[] { dataType, timestamp, streamId, bodySize, previousTagSize });
        }
        return new Tag(dataType, timestamp, bodySize, null, previousTagSize);
    }
415287
def find_by_tag(self, tag, params={}, **options): 
        
        path = "/tags/%s/tasks" % (tag)
        return self.client.get_collection(path, params, **options)
180008
def query_by_entity_uid(idd, kind=''):
        '''
        
        '''

        if kind == '':
            return TabPost2Tag.select(
                TabPost2Tag,
                TabTag.slug.alias('tag_slug'),
                TabTag.name.alias('tag_name')
            ).join(
                TabTag, on=(TabPost2Tag.tag_id == TabTag.uid)
            ).where(
                (TabPost2Tag.post_id == idd) &
                (TabTag.kind != 'z')
            ).order_by(
                TabPost2Tag.order
            )
        return TabPost2Tag.select(
            TabPost2Tag,
            TabTag.slug.alias('tag_slug'),
            TabTag.name.alias('tag_name')
        ).join(TabTag, on=(TabPost2Tag.tag_id == TabTag.uid)).where(
            (TabTag.kind == kind) &
            (TabPost2Tag.post_id == idd)
        ).order_by(
            TabPost2Tag.order
        )
473428
def get_tag(tag_type)
      matches = @tags.select { |m| m.type==tag_type }
      return matches.first
    end
891356
def _expand_tag_query(self, query, table_name = None):
        

        where = unicode()
        opt = list()

        # handle table name, can be None
        if table_name is None:
            col_prefix = ""
        else:
            col_prefix = table_name + "."

        if type(query['val1']) == dict and type(query['val2']) == dict:
            # Sub expression, recurse! This is used for boolean operators: AND OR
            # add parantheses

            sub_where1, opt1 = self._expand_tag_query(query['val1'], table_name)
            sub_where2, opt2 = self._expand_tag_query(query['val2'], table_name)
            try:
                where += unicode(" (%s %s %s) " % (sub_where1, _operation_map[query['operator']], sub_where2) )
            except KeyError:
                raise NipapNoSuchOperatorError("No such operator %s" % unicode(query['operator']))

            opt += opt1
            opt += opt2

        else:

            # TODO: raise exception if someone passes one dict and one "something else"?

            # val1 is variable, val2 is string.
            tag_attr = dict()
            tag_attr['name'] = 'name'

            if query['val1'] not in tag_attr:
                raise NipapInputError('Search variable \'%s\' unknown' % unicode(query['val1']))

            # workaround for handling equal matches of NULL-values
            if query['operator'] == 'equals' and query['val2'] is None:
                query['operator'] = 'is'
            elif query['operator'] == 'not_equals' and query['val2'] is None:
                query['operator'] = 'is_not'

            # build where clause
            if query['operator'] not in _operation_map:
                raise NipapNoSuchOperatorError("No such operator %s" % query['operator'])

            where = unicode(" %s%s %s %%s " %
                ( col_prefix, tag_attr[query['val1']],
                _operation_map[query['operator']] )
            )

            opt.append(query['val2'])

        return where, opt
709579
def _get_tag(repo, name):
    '''
    
    '''
    try:
        return [x for x in _all_tags(repo) if x[0] == name][0]
    except IndexError:
        return False
48866
def filter_by_name_or_id_or_tag(self, query_string, queryset = None):
        
        assert self.Model.NAME_FIELD, \
            'NAME_FIELD is missing on model %s' % self.Model.__name__
        assert self.Model.ID_FIELD, \
            'ID_FIELD is missing on model %s' % self.Model.__name__
        assert self.Model.TAG_FIELD, \
            'TAG_FIELD is missing on model %s' % self.Model.__name__

        filter_args = {}
        name, uuid, tag = self._parse_as_name_or_id_or_tag(query_string)
        if name is not None:
            filter_args[self.Model.NAME_FIELD] = name
        if uuid is not None:
            filter_args[self.Model.ID_FIELD+'__startswith'] = uuid
        if tag is not None:
            filter_args[self.Model.TAG_FIELD] = tag
        if queryset is None:
            queryset = self.Model.objects.all()
        return queryset.filter(**filter_args)
1278967
def get_tag(self, name):
        """"""
        res = self.get_request('/tag/' + name)
        return Tag(cloud_manager=self, **res['tag'])
616467
def tags_impl(self):
    
    if self._db_connection_provider:
      # Read tags from the database.
      db = self._db_connection_provider()
      cursor = db.execute('''
        SELECT
          Tags.tag_name,
          Tags.display_name,
          Runs.run_name
        FROM Tags
        JOIN Runs
          ON Tags.run_id = Runs.run_id
        WHERE
          Tags.plugin_name = ?
      ''', (metadata.PLUGIN_NAME,))
      result = {}
      for (tag_name, display_name, run_name) in cursor:
        if run_name not in result:
          result[run_name] = {}
        result[run_name][tag_name] = {
            'displayName': display_name,
            # TODO(chihuahua): Populate the description. Currently, the tags
            # table does not link with the description table.
            'description': '',
        }
    else:
      # Read tags from events files.
      runs = self._multiplexer.Runs()
      result = {run: {} for run in runs}

      mapping = self._multiplexer.PluginRunToTagToContent(metadata.PLUGIN_NAME)
      for (run, tag_to_content) in six.iteritems(mapping):
        for (tag, _) in six.iteritems(tag_to_content):
          summary_metadata = self._multiplexer.SummaryMetadata(run, tag)
          result[run][tag] = {'displayName': summary_metadata.display_name,
                              'description': plugin_util.markdown_to_safe_html(
                                  summary_metadata.summary_description)}

    return result
787480
def __query(self, query, tagid=None):
        
        if self.encrypted:
            document = self.decrypted_document
        else:
            document = self.document
        return OneLogin_Saml2_XML.query(document, query, None, tagid)
996209
private void writeTagValue(TagValue tag) throws IOException {
    int id = tag.getId();

    // Write tag value
    for (abstractTiffType tt : tag.getValue()) {
      if (id == 700) {
        // XMP
        XMP xmp = (XMP)tt;
        try {
          xmp.write(data);
        }catch (Exception ex) {
          XmlType xml = (XmlType)tt;
          try {
            xml.writeXml(data);
          } catch (Exception exx) {
            exx.printStackTrace();
            throw new IOException();
          }
        }
      } else if (id == 33723) {
        // IPTC
        abstractTiffType att = tag.getValue().get(0);
        if (att instanceof IPTC) {
          IPTC iptc = (IPTC) att;
          iptc.write(data);
          //for (int i = 0; i < iptc.getOriginal().size(); i++) data.put(iptc.getOriginal().get(i).toByte());
          //data.put((byte) 0);
        } else {
          for (int i = 0; i < tag.getValue().size(); i++) {
            data.put(tag.getValue().get(i).toByte());
          }
          data.put((byte) 0);
        }
      } else if (id == 330) {
        // SubIFD
        IFD subifd = ((IFD) tag.getValue().get(0));
        writeIFD(subifd);
      } else if (id == 34665) {
        // EXIF
        IFD exif = (IFD) tag.getValue().get(0);
        writeIFD(exif);
      } else if (id == 34675) {
        // ICC
        for (int off = tag.getReadOffset(); off < tag.getReadOffset() + tag.getReadlength(); off++) {
          data.put(input.readByte(off).toByte());
        }
        data.put((byte) 0);
      } else {
        switch (tag.getType()) {
          case 3:
            data.putShort((short) tt.toInt());
            break;
          case 8:
            data.putSShort((SShort) tt);
            break;
          case 4:
            data.putLong((Long) tt);
            break;
          case 9:
            data.putSLong((SLong) tt);
            break;
          case 11:
            data.putFloat((Float) tt);
            break;
          case 13:
            data.putInt(tt.toInt());
            break;
          case 5:
            data.putRational((Rational) tt);
            break;
          case 10:
            data.putSRational((SRational) tt);
            break;
          case 12:
            data.putDouble((Double) tt);
            break;
          case 2:
            data.put(tt.toByte());
            break;
          default:
            data.put(tt.toByte());
            break;
        }
      }
    }
  }
1233031
function selectorTagNameSpy(results, tagName) {
        var context = phantomas.getDOMPath(this);

        // querying by BODY and body is the same (issue #419)
        tagName = tagName.toLowerCase();

        phantomas.incrMetric('DOMqueriesByTagName');
        phantomas.addOffender('DOMqueriesByTagName', {tag: tagName, node: phantomas.getDOMPath(this)});
        querySpy('tag name', tagName, 'getElementsByTagName', context, (results.length === 0));
    }
887517
def _get_wmi_properties(self, instance_key, metrics, tag_queries):
        
        if instance_key not in self.wmi_props:
            metric_name_by_property = dict(
                (wmi_property.lower(), (metric_name, metric_type)) for wmi_property, metric_name, metric_type in metrics
            )
            properties = map(lambda x: x[0], metrics + tag_queries)
            self.wmi_props[instance_key] = (metric_name_by_property, properties)

        return self.wmi_props[instance_key]
1253705
def get_database_tag(self):
        '''
        
        '''

        def parse_response(doc):
            self._database_tag = doc['tag']
            return self._database_tag

        def create_new(fail):
            fail.trap(NotFoundError)
            doc = {'_id': doc_id, 'tag': unicode(uuid.uuid1())}
            return self.save_document(doc)

        def conflict_handler(fail):
            fail.trap(ConflictError)
            return self.get_database_tag()


        if not hasattr(self, '_database_tag'):
            doc_id = u'_local/database_tag'
            d = self.get_document(doc_id)
            d.addErrback(create_new)
            d.addErrback(conflict_handler)
            d.addCallback(parse_response)
            return d
        else:
            return defer.succeed(self._database_tag)