Exemplo n.º 1
0
def format_who_when(fields):
    """Format a tuple of name,email,secs-since-epoch,utc-offset-secs as a string."""
    offset = fields[3]
    if offset < 0:
        offset_sign = b'-'
        offset = abs(offset)
    else:
        offset_sign = b'+'
    offset_hours = offset // 3600
    offset_minutes = offset // 60 - offset_hours * 60
    offset_str = offset_sign + ('%02d%02d' %
                                (offset_hours, offset_minutes)).encode('ascii')
    name = fields[0]

    if name == b'':
        sep = b''
    else:
        sep = b' '

    name = utf8_bytes_string(name)

    email = fields[1]

    email = utf8_bytes_string(email)

    return b''.join((name, sep, b'<', email, b'> ',
                     ("%d" % fields[2]).encode('ascii'), b' ', offset_str))
Exemplo n.º 2
0
def format_who_when(fields):
    """Format a tuple of name,email,secs-since-epoch,utc-offset-secs as a string."""
    offset = fields[3]
    if offset < 0:
        offset_sign = b'-'
        offset = abs(offset)
    else:
        offset_sign = b'+'
    offset_hours = offset // 3600
    offset_minutes = offset // 60 - offset_hours * 60
    offset_str = offset_sign + ('%02d%02d' % (offset_hours, offset_minutes)).encode('ascii')
    name = fields[0]

    if name == b'':
        sep = b''
    else:
        sep = b' '

    name = utf8_bytes_string(name)

    email = fields[1]

    email = utf8_bytes_string(email)

    return b''.join((name, sep, b'<', email, b'> ', ("%d" % fields[2]).encode('ascii'), b' ', offset_str))
Exemplo n.º 3
0
def format_property(name, value):
    """Format the name and value (both unicode) of a property as a string."""
    result = b''
    utf8_name = utf8_bytes_string(name)

    result = b'property ' + utf8_name
    if value is not None:
        utf8_value = utf8_bytes_string(value)
        result += b' ' + ('%d' % len(utf8_value)).encode('ascii') + b' ' + utf8_value

    return result
Exemplo n.º 4
0
def format_property(name, value):
    """Format the name and value (both unicode) of a property as a string."""
    result = b''
    utf8_name = utf8_bytes_string(name)

    result = b'property ' + utf8_name
    if value is not None:
        utf8_value = utf8_bytes_string(value)
        result += b' ' + ('%d' %
                          len(utf8_value)).encode('ascii') + b' ' + utf8_value

    return result
Exemplo n.º 5
0
    def test_commit_unicode_committer(self):
        # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
        name = u'\u013d\xf3r\xe9m \xcdp\u0161\xfam'

        commit_utf8 = utf8_bytes_string(
            u"commit refs/heads/master\n"
            u"mark :bbb\n"
            u"committer %s <*****@*****.**> 1234567890 -0600\n"
            u"data 12\n"
            u"release v1.0\n"
            u"from :aaa" % (name, ))

        committer = (name, b'*****@*****.**', 1234567890, -6 * 3600)
        c = commands.CommitCommand(b'refs/heads/master', b'bbb', None,
                                   committer, b'release v1.0', b':aaa', None,
                                   None)

        self.assertEqual(commit_utf8, bytes(c))
Exemplo n.º 6
0
    def test_commit_unicode_committer(self):
        # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
        name = u'\u013d\xf3r\xe9m \xcdp\u0161\xfam'

        commit_utf8 = utf8_bytes_string(
            u"commit refs/heads/master\n"
            u"mark :bbb\n"
            u"committer %s <*****@*****.**> 1234567890 -0600\n"
            u"data 12\n"
            u"release v1.0\n"
            u"from :aaa" % (name,)
        )

        committer = (name, b'*****@*****.**', 1234567890, -6 * 3600)
        c = commands.CommitCommand(b'refs/heads/master', b'bbb', None, committer,
            b'release v1.0', b':aaa', None, None)

        self.assertEqual(commit_utf8, repr_bytes(c))
Exemplo n.º 7
0
 def decode_match(match):
     return utf8_bytes_string(
         codecs.decode(match.group(0), 'unicode-escape'))
Exemplo n.º 8
0
 def decode_match(match):
      return utf8_bytes_string(
           codecs.decode(match.group(0), 'unicode-escape')
      )