Example #1
0
 def _makeparams(self):
     params = [utils.escape('%s:@"%s"' % target) for target in
               self._target.items()]
     param = Expression.OR.join(params)
     exprs = [utils.escape(self._makeexpr(expr)) for expr in self._expr]
     expr = Expression.OR.join(exprs)
     result = param and '(%s)' % param
     if result and expr:
         result += Expression.AND
     result += expr
     return '--query "%s"' % result if result else ''
Example #2
0
 def _makeparams(self):
     params = ['%s:@%s' % (k, utils.escape(v, True)) for k, v in
               sorted(self._target.items())]
     op = QueryExpression.operator[Operator.BIT_OR]
     param = op.join(params)
     expr = op.join(expr.build(QueryExpression) for expr in self._exprs)
     result = param and '(%s)' % param
     if result and expr:
         result += QueryExpression.operator[Operator.BIT_AND]
     result += expr
     return '--query %s' % utils.escape(result, True) if result else ''
Example #3
0
 def __str__(self):
     value = self.value
     if value is True:
         expr_str = 'true'
     elif value is False:
         expr_str = 'false'
     elif value is None:
         expr_str = 'null'
     elif isinstance(value, (datetime, date)):
         expr_str = utils.escape(value.strftime('%Y/%m/%d %H:%M:%S.%f'))
     else:
         expr_str = utils.escape(utils.to_text(value))
     # TODO: Geo point, Array
     return expr_str
Example #4
0
 def _make_match_columns(self):
     if self._match_columns:
         exprs = (e.build(MatchColumn) for e in self._match_columns)
         result = MatchColumn.operator[Operator.OR].join(exprs)
         return '--match_columns %s' % utils.escape(result, True)
     else:
         return ''
Example #5
0
 def __str__(self):
     return ' '.join((
         'load',
         '--table', self._table.__tablename__,
         '--input_type', 'json',
         '--each',
         "'suggest_preparer(_id, type, item, sequence, time, pair_query)'",
         utils.escape(self._makejson(), True)))
Example #6
0
 def __str__(self):
     return ' '.join((
         'suggest',
         '--table', '"%s"' % self._table.__tablename__,
         '--column', '"%s"' % self._table.kana.name,
         '--types', '"%s"' % self._types,
         self._condition(),
         '--query', utils.escape(self._query, True)))
Example #7
0
 def __str__(self):
     return 'suggest --table "%(table)s" --column "%(column)s" --types ' \
             '"%(types)s" %(condition)s --query "%(query)s"' % \
             dict(table=self._table.__tablename__,
                  column=self._table.kana.name,
                  types=self._types,
                  condition=self._condition(),
                  query=utils.escape(self._query))
Example #8
0
    def delete(self, key=None, id=None, filter=None):
        """Get the 'delete' query

        :param table: Table class
        :param key: string of key of record, default is None
        :param id: string of id of record, default is None
        :param filter: instance of ExpressionTree or string of filter,
            default is None
        :returns: :class:`SimpleQuery` object
        """
        query = ['delete', '--table', self._table.__tablename__]
        if key is not None:
            query.extend(('--key', key))
        if id is not None:
            query.extend(('--id', str(id)))
        if filter is not None:
            query.extend(('--filter', utils.escape(str(filter), True)))
        self._query.extend(query)
        return self
Example #9
0
 def __str__(self):
     return ' '.join((
         'load',
         '--table', self._table.__tablename__,
         '--input-type', 'json',
         '--values', utils.escape(self._makejson(), True)))
Example #10
0
 def __str__(self):
     expr_str = utils.to_text(getattr(self.value, 'lvalue', self.value))
     return utils.escape(expr_str)
Example #11
0
 def _makefilters(self):
     if not self._filters:
         return ''
     exprs = (e.build(FilterExpression) for e in self._filters)
     result = FilterExpression.operator[Operator.OR].join(exprs)
     return '--filter %s' % utils.escape(result, True)
Example #12
0
 def _makejson(self):
     return utils.escape(json.dumps([v.asdict() for v in self._data]))
Example #13
0
def test_escape(values, expected):
    result = utils.escape(*values)
    assert result == expected