Ejemplo n.º 1
0
class StdoutCapture():
    def setUp(self):
        self.capture = StringIO()
        sys.stdout = self.capture

    def tearDown(self):
        sys.stdout = sys.__stdout__

    def get_captured_value(self):
        return self.capture.getValue()
Ejemplo n.º 2
0
class StdoutCapture():
    def setUp(self):
        self.capture = StringIO()
        sys.stdout = self.capture

    def tearDown(self):
        sys.stdout = sys.__stdout__

    def get_captured_value(self):
        return self.capture.getValue()
Ejemplo n.º 3
0
    def handler(request):
        if request.code != 200:
            raise HTTPError(request.code)

        path = "%s/%s" % (root, request.url[cut:])

        if relpath(path).startswith('..'):
            raise HTTPError(404)

        try:
            stat = os.stat(path)
            if 'IF-MODIFIED-SINCE' in request.headers:
                try:
                    request_mtime = time.mktime(time.strptime(request.headers['IF-MODIFIED-SINCE'], DATE_RFC1123))
                    print request_mtime
                except ValueError:
                    request_mtime = None
                    print 'mtime value error'
                if request_mtime and request_mtime < stat.st_mtime:
                    return request.reply(304)

            mod_time = time.strftime(DATE_RFC1123, time.gmtime(stat.st_mtime))
            data = open(path).read()

        except (OSError, IOError) as err:
            if err.errno == 2:
                raise HTTPError(404)  # not found
            if err.errno == 13:
                raise HTTPError(404)  # no access
            if err.errno == 21:
                raise HTTPError(404)  # is a directory
            raise

        (head, ext) = os.path.splitext(path)
        if ext == ".py":
            try:

                buffer = StringIO()
                sys.stdout = buffer
                sys.stderr = buffer
                execfile(path)
                data = "\n".join(buffer.getValue())
                buffer.close()
                #stdout = os.popen("/usr/bin/python2.6 " + path, 'r')
                #if not stdout:
                #    data = 'empty stdout for program'
                #else:
                #    data = stdout.read()
                #    stdout.close()
            except Exception, e:

                raise HTTPError(500)
            finally:
Ejemplo n.º 4
0
def convertPDFtoString(filePath):
    outputString = StringIO()

    with open(filePath, 'rb') as inFile:
        parser = PDFParser(inFile)
        doc = PDFDocument(parser)
        resourceManager = PDFResourceManager()
        device = TextConverter(resourceManager,
                               outputString,
                               laparams=LAParams())
        interpreter = PDFPageInterpreter(resourceManager, device)

        for page in PDFPage.create_pages(doc):
            interpreter.process_page(page)

    return outputString.getValue()
Ejemplo n.º 5
0
    zero_position = position_file[position_file['Position|Market_Value_Local']
                                  == 0]

    good_position = position_file[~position_file['Account|Account_Number'].
                                  insin(zero_position['Account|Account_Number']
                                        )]
    ref = 0
    i = 0

    for i in zero_position['Account|Account_Number']:
        s3_res1.Object(pos_error_bucket,
                       i + '_error_' + str(date.today()) + '.txt').put(Body=i)
        good_position.to_csv(stg_bucket)
        s3_res1.Object(bucket_name,
                       posFile.key).put(Bocy=stg_bucket.getValue())

        for secFile in secBucket.Objects.all():
            strTemp3 = ""
            #3s3_res1.Object(bucket_name,'PMT_Positions_POC.csv').put(Body=stg_bucket.getvalue())
            #good_position.to_csv(r'\\D:\poc\PMT_Positions_POC.csv',index=False)

            security_file = pd.read_csv(r's3://securities-incoming-mohamw/' +
                                        secFile.key)
            good_position['flag1'] = security_file['Instrument_Issue|Cadis_ID']
            good_position['flag2'] = np.where(
                good_position['Position_Sec_ID|Cadis_ID'] ==
                good_position['flag1'], 1, 0)
            error_position_file2 = good_position[good_position['flag2'] == 0]
            error_position_file2 = pd.DataFrame(error_position_file2)