~ubuntu-branches/ubuntu/vivid/samba/vivid

« back to all changes in this revision

Viewing changes to lib/subunit/python/subunit/details.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2011-12-21 13:18:04 UTC
  • mfrom: (0.39.21 sid)
  • Revision ID: package-import@ubuntu.com-20111221131804-xtlr39wx6njehxxr
Tags: 2:3.6.1-3ubuntu1
* Merge from Debian testing.  Remaining changes:
  + debian/patches/VERSION.patch:
    - set SAMBA_VERSION_SUFFIX to Ubuntu.
  + debian/patches/error-trans.fix-276472:
    - Add the translation of Unix Error code -ENOTSUP to NT Error Code
    - NT_STATUS_NOT_SUPPORTED to prevent the Permission denied error.
  + debian/smb.conf:
    - add "(Samba, Ubuntu)" to server string.
    - comment out the default [homes] share, and add a comment about
      "valid users = %S" to show users how to restrict access to
      \\server\username to only username.
    - Set 'usershare allow guests', so that usershare admins are 
      allowed to create public shares in addition to authenticated
      ones.
    - add map to guest = Bad user, maps bad username to guest access.
  + debian/samba-common.config:
    - Do not change priority to high if dhclient3 is installed.
    - Use priority medium instead of high for the workgroup question.
  + debian/control:
    - Don't build against or suggest ctdb.
    - Add dependency on samba-common-bin to samba.
  + Add ufw integration:
    - Created debian/samba.ufw.profile
    - debian/rules, debian/samba.dirs, debian/samba.files: install
      profile
    - debian/control: have samba suggest ufw
  + Add apport hook:
    - Created debian/source_samba.py.
    - debian/rules, debian/samba.dirs, debian/samba-common-bin.files: install
  + Switch to upstart:
    - Add debian/samba.{nmbd,smbd}.upstart.
  + debian/samba.logrotate, debian/samba-common.dhcp, debian/samba.if-up:
    - Make them upstart compatible
  + debian/samba.postinst: 
    - Avoid scary pdbedit warnings on first import.
  + debian/samba-common.postinst: Add more informative error message for
    the case where smb.conf was manually deleted
  + debian/patches/fix-debuglevel-name-conflict.patch: don't use 'debug_level'
    as a global variable name in an NSS module 
  + Dropped:
    - debian/patches/error-trans.fix-276472
    - debian/patches/fix-debuglevel-name-conflict.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
#  subunit: extensions to Python unittest to get test results from subprocesses.
 
3
#  Copyright (C) 2005  Robert Collins <robertc@robertcollins.net>
 
4
#
 
5
#  Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
 
6
#  license at the users choice. A copy of both licenses are available in the
 
7
#  project source as Apache-2.0 and BSD. You may not use this file except in
 
8
#  compliance with one of these two licences.
 
9
#  
 
10
#  Unless required by applicable law or agreed to in writing, software
 
11
#  distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
 
12
#  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 
13
#  license you chose for the specific language governing permissions and
 
14
#  limitations under that license.
 
15
#
 
16
 
 
17
"""Handlers for outcome details."""
 
18
 
 
19
from cStringIO import StringIO
 
20
 
 
21
from testtools import content, content_type
 
22
 
 
23
import chunked
 
24
 
 
25
 
 
26
class DetailsParser(object):
 
27
    """Base class/API reference for details parsing."""
 
28
 
 
29
 
 
30
class SimpleDetailsParser(DetailsParser):
 
31
    """Parser for single-part [] delimited details."""
 
32
 
 
33
    def __init__(self, state):
 
34
        self._message = ""
 
35
        self._state = state
 
36
 
 
37
    def lineReceived(self, line):
 
38
        if line == "]\n":
 
39
            self._state.endDetails()
 
40
            return
 
41
        if line[0:2] == " ]":
 
42
            # quoted ] start
 
43
            self._message += line[1:]
 
44
        else:
 
45
            self._message += line
 
46
 
 
47
    def get_details(self, style=None):
 
48
        result = {}
 
49
        if not style:
 
50
            # We know that subunit/testtools serialise [] formatted
 
51
            # tracebacks as utf8, but perhaps we need a ReplacingContent
 
52
            # or something like that.
 
53
            result['traceback'] = content.Content(
 
54
                content_type.ContentType("text", "x-traceback",
 
55
                {"charset": "utf8"}),
 
56
                lambda:[self._message])
 
57
        else:
 
58
            if style == 'skip':
 
59
                name = 'reason'
 
60
            else:
 
61
                name = 'message'
 
62
            result[name] = content.Content(
 
63
                content_type.ContentType("text", "plain"),
 
64
                lambda:[self._message])
 
65
        return result
 
66
 
 
67
    def get_message(self):
 
68
        return self._message
 
69
 
 
70
 
 
71
class MultipartDetailsParser(DetailsParser):
 
72
    """Parser for multi-part [] surrounded MIME typed chunked details."""
 
73
 
 
74
    def __init__(self, state):
 
75
        self._state = state
 
76
        self._details = {}
 
77
        self._parse_state = self._look_for_content
 
78
 
 
79
    def _look_for_content(self, line):
 
80
        if line == "]\n":
 
81
            self._state.endDetails()
 
82
            return
 
83
        # TODO error handling
 
84
        field, value = line[:-1].split(' ', 1)
 
85
        main, sub = value.split('/')
 
86
        self._content_type = content_type.ContentType(main, sub)
 
87
        self._parse_state = self._get_name
 
88
 
 
89
    def _get_name(self, line):
 
90
        self._name = line[:-1]
 
91
        self._body = StringIO()
 
92
        self._chunk_parser = chunked.Decoder(self._body)
 
93
        self._parse_state = self._feed_chunks
 
94
 
 
95
    def _feed_chunks(self, line):
 
96
        residue = self._chunk_parser.write(line)
 
97
        if residue is not None:
 
98
            # Line based use always ends on no residue.
 
99
            assert residue == '', 'residue: %r' % (residue,)
 
100
            body = self._body
 
101
            self._details[self._name] = content.Content(
 
102
                self._content_type, lambda:[body.getvalue()])
 
103
            self._chunk_parser.close()
 
104
            self._parse_state = self._look_for_content
 
105
 
 
106
    def get_details(self, for_skip=False):
 
107
        return self._details
 
108
 
 
109
    def get_message(self):
 
110
        return None
 
111
 
 
112
    def lineReceived(self, line):
 
113
        self._parse_state(line)