How to use readInto method in wpt

Best JavaScript code snippet using wpt

test_file.py

Source:test_file.py Github

copy

Full Screen

1import sys2import os3import unittest4from array import array5from weakref import proxy6import io7import _pyio as pyio8from test.support import TESTFN9from collections import UserList10class AutoFileTests:11 # file tests for which a test file is automatically set up12 def setUp(self):13 self.f = self.open(TESTFN, 'wb')14 def tearDown(self):15 if self.f:16 self.f.close()17 os.remove(TESTFN)18 def testWeakRefs(self):19 # verify weak references20 p = proxy(self.f)21 p.write(b'teststring')22 self.assertEqual(self.f.tell(), p.tell())23 self.f.close()24 self.f = None25 self.assertRaises(ReferenceError, getattr, p, 'tell')26 def testAttributes(self):27 # verify expected attributes exist28 f = self.f29 f.name # merely shouldn't blow up30 f.mode # ditto31 f.closed # ditto32 def testReadinto(self):33 # verify readinto34 self.f.write(b'12')35 self.f.close()36 a = array('b', b'x'*10)37 self.f = self.open(TESTFN, 'rb')38 n = self.f.readinto(a)39 self.assertEqual(b'12', a.tobytes()[:n])40 def testReadinto_text(self):41 # verify readinto refuses text files42 a = array('b', b'x'*10)43 self.f.close()44 self.f = self.open(TESTFN, 'r')45 if hasattr(self.f, "readinto"):46 self.assertRaises(TypeError, self.f.readinto, a)47 def testWritelinesUserList(self):48 # verify writelines with instance sequence49 l = UserList([b'1', b'2'])50 self.f.writelines(l)51 self.f.close()52 self.f = self.open(TESTFN, 'rb')53 buf = self.f.read()54 self.assertEqual(buf, b'12')55 def testWritelinesIntegers(self):56 # verify writelines with integers57 self.assertRaises(TypeError, self.f.writelines, [1, 2, 3])58 def testWritelinesIntegersUserList(self):59 # verify writelines with integers in UserList60 l = UserList([1,2,3])61 self.assertRaises(TypeError, self.f.writelines, l)62 def testWritelinesNonString(self):63 # verify writelines with non-string object64 class NonString:65 pass66 self.assertRaises(TypeError, self.f.writelines,67 [NonString(), NonString()])68 def testErrors(self):69 f = self.f70 self.assertEqual(f.name, TESTFN)71 self.assertFalse(f.isatty())72 self.assertFalse(f.closed)73 if hasattr(f, "readinto"):74 self.assertRaises((OSError, TypeError), f.readinto, "")75 f.close()76 self.assertTrue(f.closed)77 def testMethods(self):78 methods = [('fileno', ()),79 ('flush', ()),80 ('isatty', ()),81 ('__next__', ()),82 ('read', ()),83 ('write', (b"",)),84 ('readline', ()),85 ('readlines', ()),86 ('seek', (0,)),87 ('tell', ()),88 ('write', (b"",)),89 ('writelines', ([],)),90 ('__iter__', ()),91 ]92 methods.append(('truncate', ()))93 # __exit__ should close the file94 self.f.__exit__(None, None, None)95 self.assertTrue(self.f.closed)96 for methodname, args in methods:97 method = getattr(self.f, methodname)98 # should raise on closed file99 self.assertRaises(ValueError, method, *args)100 # file is closed, __exit__ shouldn't do anything101 self.assertEqual(self.f.__exit__(None, None, None), None)102 # it must also return None if an exception was given103 try:104 1/0105 except:106 self.assertEqual(self.f.__exit__(*sys.exc_info()), None)107 def testReadWhenWriting(self):108 self.assertRaises(OSError, self.f.read)109class CAutoFileTests(AutoFileTests, unittest.TestCase):110 open = io.open111class PyAutoFileTests(AutoFileTests, unittest.TestCase):112 open = staticmethod(pyio.open)113class OtherFileTests:114 def testModeStrings(self):115 # check invalid mode strings116 for mode in ("", "aU", "wU+", "U+", "+U", "rU+"):117 try:118 f = self.open(TESTFN, mode)119 except ValueError:120 pass121 else:122 f.close()123 self.fail('%r is an invalid file mode' % mode)124 def testBadModeArgument(self):125 # verify that we get a sensible error message for bad mode argument126 bad_mode = "qwerty"127 try:128 f = self.open(TESTFN, bad_mode)129 except ValueError as msg:130 if msg.args[0] != 0:131 s = str(msg)132 if TESTFN in s or bad_mode not in s:133 self.fail("bad error message for invalid mode: %s" % s)134 # if msg.args[0] == 0, we're probably on Windows where there may be135 # no obvious way to discover why open() failed.136 else:137 f.close()138 self.fail("no error for invalid mode: %s" % bad_mode)139 def testSetBufferSize(self):140 # make sure that explicitly setting the buffer size doesn't cause141 # misbehaviour especially with repeated close() calls142 for s in (-1, 0, 1, 512):143 try:144 f = self.open(TESTFN, 'wb', s)145 f.write(str(s).encode("ascii"))146 f.close()147 f.close()148 f = self.open(TESTFN, 'rb', s)149 d = int(f.read().decode("ascii"))150 f.close()151 f.close()152 except OSError as msg:153 self.fail('error setting buffer size %d: %s' % (s, str(msg)))154 self.assertEqual(d, s)155 def testTruncateOnWindows(self):156 # SF bug <http://www.python.org/sf/801631>157 # "file.truncate fault on windows"158 os.unlink(TESTFN)159 f = self.open(TESTFN, 'wb')160 try:161 f.write(b'12345678901') # 11 bytes162 f.close()163 f = self.open(TESTFN,'rb+')164 data = f.read(5)165 if data != b'12345':166 self.fail("Read on file opened for update failed %r" % data)167 if f.tell() != 5:168 self.fail("File pos after read wrong %d" % f.tell())169 f.truncate()170 if f.tell() != 5:171 self.fail("File pos after ftruncate wrong %d" % f.tell())172 f.close()173 size = os.path.getsize(TESTFN)174 if size != 5:175 self.fail("File size after ftruncate wrong %d" % size)176 finally:177 f.close()178 os.unlink(TESTFN)179 def testIteration(self):180 # Test the complex interaction when mixing file-iteration and the181 # various read* methods.182 dataoffset = 16384183 filler = b"ham\n"184 assert not dataoffset % len(filler), \185 "dataoffset must be multiple of len(filler)"186 nchunks = dataoffset // len(filler)187 testlines = [188 b"spam, spam and eggs\n",189 b"eggs, spam, ham and spam\n",190 b"saussages, spam, spam and eggs\n",191 b"spam, ham, spam and eggs\n",192 b"spam, spam, spam, spam, spam, ham, spam\n",193 b"wonderful spaaaaaam.\n"194 ]195 methods = [("readline", ()), ("read", ()), ("readlines", ()),196 ("readinto", (array("b", b" "*100),))]197 try:198 # Prepare the testfile199 bag = self.open(TESTFN, "wb")200 bag.write(filler * nchunks)201 bag.writelines(testlines)202 bag.close()203 # Test for appropriate errors mixing read* and iteration204 for methodname, args in methods:205 f = self.open(TESTFN, 'rb')206 if next(f) != filler:207 self.fail, "Broken testfile"208 meth = getattr(f, methodname)209 meth(*args) # This simply shouldn't fail210 f.close()211 # Test to see if harmless (by accident) mixing of read* and212 # iteration still works. This depends on the size of the internal213 # iteration buffer (currently 8192,) but we can test it in a214 # flexible manner. Each line in the bag o' ham is 4 bytes215 # ("h", "a", "m", "\n"), so 4096 lines of that should get us216 # exactly on the buffer boundary for any power-of-2 buffersize217 # between 4 and 16384 (inclusive).218 f = self.open(TESTFN, 'rb')219 for i in range(nchunks):220 next(f)221 testline = testlines.pop(0)222 try:223 line = f.readline()224 except ValueError:225 self.fail("readline() after next() with supposedly empty "226 "iteration-buffer failed anyway")227 if line != testline:228 self.fail("readline() after next() with empty buffer "229 "failed. Got %r, expected %r" % (line, testline))230 testline = testlines.pop(0)231 buf = array("b", b"\x00" * len(testline))232 try:233 f.readinto(buf)234 except ValueError:235 self.fail("readinto() after next() with supposedly empty "236 "iteration-buffer failed anyway")237 line = buf.tobytes()238 if line != testline:239 self.fail("readinto() after next() with empty buffer "240 "failed. Got %r, expected %r" % (line, testline))241 testline = testlines.pop(0)242 try:243 line = f.read(len(testline))244 except ValueError:245 self.fail("read() after next() with supposedly empty "246 "iteration-buffer failed anyway")247 if line != testline:248 self.fail("read() after next() with empty buffer "249 "failed. Got %r, expected %r" % (line, testline))250 try:251 lines = f.readlines()252 except ValueError:253 self.fail("readlines() after next() with supposedly empty "254 "iteration-buffer failed anyway")255 if lines != testlines:256 self.fail("readlines() after next() with empty buffer "257 "failed. Got %r, expected %r" % (line, testline))258 f.close()259 # Reading after iteration hit EOF shouldn't hurt either260 f = self.open(TESTFN, 'rb')261 try:262 for line in f:263 pass264 try:265 f.readline()266 f.readinto(buf)267 f.read()268 f.readlines()269 except ValueError:270 self.fail("read* failed after next() consumed file")271 finally:272 f.close()273 finally:274 os.unlink(TESTFN)275class COtherFileTests(OtherFileTests, unittest.TestCase):276 open = io.open277class PyOtherFileTests(OtherFileTests, unittest.TestCase):278 open = staticmethod(pyio.open)279def tearDownModule():280 # Historically, these tests have been sloppy about removing TESTFN.281 # So get rid of it no matter what.282 if os.path.exists(TESTFN):283 os.unlink(TESTFN)284if __name__ == '__main__':...

Full Screen

Full Screen

signed-transaction.ts

Source:signed-transaction.ts Github

copy

Full Screen

1import { Bool, BytesReader, Codec, CompactInt } from "as-scale-codec";2import { Extrinsic, ExtrinsicType } from "./extrinsic";3/**4 * @description Class representing an Extrinsic in the Substrate Runtime5 */6export class SignedTransaction<Address extends Codec, A extends Codec, N extends Codec, S extends Codec> 7 extends Extrinsic{8 9 /**10 * from address 11 */12 public from: Address13 14 /**15 * to address16 */17 public to: Address18 /**19 * amount of the transfer20 */21 public amount: A22 /**23 * nonce of the transaction24 */25 public nonce: N26 /**27 * the signature of the transaction (64 byte array)28 */29 public signature: S;30 /**31 * Determines whether to exhaust the gas. Default false32 */33 public exhaustResourcesWhenNotFirst: Bool34 constructor(35 from: Address = instantiate<Address>(), 36 to: Address = instantiate<Address>(), 37 amount: A = instantiate<A>(), 38 nonce: N = instantiate<N>(), 39 signature: S = instantiate<S>(), 40 exhaustResourcesWhenNotFirst: Bool = new Bool()) 41 {42 super(ExtrinsicType.SignedTransaction);43 this.from = from;44 this.to = to;45 this.amount = amount;46 this.nonce = nonce;47 this.signature = signature;48 this.exhaustResourcesWhenNotFirst = exhaustResourcesWhenNotFirst;49 }50 /**51 * @description SCALE Encodes the Header into u8[]52 */53 toU8a(): u8[] {54 let len = new CompactInt(ExtrinsicType.SignedTransaction);55 return len.toU8a()56 .concat(this.from.toU8a())57 .concat(this.to.toU8a())58 .concat(this.amount.toU8a())59 .concat(this.nonce.toU8a())60 .concat(this.signature.toU8a())61 .concat(this.exhaustResourcesWhenNotFirst.toU8a());62 }63 /**64 * @description Get type id of the Extrinsic65 */66 getTypeId(): i32{67 return <i32>this.typeId;68 }69 /**70 * @description get SCALE encoded bytes for the Transfer instance71 */72 getTransferBytes(): u8[]{73 return this.from.toU8a()74 .concat(this.to.toU8a())75 .concat(this.amount.toU8a())76 .concat(this.nonce.toU8a())77 }78 /**79 * @description Get amount of transaction80 */81 getAmount(): A{82 return this.amount;83 }84 /**85 * @description Get nonce of the transaction86 */87 getNonce(): N{88 return this.nonce;89 }90 /**91 * @description Get signature of the transaction92 */93 getSignature(): S{94 return this.signature;95 }96 /**97 * @description Get sender of the transaction98 */99 getFrom(): Address{100 return this.from;101 }102 /**103 * @description Get receiver of the transaction104 */105 getTo(): Address{106 return this.to;107 }108 /**109 * @description Converts to SCALE encoded bytes110 */111 encodedLength(): i32{112 return this.toU8a().length;113 }114 /**115 * @description Checks if this instance is equal to other instance116 * @param other 117 */118 eq(other: SignedTransaction<Address, A, N, S>): bool{119 return this.from == other.from 120 && this.to == other.to121 && this.amount == other.amount122 && this.signature == other.signature;123 }124 /**125 * @description Checks if this instance is not equal to other instance126 * @param other 127 */128 notEq(other: SignedTransaction<Address, A, N, S>): bool{129 return !this.eq(other);130 }131 /**132 * @description Non static constructor from bytes133 * @param bytes SCALE encoded bytes134 * @param index starting index135 */136 populateFromBytes(bytes: u8[], index: i32 = 0): void {137 assert(bytes.length - index > this.getTypeId(), "SignedTransaction: Bytes array with insufficient length");138 const bytesReader = new BytesReader(bytes.slice(index));139 let length = bytesReader.readInto<CompactInt>();140 assert(<i32>length.unwrap() == this.typeId, "SignedTransaction: Incorrectly encoded SignedTransaction");141 this.from = bytesReader.readInto<Address>();142 this.to = bytesReader.readInto<Address>();143 this.amount = bytesReader.readInto<A>();144 this.nonce = bytesReader.readInto<N>();145 this.signature = bytesReader.readInto<S>();146 }147 /**148 * @description Instanciates new Extrinsic object from SCALE encoded byte array149 * @param input - SCALE encoded Extrinsic150 */151 static fromU8Array<Address extends Codec, A extends Codec, N extends Codec, S extends Codec>(input: u8[], index: i32 = 0): Extrinsic {152 assert(input.length - index >= ExtrinsicType.SignedTransaction, "Extrinsic: Invalid bytes provided. EOF");153 const bytesReader = new BytesReader(input.slice(index));154 const from = bytesReader.readInto<Address>();155 const to = bytesReader.readInto<Address>();156 const amount = bytesReader.readInto<A>();157 const nonce = bytesReader.readInto<N>();158 const signature = bytesReader.readInto<S>();159 const exhaustResourcesWhenNotFirst = bytesReader.readInto<Bool>();160 return new SignedTransaction(from, to, amount, nonce, signature, exhaustResourcesWhenNotFirst);161 }...

Full Screen

Full Screen

spi.py

Source:spi.py Github

copy

Full Screen

1'''2SPI test for the CC3200 based boards.3'''4from machine import SPI5import os6mch = os.uname().machine7if 'LaunchPad' in mch:8 spi_pins = ('GP14', 'GP16', 'GP30')9elif 'WiPy' in mch:10 spi_pins = ('GP14', 'GP16', 'GP30')11else:12 raise Exception('Board not supported!')13spi = SPI(0, SPI.MASTER, baudrate=2000000, polarity=0, phase=0, firstbit=SPI.MSB, pins=spi_pins)14print(spi)15spi = SPI(baudrate=5000000)16print(spi)17spi = SPI(0, SPI.MASTER, baudrate=200000, bits=16, polarity=0, phase=0)18print(spi)19spi = SPI(0, SPI.MASTER, baudrate=10000000, polarity=0, phase=1)20print(spi)21spi = SPI(0, SPI.MASTER, baudrate=5000000, bits=32, polarity=1, phase=0)22print(spi)23spi = SPI(0, SPI.MASTER, baudrate=10000000, polarity=1, phase=1)24print(spi)25spi.init(baudrate=20000000, polarity=0, phase=0)26print(spi)27spi=SPI()28print(spi)29SPI(mode=SPI.MASTER)30SPI(mode=SPI.MASTER, pins=spi_pins)31SPI(id=0, mode=SPI.MASTER, polarity=0, phase=0, pins=('GP14', 'GP16', 'GP15'))32SPI(0, SPI.MASTER, polarity=0, phase=0, pins=('GP31', 'GP16', 'GP15'))33spi = SPI(0, SPI.MASTER, baudrate=10000000, polarity=0, phase=0, pins=spi_pins)34print(spi.write('123456') == 6)35buffer_r = bytearray(10)36print(spi.readinto(buffer_r) == 10)37print(spi.readinto(buffer_r, write=0x55) == 10)38read = spi.read(10)39print(len(read) == 10)40read = spi.read(10, write=0xFF)41print(len(read) == 10)42buffer_w = bytearray([1, 2, 3, 4, 5, 6, 7, 8, 9, 0])43print(spi.write_readinto(buffer_w, buffer_r) == 10)44print(buffer_w == buffer_r)45# test all polaritiy and phase combinations46spi.init(polarity=1, phase=0, pins=None)47buffer_r = bytearray(10)48spi.write_readinto(buffer_w, buffer_r)49print(buffer_w == buffer_r)50spi.init(polarity=1, phase=1, pins=None)51buffer_r = bytearray(10)52spi.write_readinto(buffer_w, buffer_r)53print(buffer_w == buffer_r)54spi.init(polarity=0, phase=1, pins=None)55buffer_r = bytearray(10)56spi.write_readinto(buffer_w, buffer_r)57print(buffer_w == buffer_r)58# test 16 and 32 bit transfers59buffer_w = bytearray([1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2])60buffer_r = bytearray(12)61spi.init(SPI.MASTER, baudrate=10000000, bits=16, polarity=0, phase=0, pins=None)62print(spi.write_readinto(buffer_w, buffer_r) == 12)63print(buffer_w == buffer_r)64buffer_r = bytearray(12)65spi.init(SPI.MASTER, baudrate=10000000, bits=32, polarity=0, phase=0, pins=None)66print(spi.write_readinto(buffer_w, buffer_r) == 12)67print(buffer_w == buffer_r)68# check for memory leaks...69for i in range (0, 1000):70 spi = SPI(0, SPI.MASTER, baudrate=1000000)71# test deinit72spi = SPI(0, SPI.MASTER, baudrate=1000000)73spi.deinit()74print(spi)75spi = SPI(0, SPI.MASTER, baudrate=1000000)76# next ones must fail77try:78 spi = SPI(0, 10, baudrate=10000000, polarity=0, phase=0)79except:80 print("Exception")81try:82 spi = SPI(0, mode=SPI.MASTER, baudrate=10000000, polarity=1, phase=2)83except:84 print("Exception")85try:86 spi = SPI(1, mode=SPI.MASTER, baudrate=10000000, polarity=1, phase=1)87except:88 print("Exception")89try:90 spi = SPI(0, mode=SPI.MASTER, baudrate=2000000, polarity=2, phase=0)91except:92 print("Exception")93try:94 spi = SPI(0, mode=SPI.MASTER, baudrate=2000000, polarity=2, phase=0, firstbit=2)95except:96 print("Exception")97try:98 spi = SPI(0, mode=SPI.MASTER, baudrate=2000000, polarity=2, phase=0, pins=('GP1', 'GP2'))99except:100 print("Exception")101try:102 spi = SPI(0, mode=SPI.MASTER, baudrate=2000000, polarity=0, phase=0, bits=9)103except:104 print("Exception")105spi.deinit()106try:107 spi.read(15)108except Exception:109 print("Exception")110try:111 spi.spi.readinto(buffer_r)112except Exception:113 print("Exception")114try:115 spi.spi.write('abc')116except Exception:117 print("Exception")118try:119 spi.write_readinto(buffer_w, buffer_r)120except Exception:121 print("Exception")122# reinitialization must work123spi.init(baudrate=500000)...

Full Screen

Full Screen

transfer.ts

Source:transfer.ts Github

copy

Full Screen

1import { BytesReader, Codec, CompactInt } from "as-scale-codec";2import { Utils } from "../../utils";3/**4 * @description Class representing a Transfer in the Substrate Runtime5 */6export class Transfer<Address extends Codec, A extends Codec, N extends Codec> 7 implements Codec {8 9 /**10 * from address 11 */12 public from: Address13 14 /**15 * to address16 */17 public to: Address18 /**19 * amount of the transfer20 */21 public amount: A22 /**23 * nonce of the transaction24 */25 public nonce: N26 constructor(27 from: Address = instantiate<Address>(), 28 to: Address = instantiate<Address>(), 29 amount: A = instantiate<A>(), 30 nonce: N = instantiate<N>()) 31 {32 this.from = from;33 this.to = to;34 this.amount = amount;35 this.nonce = nonce;36 }37 /**38 * @description SCALE Encodes the Header into u8[]39 */40 toU8a(): u8[] {41 const result: u8[] = this.from.toU8a()42 .concat(this.to.toU8a())43 .concat(this.amount.toU8a())44 .concat(this.nonce.toU8a());45 return Utils.encodeCompact(result);46 }47 /**48 * @description get SCALE encoded bytes for the Transfer instance49 */50 getTransferBytes(): u8[]{51 return this.from.toU8a()52 .concat(this.to.toU8a())53 .concat(this.amount.toU8a())54 .concat(this.nonce.toU8a())55 }56 /**57 * @description Get amount of transaction58 */59 getAmount(): A{60 return this.amount;61 }62 /**63 * @description Get nonce of the transaction64 */65 getNonce(): N{66 return this.nonce;67 }68 /**69 * @description Get sender of the transaction70 */71 getFrom(): Address{72 return this.from;73 }74 /**75 * @description Get receiver of the transaction76 */77 getTo(): Address{78 return this.to;79 }80 /**81 * @description Gets bytes length of the instance82 */83 encodedLength(): i32{84 return this.toU8a().length;85 }86 /**87 * @description Checks if this instance is equal to other instance88 * @param other 89 */90 eq(other: Transfer<Address, A, N>): bool{91 return this.from.eq(other.from) 92 && this.to.eq(other.to)93 && this.amount.eq(other.amount)94 && this.nonce.eq(other.nonce);95 }96 /**97 * @description Checks if this instance is not equal to other instance98 * @param other 99 */100 notEq(other: Transfer<Address, A, N>): bool{101 return !this.eq(other);102 }103 /**104 * @description Non static constructor from bytes105 * @param bytes SCALE encoded bytes106 * @param index starting index107 */108 populateFromBytes(bytes: u8[], index: i32 = 0): void {109 const bytesReader = new BytesReader(bytes.slice(index));110 let _length = bytesReader.readInto<CompactInt>();111 this.from = bytesReader.readInto<Address>();112 this.to = bytesReader.readInto<Address>();113 this.amount = bytesReader.readInto<A>();114 this.nonce = bytesReader.readInto<N>();115 }116 /**117 * @description Instanciates new Transfer object from SCALE encoded byte array118 * @param input - SCALE encoded Transfer119 */120 static fromU8Array<Address extends Codec, A extends Codec, N extends Codec>(input: u8[], index: i32 = 0): Transfer<Address, A, N> {121 const bytesReader = new BytesReader(input.slice(index));122 let _length = bytesReader.readInto<CompactInt>();123 const from = bytesReader.readInto<Address>();124 const to = bytesReader.readInto<Address>();125 const amount = bytesReader.readInto<A>();126 const nonce = bytesReader.readInto<N>();127 return new Transfer(from, to, amount, nonce);128 }...

Full Screen

Full Screen

class_x_m_l_attributes.js

Source:class_x_m_l_attributes.js Github

copy

Full Screen

1var class_x_m_l_attributes =2[3 [ "XMLAttributes", "class_x_m_l_attributes.html#aeb85120c7a1a43e65e35efeba8bef6ad", null ],4 [ "~XMLAttributes", "class_x_m_l_attributes.html#a666cf3d31b17e758424c7cbbfc77ac22", null ],5 [ "XMLAttributes", "class_x_m_l_attributes.html#a6cfc9deeaac1b011a509e96b33ed5d02", null ],6 [ "add", "class_x_m_l_attributes.html#aa4e8d0dd27a9b619edf3766f5a87e471", null ],7 [ "add", "class_x_m_l_attributes.html#ac244dd478625b8c31423c29d6e64e601", null ],8 [ "clear", "class_x_m_l_attributes.html#ab841f490f96d62770359ba0f27a9444b", null ],9 [ "clone", "class_x_m_l_attributes.html#a3ffcd445b7251e72b2ad0a2c03989036", null ],10 [ "getIndex", "class_x_m_l_attributes.html#a6445564c496f1ada3ff49798530edf05", null ],11 [ "getIndex", "class_x_m_l_attributes.html#a10a0b66d4f07d77342b94f01ed33b8f3", null ],12 [ "getIndex", "class_x_m_l_attributes.html#a0ad20b25996d4549e0a6f638b60572c6", null ],13 [ "getLength", "class_x_m_l_attributes.html#a01e80cc93dbbc2cf0cd70ff55ce0bb47", null ],14 [ "getName", "class_x_m_l_attributes.html#ae4cfc4a0922583a2688fecce9122d0e4", null ],15 [ "getNumAttributes", "class_x_m_l_attributes.html#acbe503ed8bdf6f5e4f53a029ff8a27ef", null ],16 [ "getPrefix", "class_x_m_l_attributes.html#a8d5a23bafadabbbeb1355f62adf4308a", null ],17 [ "getPrefixedName", "class_x_m_l_attributes.html#a8be06fd61e4f34fa2df96b14642f5a08", null ],18 [ "getURI", "class_x_m_l_attributes.html#a0a895d106b6a889cf970db310ccf6792", null ],19 [ "getValue", "class_x_m_l_attributes.html#a40f9ed120e240be8a69e44be55c56383", null ],20 [ "getValue", "class_x_m_l_attributes.html#a44be2f7253ecfa6e5eb7fdb5ef83a330", null ],21 [ "getValue", "class_x_m_l_attributes.html#a2f1fbac803c38663734f76d40738cb64", null ],22 [ "getValue", "class_x_m_l_attributes.html#a95a0086c0b8f6447b74cb6f533d32153", null ],23 [ "hasAttribute", "class_x_m_l_attributes.html#a76f18957a07a747876a84431915b92f1", null ],24 [ "hasAttribute", "class_x_m_l_attributes.html#aa101bbde673dd99f68ef0b5fee483def", null ],25 [ "hasAttribute", "class_x_m_l_attributes.html#aaabcc48288b4fc697884e8137223ae31", null ],26 [ "isEmpty", "class_x_m_l_attributes.html#a26896f4b9a5b411f6c86020c6045dc2c", null ],27 [ "operator=", "class_x_m_l_attributes.html#a4044f9a1f9c37123e8a185df1600abc9", null ],28 [ "readInto", "class_x_m_l_attributes.html#a739f7f54c97e39f4720d777289e162bf", null ],29 [ "readInto", "class_x_m_l_attributes.html#aa447b61a4c289c15b9ca9cff65e1a347", null ],30 [ "readInto", "class_x_m_l_attributes.html#ab65f2791071126433398f9b440c75db3", null ],31 [ "readInto", "class_x_m_l_attributes.html#aa396834ca5a3c2b69500464b62c3754f", null ],32 [ "readInto", "class_x_m_l_attributes.html#a2fd01a04238a79814e19428deb731061", null ],33 [ "readInto", "class_x_m_l_attributes.html#aeec0988d526c669b7cb240e4b1920500", null ],34 [ "readInto", "class_x_m_l_attributes.html#a4727511c5d8c62c5010accfc1e59d34f", null ],35 [ "readInto", "class_x_m_l_attributes.html#acee6cf5316f6d7fe218acc87fb569f7a", null ],36 [ "readInto", "class_x_m_l_attributes.html#a0ef6ec66246aba0176039d71d63731df", null ],37 [ "readInto", "class_x_m_l_attributes.html#a03e214d2380bca266f6e2cd2ba4cc75f", null ],38 [ "readInto", "class_x_m_l_attributes.html#adbfe7ad8d107bb01183f0ea426164e0e", null ],39 [ "readInto", "class_x_m_l_attributes.html#a28b7019532c1adb88e3bef82e77feadc", null ],40 [ "remove", "class_x_m_l_attributes.html#a92ba7c7900c10a809b4d14aec7344fd1", null ],41 [ "remove", "class_x_m_l_attributes.html#aca93f0fb0bb2933afd40264d23fea4a7", null ],42 [ "remove", "class_x_m_l_attributes.html#a807cc84ce5e1d372af5dbf3404815f9b", null ]...

Full Screen

Full Screen

utils.py

Source:utils.py Github

copy

Full Screen

1import os2import shutil3# The code is taken from https://stackoverflow.com/a/29967714/22278954class Copy:5 # differs from shutil.COPY_BUFSIZE on platforms != Windows6 READINTO_BUFSIZE = 1024 * 10247 @classmethod8 def fileobj(cls, fsrc, fdst, callback, length=0):9 try:10 # check for optimisation opportunity11 if "b" in fsrc.mode and "b" in fdst.mode and fsrc.readinto:12 return cls._fileobj_readinto(fsrc, fdst, callback, length)13 except AttributeError:14 # one or both file objects do not support a .mode or .readinto attribute15 pass16 if not length:17 length = shutil.COPY_BUFSIZE18 fsrc_read = fsrc.read19 fdst_write = fdst.write20 while True:21 buf = fsrc_read(length)22 if not buf:23 break24 fdst_write(buf)25 callback(len(buf))26 @classmethod27 def _fileobj_readinto(cls, fsrc, fdst, callback, length=0):28 """readinto()/memoryview() based variant of copyfileobj().29 *fsrc* must support readinto() method and both files must be30 open in binary mode.31 """32 fsrc_readinto = fsrc.readinto33 fdst_write = fdst.write34 if not length:35 try:36 file_size = os.stat(fsrc.fileno()).st_size37 except OSError:38 file_size = cls.READINTO_BUFSIZE39 length = min(file_size, cls.READINTO_BUFSIZE)40 with memoryview(bytearray(length)) as mv:41 while True:42 n = fsrc_readinto(mv)43 if not n:44 break45 if n < length:46 with mv[:n] as smv:47 fdst.write(smv)48 else:49 fdst_write(mv)...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3var options = {4 };5wpt.runTest(options, function(err, data) {6 if (err) {7 console.log("Error: " + err);8 } else {9 console.log("Test ID: " + data.data.testId);10 wpt.readInto(data.data.testId, function(err, data) {11 if (err) {12 console.log("Error: " + err);13 } else {14 console.log("Test Status: " + data.data.statusCode);15 console.log("Test Status Text: " + data.data.statusText);16 }17 });18 }19});20var wpt = require('wpt');21var wpt = new WebPageTest('www.webpagetest.org');22var options = {23 };24wpt.runTest(options, function(err, data) {25 if (err) {26 console.log("Error: " + err);27 } else {28 console.log("Test ID: " + data.data.testId);29 wpt.read(data.data.testId, function(err, data) {30 if (err) {31 console.log("Error: " + err);32 } else {33 console.log("Test Status: " + data.data.statusCode);34 console.log("Test Status Text: " + data.data.statusText);35 }36 });37 }38});39var wpt = require('wpt');40var wpt = new WebPageTest('www.webpagetest.org');41wpt.getLocations(function(err, data) {42 if (err) {43 console.log("Error: " + err);44 } else {45 console.log("Locations: " + data.data);46 }47});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var fs = require('fs');3var path = require('path');4var file = path.join(__dirname, 'enwiki-20160101-pages-articles-multistream.xml');5var reader = wptools.createReader(file);6reader.readInto(function (err, doc) {7 if (err) {8 console.log(err);9 }10 else {11 console.log(doc);12 }13});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var fs = require('fs');3var file = fs.createWriteStream("output.txt");4var wp = wptools.page('Albert Einstein');5wp.readInto(file, function(err, resp) {6 console.log(resp);7});8Albert Einstein (14 March 1879 – 18 April 1955) was a German-born theoretical physicist. He developed the general theory of relativity, one of the two pillars of modern physics (alongside quantum mechanics). Einstein's work is also known for its influence on the philosophy of science. Einstein is best known in popular culture for his mass–energy equivalence formula E = mc2 (which has been dubbed "the world's most famous equation"). He received the 1921 Nobel Prize in Physics "for his services to theoretical physics

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var page = wptools.page('Albert_Einstein');3page.readInto('image', function(err, image) {4 console.log(image);5});6var wptools = require('wptools');7var page = wptools.page('Albert_Einstein');8page.readInto('image', function(err, image) {9 console.log(image);10});

Full Screen

Using AI Code Generation

copy

Full Screen

1var file = new WpTextFile("C:\\test.txt");2file.readInto("C:\\test2.txt");3var file = new WpTextFile("C:\\test2.txt");4file.readInto("C:\\test3.txt");5var file = new WpTextFile("C:\\test3.txt");6file.readInto("C:\\test4.txt");7var file = new WpTextFile("C:\\test4.txt");8file.readInto("C:\\test5.txt");9var file = new WpTextFile("C:\\test5.txt");10file.readInto("C:\\test6.txt");11var file = new WpTextFile("C:\\test6.txt");12file.readInto("C:\\test7.txt");13var file = new WpTextFile("C:\\test7.txt");14file.readInto("C:\\test8.txt");15var file = new WpTextFile("C:\\test8.txt");16file.readInto("C:\\test9.txt");17var file = new WpTextFile("C:\\test9.txt");18file.readInto("C:\\test10.txt");19var file = new WpTextFile("C:\\test10.txt");20file.readInto("C:\\test11.txt");21var file = new WpTextFile("C:\\test11.txt");22file.readInto("C:\\test12.txt");

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var fs = require('fs');3var buffer = new Buffer(1024);4wptools.readInto('test.txt', buffer, function(err, bytesRead) {5 if (err) {6 console.log('Error reading file into buffer: ' + err);7 } else {8 console.log('Bytes read: ' + bytesRead);9 }10});11fs.writeFile('test2.txt', buffer, function(err) {12 if (err) {13 console.log('Error writing buffer to file: ' + err);14 }15});16fs.readFile('test2.txt', function(err, data) {17 if (err) {18 console.log('Error reading file into buffer: ' + err);19 } else {20 console.log('Bytes read: ' + data.length);21 }22});23wptools.writeFrom('test3.txt', buffer, function(err) {24 if (err) {25 console.log('Error writing buffer to file: ' + err);26 }27});28var wptools = require('wptools');29var fs = require('fs');30var buffer = new Buffer(1024);31wptools.readInto('test.txt', buffer, function(err, bytesRead) {32 if (err) {33 console.log('Error reading file into buffer: ' + err);34 } else {35 console.log('Bytes read: ' + bytesRead);36 }37});38fs.writeFile('test2.txt', buffer, function(err) {39 if (err) {40 console.log('Error writing buffer to file: ' + err);41 }42});43fs.readFile('test2.txt', function

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var fs = require('fs');3var content = wptools.readInto('test.txt');4console.log(content);5var wptools = require('wptools');6var fs = require('fs');7wptools.write('test.txt', 'This is the content of the file');8console.log('File written successfully');9var wptools = require('wptools');10var fs = require('fs');11wptools.writeFrom('test.txt', 'This is the content of the file');12console.log('File written successfully');13var wptools = require('wptools');14var fs = require('fs');15wptools.append('test.txt', 'This is the content of the file');16console.log('File written successfully');17var wptools = require('wptools');18var fs = require('fs');19wptools.appendFrom('test.txt', 'This is the content of the file');20console.log('File written successfully');21var wptools = require('wptools');22var fs = require('fs');23wptools.copy('test.txt', 'test1.txt');24console.log('File copied successfully');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2 if (err) {3 console.log(err);4 } else {5 console.log(data);6 }7});8{ title: 'Indonesia makes its first legal execution in 17 years - ABC News (Australian Broadcasting Corporation)',

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful