Example #1
0
        def _upload(stuff):
            """assumes that SELECTOR_FOR_TEST_UPLOAD is a configured http server
            """
            selector = SELECTOR_FOR_TEST_UPLOAD
            basicAuth = BASIC_AUTH_CREDENTIALS

            # make a tmp dir just for testing:
            tmp = mkdtemp()
            filename = 'test.txt'
            tmp_filename = os.path.join(tmp, filename)
            f = open(tmp_filename, 'w+')
            f.write(stuff)
            f.close()

            # get local sha256 before cleanup:
            digest = hashlib.sha256()
            digest.update(open(tmp_filename).read())
            dgst = digest.hexdigest()

            # upload:
            status = web.upload(selector, tmp_filename, basicAuth, log=False)
            shutil.rmtree(tmp) # cleanup; do before asserts

            # test
            good_upload = True
            disgest_match = False
            if not status.startswith('success'):
                good_upload = False
            elif status.find(dgst) > -1:
                digest_match = True

            return int(status.split()[3]), good_upload, digest_match
Example #2
0
    def uploadReport(self, itemsList):
        """Pickle & upload data to psychopy.org"""
        tmp = tempfile.NamedTemporaryFile()
        pickle.dump(itemsList, tmp)
        tmp.flush()
        tmp.seek(0)

        # Upload the data:
        selector = 'http://upload.psychopy.org/benchmark/'
        basicAuth = 'psychopy:open-sourc-ami'
        status = web.upload(selector, tmp.name, basicAuth)
        tmp.close()  # vanishes

        return status
Example #3
0
 def uploadReport(self, itemsList):
     """Pickle & upload data to psychopy.org"""
     tmp = tempfile.NamedTemporaryFile()
     pickle.dump(itemsList, tmp)
     tmp.flush()
     tmp.seek(0)
     
     # Upload the data:
     selector = 'http://upload.psychopy.org/benchmark/'
     basicAuth = 'psychopy:open-sourc-ami'
     status = web.upload(selector, tmp.name, basicAuth)
     tmp.close()  # vanishes
     
     return status
Example #4
0
    def uploadReport(self, itemsList):
        """Pickle & upload data to psychopy.org

        Windows compatibility added by Sol Simpson (need a closed file)
        """

        tmp = tempfile.NamedTemporaryFile(delete=False)
        pickle.dump(itemsList, tmp)
        tmp.close()

        # Upload the data:
        selector = 'http://upload.psychopy.org/benchmark/'
        basicAuth = 'psychopy:open-sourc-ami'
        status = None
        try:
            status = web.upload(selector, tmp.name, basicAuth)
        except:
            status = "Exception occurred during web.upload"
        finally:
            os.unlink(tmp.name)
        return status
Example #5
0
    def uploadReport(self, itemsList):
        """Pickle & upload data to psychopy.org

        Windows compatibility added by Sol Simpson (need a closed file)
        """

        tmp = tempfile.NamedTemporaryFile(delete=False)
        pickle.dump(itemsList, tmp)
        tmp.close()

        # Upload the data:
        selector = 'http://upload.psychopy.org/benchmark/'
        basicAuth = 'psychopy:open-sourc-ami'
        status = None
        try:
            status = web.upload(selector, tmp.name, basicAuth)
        except:
            status = "Exception occurred during web.upload"
        finally:
            os.unlink(tmp.name)
        return status
Example #6
0
    def test_upload(self):
        selector = SELECTOR_FOR_TEST_UPLOAD
        selectorS = SELECTOR_FOR_TEST_UPLOAD.replace('http', 'https')
        selectorBad = selector = 'http://upload.psychopy.org/../../up.php'
        filename = __file__
        basicAuth = BASIC_AUTH_CREDENTIALS

        web.upload(selector, filename, basicAuth, log=False)
        web.upload(selectorS, filename, basicAuth, https=True, log=False)
        with pytest.raises(ValueError):
            web.upload(selectorS, filename, basicAuth, log=False)
        with pytest.raises(ValueError):
            web.upload(selector, filename, basicAuth, https=True, log=False)
        with pytest.raises(ValueError):
            web.upload('', filename, basicAuth, log=False)
        web.upload(selector + 'JUNK', filename, basicAuth, log=False)
        with pytest.raises(ValueError):
            web.upload(selector, filename + 'JUNK', basicAuth, log=False)
        web.upload(selector, filename, basicAuth + 'JUNK', log=False)
Example #7
0
#!/usr/bin/env python2
"""Illustrates using psychopy.web.upload() to send a file over the internet to a configured server.

- This demo will upload a file to http://upload.psychopy.org/test/up.php.
- The file 'filename' is sent as is, whether that's cleartext, binary, or encrypted. It's simply uploaded.
- A configured server saves the file, and returns a status code. "Configured" means that it has the receiving
    script, up.php, accessible online (in its web space), plus necesssary file permissions. up.php is provided
    as part of psychopy along with notes for a sys-admin, see psychopy/contrib/http/.
- This demo will save and then delete the file, and indicate "demo_no_save". 'too_big' means the file was too large
- basicAuth is optional. The test server uses it with the values given, sent in cleartext (not secure). 
"""
__author__ = 'Jeremy R. Gray'

from psychopy import web

from psychopy import logging
logging.console.setLevel(logging.DEBUG)  # show what's going on

#selector = 'http://host/path/to/up.php'
selector = 'http://upload.psychopy.org/test/up.php'  # specially configured for testing / demo (no saving)
filename = __file__  # path to file to upload; __file__ is this script--it will upload itself
basicAuth = 'psychopy:open-sourc-ami'  # optional apache basic auth 'user:password'; required for testing / demo

status = web.upload(selector, filename,
                    basicAuth)  # do the upload, get return status
#!/usr/bin/env python

"""Illustrates using psychopy.web.upload() to send a file over the internet to a configured server.

- This demo will upload a file to http://upload.psychopy.org/test/up.php.
- The file 'filename' is sent as is, whether that's cleartext, binary, or encrypted. It's simply uploaded.
- A configured server saves the file, and returns a status code. "Configured" means that it has the receiving
    script, up.php, accessible online (in its web space), plus necesssary file permissions. up.php is provided
    as part of psychopy along with notes for a sys-admin, see psychopy/contrib/http/.
- This demo will save and then delete the file, and indicate "demo_no_save". 'too_big' means the file was too large
- basicAuth is optional. The test server uses it with the values given, sent in cleartext (not secure). 
"""
__author__ = 'Jeremy R. Gray'

from psychopy import web

from psychopy import logging
logging.console.setLevel(logging.DEBUG) # show what's going on

#selector = 'http://host/path/to/up.php'
selector = 'http://upload.psychopy.org/test/up.php' # specially configured for testing / demo (no saving)
filename = __file__  # path to file to upload; __file__ is this script--it will upload itself
basicAuth = 'psychopy:open-sourc-ami'  # optional apache basic auth 'user:password'; required for testing / demo

status = web.upload(selector, filename, basicAuth) # do the upload, get return status