예제 #1
0
 def __init__(self, *args, **kwargs):
     self.pid = -1
     self.stdin = open("/dev/null", "r")
     self.stdout = open("/dev/null", "r+")
     self.stderr = open("/dev/null", "r+")
     self.returncode = None
     self.universal_newlines = False
예제 #2
0
 def test_append_mode(self):
     source_data = 'Some text\nwith newlines\n'
     
     with storage.open(FILE, 'ab') as handle:
         with storage.open(FILE) as f:
             self.assertEqual(f.read(), '')
         
         handle.write(source_data)
     
     with storage.open(FILE, 'rb') as handle:
         self.assertEqual(handle.read(), source_data)
     
     with storage.open(FILE, 'a') as handle:
         self.assertEqual(handle.tell(), len(source_data))
         handle.write(source_data[::-1])
     
     with storage.open(FILE) as handle:
         self.assertEqual(handle.read(), source_data + source_data[::-1])
예제 #3
0
def load_document(path, page, console):
    with open(path) as handle:
        xaml = handle.read().decode('utf-8')
    document = XamlReader.Load(xaml)
    for index, button in enumerate(find_buttons(document)):
        def handler(sender, event, index=index):
            code = get_code(path, page, index)
            console.handle_lines(code)
        button.Click += handler
    return document
예제 #4
0
def load_document(path, page, console):
    with open(path) as handle:
        xaml = handle.read().decode('utf-8')
    document = XamlReader.Load(xaml)
    for index, button in enumerate(find_buttons(document)):

        def handler(sender, event, index=index):
            code = get_code(path, page, index)
            console.handle_lines(code)

        button.Click += handler
    return document
예제 #5
0
 def test_open_simple_read_and_write(self):
     source_data = 'Some text\nwith newlines\n'
     
     handle = storage.open(FILE, 'w')
     self.assertTrue(isinstance(handle, storage.file))
     self.assertEquals(handle.mode, 'w')
     handle.write(source_data)
     handle.close()
     
     handle = storage.open(FILE, 'r')
     self.assertTrue(isinstance(handle, storage.file))
     data = handle.read()
     self.assertEquals(handle.mode, 'r')
     handle.close()
     self.assertEqual(data, source_data)
     
     handle = storage.open(FILE)
     self.assertTrue(isinstance(handle, storage.file))
     self.assertEquals(handle.mode, 'r')
     data = handle.read()
     handle.close()
     self.assertEqual(data, source_data)
예제 #6
0
def get_code(path, page, index):
    directory = Path.GetDirectoryName(path)
    code_directory = Path.Combine(directory, 'code%s' % page)
    code_file = Path.Combine(code_directory, 'example%s.txt' % index)
    if code_file in _code_cache:
        return _code_cache[code_file]

    handle = open(code_file)
    code = handle.read().decode('utf-8')
    code = code.replace('\r\n', '\n').replace('\r', '\n')
    code_lines = code.splitlines()
    handle.close()
    _code_cache[code_file] = code_lines
    return code_lines
예제 #7
0
def get_code(path, page, index):
    directory = Path.GetDirectoryName(path)
    code_directory = Path.Combine(directory, 'code%s' % page)
    code_file = Path.Combine(code_directory, 'example%s.txt' % index)
    if code_file in _code_cache:
        return _code_cache[code_file]
    
    handle = open(code_file)
    code = handle.read().decode('utf-8')
    code = code.replace('\r\n', '\n').replace('\r', '\n')
    code_lines = code.splitlines() 
    handle.close()
    _code_cache[code_file] = code_lines
    return code_lines
예제 #8
0
def get_list(path):
    with open(path) as handle:
        items = handle.readlines()
    return items
예제 #9
0
from consoletextbox import ConsoleTextBox
from context import context, title
from mousehandler import MouseHandler
from printer import StatefulPrinter
from utils import always_invoke, _debug, SetInvokeRoot, load_document

import storage
import storage_backend
from storage import original_open as open
storage.backend = storage_backend
storage.replace_builtins()

# create the example files
if not storage_backend.CheckForFile('myfile.txt'):
    h = storage.open('myfile.txt', 'w')
    h.write("""This is a text file.
    You can read it.
    It exists.
    """)
    h.close()
if not storage_backend.CheckForFile('workfile'):
    h = storage.open('workfile', 'w')
    h.write('This is the entire file.\n')
    h.close()
if not storage_backend.CheckForFile('workfile2'):
    h = storage.open('workfile2', 'w')
    h.write('This is the first line of the file.\nSecond line of the file\n')
    h.close()

root = Application.Current.LoadRootVisual(StackPanel(), "app.xaml")
예제 #10
0
파일: main.py 프로젝트: gozack1/trypython
def get_list(path):
    with open(path) as handle:
        items = handle.readlines()
    return items
예제 #11
0
파일: main.py 프로젝트: gozack1/trypython
from consoletextbox import ConsoleTextBox
from context import context, title
from mousehandler import MouseHandler
from printer import StatefulPrinter
from utils import always_invoke, _debug, SetInvokeRoot, load_document

import storage
import storage_backend
from storage import original_open as open

storage.backend = storage_backend
storage.replace_builtins()

# create the example files
if not storage_backend.CheckForFile("myfile.txt"):
    h = storage.open("myfile.txt", "w")
    h.write(
        """This is a text file.
    You can read it.
    It exists.
    """
    )
    h.close()
if not storage_backend.CheckForFile("workfile"):
    h = storage.open("workfile", "w")
    h.write("This is the entire file.\n")
    h.close()
if not storage_backend.CheckForFile("workfile2"):
    h = storage.open("workfile2", "w")
    h.write("This is the first line of the file.\nSecond line of the file\n")
    h.close()
예제 #12
0
from consoletextbox import ConsoleTextBox
from context import context, title
from mousehandler import MouseHandler
from printer import StatefulPrinter
from utils import always_invoke, _debug, SetInvokeRoot, load_document

import storage
import storage_backend
from storage import original_open as open
storage.backend = storage_backend
storage.replace_builtins()

# create the example files
if not storage_backend.CheckForFile('myfile.txt'):
    h = storage.open('myfile.txt', 'w')
    h.write("""This is a text file.
    You can read it.
    It exists.
    """)
    h.close()
if not storage_backend.CheckForFile('workfile'):
    h = storage.open('workfile', 'w')
    h.write('This is the entire file.\n')
    h.close()
if not storage_backend.CheckForFile('workfile2'):
    h = storage.open('workfile2', 'w')
    h.write('This is the first line of the file.\nSecond line of the file\n')
    h.close()
if not storage_backend.CheckForFile('example.sdf'):
    h = storage.open('example.sdf', 'w')