@@ -54,18 +54,25 @@ class HTTPReaderIterDataPipe(IterDataPipe[Tuple[str, StreamWrapper]]):
54
54
**kwargs: a Dictionary to pass optional arguments that requests takes. For the full list check out https://docs.python-requests.org/en/master/api/
55
55
56
56
Example:
57
- >>> from torchdata.datapipes.iter import IterableWrapper, HttpReader
58
- >>> file_url = "https://raw.githubusercontent.com/pytorch/data/main/LICENSE"
59
- >>> query_params = {"auth" : ("fake_username", "fake_password"), "allow_redirects" : True}
60
- >>> timeout = 120
61
- >>> http_reader_dp = HttpReader(IterableWrapper([file_url]), timeout=timeout, query_params)
62
- >>> reader_dp = http_reader_dp.readlines()
63
- >>> it = iter(reader_dp)
64
- >>> path, line = next(it)
65
- >>> path
66
- https://raw.githubusercontent.com/pytorch/data/main/LICENSE
67
- >>> line
68
- b'BSD 3-Clause License'
57
+
58
+ .. testcode::
59
+
60
+ from torchdata.datapipes.iter import IterableWrapper, HttpReader
61
+
62
+ file_url = "https://raw.githubusercontent.com/pytorch/data/main/LICENSE"
63
+ query_params = {"auth" : ("fake_username", "fake_password"), "allow_redirects" : True}
64
+ timeout = 120
65
+ http_reader_dp = HttpReader(IterableWrapper([file_url]), timeout=timeout, **query_params)
66
+ reader_dp = http_reader_dp.readlines()
67
+ it = iter(reader_dp)
68
+ path, line = next(it)
69
+ print((path, line))
70
+
71
+ Output:
72
+
73
+ .. testoutput::
74
+
75
+ ('https://raw.githubusercontent.com/pytorch/data/main/LICENSE', b'BSD 3-Clause License')
69
76
"""
70
77
71
78
def __init__ (
@@ -154,16 +161,31 @@ class GDriveReaderDataPipe(IterDataPipe[Tuple[str, StreamWrapper]]):
154
161
**kwargs: a Dictionary to pass optional arguments that requests takes. For the full list check out https://docs.python-requests.org/en/master/api/
155
162
156
163
Example:
157
- >>> from torchdata.datapipes.iter import IterableWrapper, GDriveReader
158
- >>> gdrive_file_url = "https://drive.google.com/uc?export=download&id=SomeIDToAGDriveFile"
159
- >>> gdrive_reader_dp = GDriveReader(IterableWrapper([gdrive_file_url]))
160
- >>> reader_dp = gdrive_reader_dp.readlines()
161
- >>> it = iter(reader_dp)
162
- >>> path, line = next(it)
163
- >>> path
164
- https://drive.google.com/uc?export=download&id=SomeIDToAGDriveFile
165
- >>> line
166
- <First line from the GDrive File>
164
+
165
+ .. testsetup::
166
+
167
+ from torchdata.datapipes.iter import GDriveReader
168
+
169
+ GDriveReader.readlines = lambda self: [
170
+ ("https://drive.google.com/uc?export=download&id=SomeIDToAGDriveFile", b"<First line from the GDrive File>")
171
+ ]
172
+
173
+ .. testcode::
174
+
175
+ from torchdata.datapipes.iter import IterableWrapper, GDriveReader
176
+
177
+ gdrive_file_url = "https://drive.google.com/uc?export=download&id=SomeIDToAGDriveFile"
178
+ gdrive_reader_dp = GDriveReader(IterableWrapper([gdrive_file_url]))
179
+ reader_dp = gdrive_reader_dp.readlines()
180
+ it = iter(reader_dp)
181
+ path, line = next(it)
182
+ print((path, line))
183
+
184
+ Output:
185
+
186
+ .. testoutput::
187
+
188
+ ('https://drive.google.com/uc?export=download&id=SomeIDToAGDriveFile', b'<First line from the GDrive File>')
167
189
"""
168
190
source_datapipe : IterDataPipe [str ]
169
191
@@ -207,16 +229,23 @@ class OnlineReaderIterDataPipe(IterDataPipe[Tuple[str, StreamWrapper]]):
207
229
**kwargs: a Dictionary to pass optional arguments that requests takes. For the full list check out https://docs.python-requests.org/en/master/api/
208
230
209
231
Example:
210
- >>> from torchdata.datapipes.iter import IterableWrapper, OnlineReader
211
- >>> file_url = "https://raw.githubusercontent.com/pytorch/data/main/LICENSE"
212
- >>> online_reader_dp = OnlineReader(IterableWrapper([file_url]))
213
- >>> reader_dp = online_reader_dp.readlines()
214
- >>> it = iter(reader_dp)
215
- >>> path, line = next(it)
216
- >>> path
217
- https://raw.githubusercontent.com/pytorch/data/main/LICENSE
218
- >>> line
219
- b'BSD 3-Clause License'
232
+
233
+ .. testcode::
234
+
235
+ from torchdata.datapipes.iter import IterableWrapper, OnlineReader
236
+
237
+ file_url = "https://raw.githubusercontent.com/pytorch/data/main/LICENSE"
238
+ online_reader_dp = OnlineReader(IterableWrapper([file_url]))
239
+ reader_dp = online_reader_dp.readlines()
240
+ it = iter(reader_dp)
241
+ path, line = next(it)
242
+ print((path, line))
243
+
244
+ Output:
245
+
246
+ .. testoutput::
247
+
248
+ ('https://raw.githubusercontent.com/pytorch/data/main/LICENSE', b'BSD 3-Clause License')
220
249
"""
221
250
source_datapipe : IterDataPipe [str ]
222
251
0 commit comments