def get(uri): prot, dompath = uri.split(':', 1) if prot == 'about': return HTTPResponse((uri, fs.read('about/' + dompath), 'text/html')) if prot == 'file': path = os.path.join('/', dompath.lstrip('/')) if os.path.exists(path): if os.path.isdir(path): doc = ''' <html><head><title>{path}</title></head><body> <h1>Index of {path}</h1> <hr> <ul>{ls}</ul> </body></html> '''.format(path=path, ls=''.join([ '<li><a href="%s">%s</a></li>' % (os.path.join(path, i), i) for i in os.listdir(path) ])) return HTTPResponse((uri, doc, 'text/html')) return HTTPResponse( requests.get(uri, headers={'user-agent': 'proton/0.0.1'}, timeout=30))
def test_read(): content = "this is a test content" with open(TEST_FILE, 'w') as file: file.write(content) assert fs.read(TEST_FILE) == content
def test_read_utf8(): content = """"this is a test content with utf-8 characters, such as ÀÁÂÂÄ or ¼½¾""" with open(TEST_FILE, 'wb') as file: file.write(content.encode('UTF-8')) assert fs.read(TEST_FILE) == content
def main(): fs.init('fs') fs.mkdir('a') fs.mkdir('b') fs.mkdir('a/c') fs.create('a/d.txt', 20) fs.create('a/c/e.txt', 20) fd1 = fs.open('a/d.txt', 'rw') fd2 = fs.open('a/c/e.txt', 'rw') fs.write(fd1, 'hello\nbye\n') fs.write(fd2, 'goodbye\n') print fs.read(fd2, 4) print fs.readlines(fd1) for f in fs.readlines(fd1): print(f), fs.close(fd1) fs.close(fd2) fs.suspend()
import fs import main if __name__ == '__main__': OUT_NAME = 'output.txt' raw_input = fs.read(OUT_NAME) print('====> Reading %s' % OUT_NAME) rows = raw_input.split('\n') # assert len(rows)-2 is 5 nums = set() for i, row in enumerate(rows): # Skip first row (contains number of entries) if i == 0: continue # Skip last row (contains only \n) if i == len(rows) - 1: continue cols = row.split(' ') assert len(cols) is 10 num = cols[0] assert num not in nums assert num[0] == '1' and num[-1] == '1' nums.add(num) for i in range(9): assert not main.is_prime(int(num, 2 + i))
a = Term(arr[0]) b = Term(arr[1]) print(a) print(b) print(a - b) print(abs((a - b).solve())) return input if __name__ == '__main__': #IN_NAME = 'B-small-attempt2.in' IN_NAME = 'input.txt' OUT_NAME = 'output.txt' raw_input = fs.read(IN_NAME) print('====> Reading %s' % IN_NAME) rows = raw_input.split('\n') cases = int(rows[0]) solution = '' for i, row in enumerate(rows): # Skip first row (contains number of entries) if i == 0: continue # Skip last row (contains only \n) if i == len(rows) - 1: continue solution += 'Case #%i: %s\n' % (i, str(solve(row))) fs.write(OUT_NAME, solution) print('====> Writing %s' % OUT_NAME)
b = Term(arr[1]) print(a) print(b) print(a - b) print(abs((a - b).solve())) return input if __name__ == '__main__': #IN_NAME = 'B-small-attempt2.in' IN_NAME = 'input.txt' OUT_NAME = 'output.txt' raw_input = fs.read(IN_NAME) print('====> Reading %s' % IN_NAME) rows = raw_input.split('\n') cases = int(rows[0]) solution = '' for i, row in enumerate(rows): # Skip first row (contains number of entries) if i == 0: continue # Skip last row (contains only \n) if i == len(rows) - 1: continue solution += 'Case #%i: %s\n' % (i, str(solve(row))) fs.write(OUT_NAME, solution) print('====> Writing %s' % OUT_NAME)
import pandoc import os import fs pandoc.core.PANDOC_PATH = '/usr/bin/pandoc' # Create New Pandoc Document doc = pandoc.Document() # Read the markdown README doc.markdown = fs.read('README.md') # Write a rST README for long_description fs.write('README.txt', doc.rst) # Run the register command os.system("python setup.py register sdist upload") # Remove the rST README fs.rm('README.txt')
try: fd2 = fs.open('a1/b.txt', 'r') except Exception, e: print e try: fs.write(fd, 'hello\n') except Exception, e: print e try: fs.write(fd + 1, 'hello\n') except Exception, e: print e fd3 = fs.open('/a0/a1/a2.txt', 'w') print fd == fd3 fs.write(fd, 'hello\n') print fs.read(fd, 6) fs.seek(fd, 0) print fs.read(fd, 6) try: fs.seek(fd, 7) except Exception, e: print e try: fs.seek(fd, 11) except Exception, e: print e fs.seek(fd, 0) try: fs.write(fd, '12345678900') except Exception, e: print e
from distutils.core import setup import fs try: long_description = fs.read('README.txt') except IOError: long_description = fs.read('README.md') setup( name='pyfs', packages=['fs'], version='0.0.5', description='a pythonic file system wrapper for humans', long_description=long_description, author='Christoph Koerner', author_email='*****@*****.**', url='https://github.com/chaosmail/python-fs', download_url='https://github.com/chaosmail/python-fs/releases', license='MIT', keywords= ['fs', 'file system', 'filesystem', 'wrapper'], classifiers=[ 'Development Status :: 3 - Alpha', 'Environment :: Console', 'Environment :: Web Environment', 'Intended Audience :: Developers', 'Intended Audience :: System Administrators', 'Intended Audience :: Science/Research', 'License :: OSI Approved :: MIT License', 'Operating System :: OS Independent', 'Programming Language :: Python', 'Programming Language :: Python :: 2',
fs.mkdir('/a/b3') #now on drectory b3 fs.chdir('b3') fs.mkdir('/a/b1/c1') print fs.listdir('/a/b1') fs.create('/a/b3/fc', 30) fcd = fs.open('/a/b3/fc', 'w') fs.write(fcd, '\nnow we needtousegitagain\n') fs.close(fcd) fcd1 = fs.open('/a/b3/fc', 'r') print fs.readlines(fcd1) print fs.read(fcd1, 5) fs.seek(fcd1, 5) print fs.read(fcd1, 10) fs.close(fcd1) fs.suspend() #fs.open('/fa','r') fs.chdir('..') #resume is not sure fs.resume('abc.fssave') fs.create('fb', 29) fbd = fs.open('fb', 'w') fs.write(fbd, 'quizz is so annoying.\n') fs.close(fbd) fs.chdir('/a/')
from distutils.core import setup import fs try: long_description = fs.read('README.txt') except IOError: long_description = fs.read('README.md') setup( name='pyfs', packages=['fs'], version='0.0.8', description='a pythonic file system wrapper for humans', long_description=long_description, author='Christoph Koerner', author_email='*****@*****.**', url='https://github.com/chaosmail/python-fs', download_url='https://github.com/chaosmail/python-fs/releases', license='MIT', keywords=['fs', 'file system', 'filesystem', 'wrapper'], classifiers=[ 'Development Status :: 5 - Production/Stable', 'Environment :: Console', 'Environment :: Web Environment', 'Intended Audience :: Developers', 'Intended Audience :: System Administrators', 'Intended Audience :: Science/Research', 'License :: OSI Approved :: MIT License', 'Operating System :: OS Independent', 'Programming Language :: Python', 'Programming Language :: Python :: 2',
import string import domrenderer import css import fs auto_closing_tags = ('area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'nextid', 'param', 'source', 'track', 'wbr') mastercss = css.parse(fs.read('rs/master.css')) def parse(html): ''' Parses html into an Element ''' html += ' ' * 8 # So range checker on look-ahead isn't required cel = Element(None, '$document') # Current ELement i = 0 while i < len(html) - 8: if cel.tag == 'plaintext': cel.write(html[i:]) i = len(html) elif html[ i] not in '<&>' + string.whitespace: # or cel.tag in ('style', 'script'): s = ''