#!/usr/bin/env python

from __future__ import print_function

import os
from subprocess import check_output
from sys import argv, stdout

RSGRP = "travistestresourcegroup"
STACC = "travistestresourcegr3014"

def cmd(command):
    """ Accepts a command line command as a string and returns stdout in UTF-8 format """
    if os.name == 'nt':
        command = command.replace('az', 'az.bat')
    return check_output([str(x) for x in command.split()]).decode('utf-8')

# get storage account connection string
out = cmd('az storage account connection-string -g {} -n {}'.format(RSGRP, STACC))
connection_string = out.replace('Connection String : ', '')
os.environ['AZURE_STORAGE_CONNECTION_STRING'] = connection_string

sas_token = cmd('az storage account generate-sas --services b --resource-types sco --permission rwdl --expiry 2017-01-01T00:00Z'
          .format(connection_string)).strip()
os.environ.pop('AZURE_STORAGE_CONNECTION_STRING', None)
os.environ['AZURE_STORAGE_ACCOUNT'] = STACC
os.environ['AZURE_SAS_TOKEN'] = sas_token

print('\n=== Listing storage containers...===')
print(cmd('az storage container list'))

print('\n=== Trying to list storage shares *SHOULD FAIL*... ===')
print('az storage container list --sas-token \"{}\"'.format(sas_token))
print(cmd('az storage share list'))

exit(0)
@@ -459,16 +459,204 @@
 tf-8')%0A%0A
+def set_env(key, val):%0A    %22%22%22 set environment variable %22%22%22%0A    os.environ%5Bkey%5D = val%0A%0Adef pop_env(key):%0A    %22%22%22 pop environment variable or None %22%22%22%0A    return os.environ.pop(key, None)%0A%0A
 # get st
@@ -830,27 +830,24 @@
  ', '')%0A
-os.environ%5B
+set_env(
 'AZURE_S
@@ -871,19 +871,17 @@
 _STRING'
-%5D =
+,
  connect
@@ -890,16 +890,17 @@
 n_string
+)
 %0A%0Asas_to
@@ -1068,30 +1068,23 @@
 strip()%0A
-os.environ.pop
+pop_env
 ('AZURE_
@@ -1113,27 +1113,18 @@
 ING'
-, None)%0Aos.environ%5B
+)%0Aset_env(
 'AZU
@@ -1146,29 +1146,25 @@
 UNT'
-%5D =
+,
  STACC
-%0Aos.environ%5B
+)%0Aset_env(
 'AZU
@@ -1176,19 +1176,17 @@
 S_TOKEN'
-%5D =
+,
  sas_tok
@@ -1187,16 +1187,17 @@
 as_token
+)
 %0A%0Aprint(

Add helper methods to simplify the syntax.