コード例 #1
0
ファイル: bf.py プロジェクト: k-freeman/IRCbot
 def __init__(self):
     self.queue_in=Queue()
     self.queue_out=Queue()
     thread.start_new_thread(self.run,())
     self.resttime=0
     self.lastcmd=0
     self.fo=StringIO()
     self.bfck = BrainFck(fout=self.fo)
コード例 #2
0
ファイル: test_1.py プロジェクト: JohnnyDankseed/pybrainfuck
def test_run(main=False):

    fout = StringIO()
    bfck = BrainFck(fout=fout,
                    linemode=True,
                    multiline=True,
                    comments=True,
                    breakline=True)

    bfck.run(test_program)

    if main:
        print(fout.getvalue())
        print('len fout:', len(fout.getvalue()))
        print('len output:', len(test_output))

    assert fout.getvalue() == test_output
コード例 #3
0
ファイル: bf.py プロジェクト: k-freeman/IRCbot
class bf(object):
        
    def __init__(self):
        self.queue_in=Queue()
        self.queue_out=Queue()
        thread.start_new_thread(self.run,())
        self.resttime=0
        self.lastcmd=0
        self.fo=StringIO()
        self.bfck = BrainFck(fout=self.fo)
    
    def run(self):
        while 1:
            recv=self.queue_in.get()
            try:
                _, msg_header, msg_payload = recv.split(":",2)
                identification, msg_type, msg_receiver = msg_header.strip(" ").split(" ")
                sender=identification.split("!")
                
                if msg_payload[0]=="!" and msg_payload[1:3]=="bf" and msg_receiver[0]=="#":
                    inbf=io.BytesIO(msg_payload.split(" ",1)[1])
                    #signal.alarm(2)   #
                    try:
                        print "start"
                        self.bfck.run(inbf)
                        for i,c in enumerate(self.fo.buflist):
                            if not curses.ascii.isprint(c):
                                self.fo.buflist[i]=""
                        outbf="".join(self.fo.buflist).strip("\n\r")
                        self.fo.read()
                    except Exception:
                        outbf="Timed out!"
                    

                    self.queue_out.put("PRIVMSG "+ msg_receiver +" :"+outbf+"\n")
                
            except IndexError:
                pass
            except ValueError: # no normal channel/private message
                pass

    def cmd(self,msg):
        self.queue_in.put(msg)
コード例 #4
0
ファイル: brainfuck.py プロジェクト: k-freeman/IRCbot
from StringIO import StringIO
import sys,io

from pybrainfuck import BrainFck

a=io.BytesIO("++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.+++.")

fo=StringIO()
bfck = BrainFck(fout=fo)
bfck.run(a)
out="".join(fo.buflist).strip("\n\r")






コード例 #5
0
from PIL import Image
from pybrainfuck import BrainFck

# Read image and get pixel data as list
pixels = list(Image.open('brainfun.png').getdata())

# Extract just get the blocks. Fun fact: PIL's resize with PIL.Image.NEAREST
# for nearest neighbor messes with the values, but mtPaint does it correctly.
pixels = [pixels[r*512 + c] \
  for r in range(0, 512, 16) \
  for c in range(0, 512, 16)]

# Sort the pixels by RGB value
pixels.sort(key=lambda p: (p[0] << 8) + (p[1] << 4) + p[2])

# Run the alpha values as Brainfuck
BrainFck().run(u"".join([chr(p[3]) for p in pixels]))
コード例 #6
0
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)

import sys

from pybrainfuck import BrainFck

if __name__ == '__main__':

    bfck = BrainFck()

    for arg in sys.argv[1:]:
        print('-' * 50)
        print('Running:', arg)
        print('-' * 50)
        bfck.runfiles(arg)
        print()