コード例 #1
0
ファイル: cli.py プロジェクト: Christopher51773/fish
def form_tag_value_pairs(tags, options=None):
    fromFile = options and options.force    # overload -f
    pairs = []
    value = None
    for tag in tags:
        eqPos = tag.find('=')
        if eqPos == -1:
            if fromFile:
                if value is None:
                    value = fishbase.Dummy()
                    value.value = sys.stdin.read()
                    value.mime = options.mime or 'text/plain'
            pairs.append(TagValue(tag, value))
        else:
            t = tag[:eqPos]
            if fromFile:
                v = get_typed_tag_value_from_file(tag[eqPos + 1:], options)
            else:
                v = get_typed_tag_value(tag[eqPos + 1:])
            pairs.append(TagValue(t, v))
    return pairs
コード例 #2
0
ファイル: testfish.py プロジェクト: Christopher51773/fish
 def testTypedValueInterpretation(self):
     corrects = {
             u'TRUE': (True, bool),
             u'tRuE': (True, bool),
             u't': (True, bool),
             u'T': (True, bool),
             u'f': (False, bool),
             u'false': (False, bool),
             u'1': (1, int),
             u'+1': (1, int),
             u'-1': (-1, int),
             u'0': (0, int),
             u'+0': (0, int),
             u'-0': (0, int),
             u'123456789': (123456789, int),
             u'-987654321': (-987654321, int),
             u'011': (11, int),
             u'-011': (-11, int),
             u'3.14159': (float('3.14159'), float),
             u'-3.14159': (float('-3.14159'), float),
             u'.14159': (float('.14159'), float),
             u'-.14159': (float('-.14159'), float),
             u'"1"': ('1', unicode),
             u'DADGAD': ('DADGAD', unicode),
             u'': ('', unicode),
             u'1,300': ('1,300', unicode),
             u'.': ('.', unicode),
             u'+.': ('+.', unicode),
             u'-.': ('-.', unicode),
             u'+': ('+', unicode),
             u'-': ('-', unicode),
     }
     for s in corrects:
         target, targetType = corrects[s]
         v = fishlib.get_typed_tag_value(s)
         self.assertEqual((s, v), (s, target))
         self.assertEqual((s, type(v)), (s, targetType))