class RPMTest(unittest.TestCase): def setUp(self): self.rpm = RPM(file('tests/Eterm-0.9.3-5mdv2007.0.src.rpm')) self.rpm = StringIO('') def test_entries(self): description = '''Eterm is a color vt102 terminal emulator intended as a replacement for Xterm.\nIt is designed with a Freedom of Choice philosophy, leaving as much power,\nflexibility, and freedom as possible in the hands of the user.\n\nIt is designed to look good and work well, but takes a feature-rich approach\nrather than one of minimalism while still maintaining speed and efficiency.\n\nIt works on any windowmanager/desktop environment, although it is designed\nto work and integrate best with Enlightenment.''' self.assertEqual(self.rpm[rpmdefs.RPMTAG_NAME], 'Eterm') self.assertEqual(self.rpm[rpmdefs.RPMTAG_VERSION], '0.9.3') self.assertEqual(self.rpm[rpmdefs.RPMTAG_RELEASE], '5mdv2007.0') self.assertEqual(self.rpm[rpmdefs.RPMTAG_ARCH], 'i586') self.assertEqual(self.rpm[rpmdefs.RPMTAG_COPYRIGHT], 'BSD') self.assertEqual(self.rpm[rpmdefs.RPMTAG_DESCRIPTION], description) def test_package_type(self): self.assertEqual(self.rpm.binary, False) self.assertEqual(self.rpm.source, True) def test_name(self): self.assertEqual(self.rpm.name(), 'Eterm') def test_package(self): self.assertEqual(self.rpm.package(), 'Eterm-0.9.3') def test_filename(self): self.assertEqual(self.rpm.filename(), 'Eterm-0.9.3-5mdv2007.0.i586.src.rpm')
def _open(self, name, mode='rb'): try: f = self.model.objects.get(filename=name) except self.model.DoesNotExist: return None fh = StringIO(base64.b64decode(f.contents)) fh.name = name fh.mode = mode fh.size = f.size return files.File(fh)
def upload_store(self, environ, start_response, sid, slang, tlang): """add units from uploaded file to tmdb""" from cStringIO import StringIO from translate.storage import factory start_response("200 OK", [('Content-type', 'text/plain')]) data = StringIO(environ['wsgi.input'].read(int(environ['CONTENT_LENGTH']))) data.name = sid store = factory.getobject(data) count = self.tmdb.add_store(store, slang, tlang) response = "added %d units from %s" % (count, sid) return [response]
def upload_store(self, environ, start_response, sid, slang, tlang): """add units from uploaded file to tmdb""" from cStringIO import StringIO from translate.storage import factory start_response("200 OK", [('Content-type', 'text/plain')]) data = StringIO(environ['wsgi.input'].read( int(environ['CONTENT_LENGTH']))) data.name = sid store = factory.getobject(data) count = self.tmdb.add_store(store, slang, tlang) response = "added %d units from %s" % (count, sid) return [response]
def get_attachment(self, msg, attach_id): "Get and return an attachment" num = 0 attach_id = int(attach_id) for part in msg.walk(): attachment = part.get_param('attachment', NOTFOUND, 'Content-Disposition') if not attachment is NOTFOUND: filename = part.get_filename(None) if filename: filename = filename.replace(' ', '_') num += 1 if attach_id == num: if part.is_multipart(): data = part.as_string() else: data = part.get_payload(decode=True) attachment = StringIO(data) attachment.content_type = part.get_content_type() attachment.size = len(data) attachment.name = filename return attachment return None