From f1fb83f2089f4231b5dbc4fee432524ea9a2f60e Mon Sep 17 00:00:00 2001 From: Jamie Hardt Date: Sat, 5 Jan 2019 22:03:16 -0800 Subject: [PATCH] Update wave_reader.py Fixed file URL code for version 2.7 --- wavinfo/wave_reader.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/wavinfo/wave_reader.py b/wavinfo/wave_reader.py index b34e453..0f2594c 100644 --- a/wavinfo/wave_reader.py +++ b/wavinfo/wave_reader.py @@ -1,9 +1,14 @@ #-*- coding: utf-8 -*- import struct -import pathlib import os +import sys from collections import namedtuple +if sys.version[0] == 3: + import pathlib +else: + import urlparse, urllib + from .riff_parser import parse_chunk, ChunkDescriptor, ListChunkDescriptor from .wave_ixml_reader import WavIXMLFormat from .wave_bext_reader import WavBextReader @@ -32,11 +37,15 @@ class WavInfoReader(): :param bext_encoding: The text encoding to use when decoding the string fields of the Broadcast-WAV extension. Per EBU 3285 this is ASCII but this parameter is available to you if you encounter a werido. - """ absolute_path = os.path.abspath(path) - #: ``file://`` url for the file. - self.url = pathlib.Path(absolute_path).as_uri() + + if sys.version[0] == 3: + #: `file://` url for the file. + self.url = pathlib.Path(absolute_path).as_uri() + else: + self.url = urlparse.urljoin('file:', urllib.pathname2url(absolute_path)) + with open(path, 'rb') as f: chunks = parse_chunk(f) @@ -135,7 +144,7 @@ class WavInfoReader(): Walk all of the available metadata fields. :yields: a string, the :scope: of the metadatum, the string :name: of the - metadata field, and the value + metadata field, and the value. """ scopes = ('fmt','data')#,'bext','ixml','info')