Skip to content

Commit 62d97b0

Browse files
author
Viktor Nagy
committed
Added support for python2.5.
The 'mystring'.format method was introduced in Python 2.6
1 parent 7f8ced6 commit 62d97b0

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

lucenequerybuilder/query.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,16 @@ def __str__(self):
180180
elif self.exrange is not None:
181181
rv = '{' + str(self.exrange[0]) + ' TO ' + str(self.exrange[1]) + '}'
182182
elif self.fuzzy:
183-
rv = '{0!s}~'.format(self.fuzzy[0])
183+
try:
184+
rv = '{0!s}~'.format(self.fuzzy[0])
185+
except AttributeError:
186+
rv = '%s~' % self.fuzzy[0]
184187
if self.fuzzy[1] is not None:
185-
rv += '{0:.3f}'.format(self.fuzzy[1])
188+
try:
189+
rv += '{0:.3f}'.format(self.fuzzy[1])
190+
except AttributeError:
191+
rv += '%.3f' % self.fuzzy[1]
192+
186193
else:
187194
rv = ''
188195
for o in self.must:
@@ -193,7 +200,10 @@ def __str__(self):
193200
rv += str(o)
194201

195202
if self.field is not None:
196-
rv = '{0}:({1})'.format(self.field, rv)
203+
try:
204+
rv = '{0}:({1})'.format(self.field, rv)
205+
except AttributeError:
206+
rv = '%s:(%s)' % (self.field, rv)
197207
return rv
198208

199209

@@ -214,9 +224,15 @@ def __unicode__(self):
214224
elif self.exrange is not None:
215225
rv = u'{' + unicode(self.exrange[0]) + u' TO ' + unicode(self.exrange[1]) + u'}'
216226
elif self.fuzzy:
217-
rv = u'{0!s}~'.format(self.fuzzy[0])
227+
try:
228+
rv = u'{0!s}~'.format(self.fuzzy[0])
229+
except AttributeError:
230+
rv = u'%s~' % self.fuzzy[0]
218231
if self.fuzzy[1] is not None:
219-
rv += u'{0:.3f}'.format(self.fuzzy[1])
232+
try:
233+
rv += '{0:.3f}'.format(self.fuzzy[1])
234+
except AttributeError:
235+
rv += '%.3f' % self.fuzzy[1]
220236
else:
221237
rv = u''
222238
for o in self.must:
@@ -227,5 +243,8 @@ def __unicode__(self):
227243
rv += unicode(o)
228244

229245
if self.field is not None:
230-
rv = u'{0}:({1})'.format(self.field, rv)
231-
return rv
246+
try:
247+
rv = u'{0}:({1})'.format(self.field, rv)
248+
except AttributeError:
249+
rv = u'%s:(%s)' % (self.field, rv)
250+
return rv

0 commit comments

Comments
 (0)