So, for those who were at the Pycon Singapore, I talked about one of my projects they're called Warped Drive. This time I'm going to talk about another. I've got the wrong slider. That's bad, isn't it? This is the one I did at Pycon Singapore. I need to bring the right ones. This will teach me. Here, that's better. Now, I've probably lost this connection. So, yes, as you were saying, I'm the author of Model Whiskey, so I've been doing Python since I don't know when to come out. I dragged down version 0.9 off the... It wasn't internet back then, it was like usernet news groups. So, I've been playing around with Python quite a lot of time. And I have a history of being really silly and putting out open source projects. And I don't know if anyone else has their own little open source projects. They can be a lot of work, and I'm silly and keep doing it. So, I have three main open source projects I've known for. ModWiskey, Wrapped, and... What was the other one? There's another one which died actually, a long time ago. There's a C++, we won't go into that. So now, I'm going to talk about Wrapped today. Let's see if it gets going. Good, that works. Okay, so Wrapped. So, I'll start rather than go and talk to me about monkey patching. But I'm not going to go there quite first, I'm going to talk about decorators first. Now, we all know what decorators are in Python. Yes, they're useful. Yes, they're easy to implement. Who's implemented a decorator themselves? Everyone's used them. Okay, so you've used them. So for those who have implemented them, are they actually easy to implement? You think so? You sure? Okay, so here's a typical decorator. One area of a decorator is you're putting a wrapper around another function. And there is a syntax in Python where you use this app symbol to make use of your decorator. And there's a bit of magic going on here to essentially put this function around this other one so that when this one is called, it'll actually call this one, do this work, and return that result. So you essentially intersect that call and put this wrapper around it. And that is the basic pattern for implementing a decorator that you've probably used. The problem is, if you implement a decorator like that as written, it will break things. It doesn't actually, it will work most of the time. Most people wouldn't even know there was a problem. But one of the things that breaks is introspection. And if you're familiar with Python, one of the great things about the language is that you can actually go in there and look at the objects in your application.  And you can work out the type of the objects. You can ask their names. You can look at help strings and so on and so forth. They're looking at the name, they're looking at the help strings, looking at the arguments that a function accepts. That's what we regard as being introspection. It's pulling out that information to learn about it. Decorators, if you use that basic pattern, as people use, breaks it. As the name, done is called name, done is called doc. That is the name and the help string that you'll get. Those things are not preserved when you wrap things with a decorator. Now, you may be familiar if you've done implementation of decorators in a package called, or module in the standard library called functools. Now, it has the thing in there called wrappes. Now, it itself is a decorator. It's a bit of magic which you can supposedly use to make this decorator work properly, to fix those problems of introspection. The problem is it doesn't solve all the problems. It doesn't always work. It sort of fixes the basic things like done is called name and done is called help, doc. But there's other things that doesn't quite get right. Now, the things it doesn't fix is, there are other ask the issues with introspection which it doesn't fix. Things like, if you want to get the arguments of the function which the decorator is applied to, they don't work. You can't get them back properly. You're going to get back the arguments that the wrapper itself is applied. And there's other problems where if you try and use a wrapper using that basic pattern of a decorator, it won't work when implementing it around certain types of other decorators which you implement using a thing called descriptors. Now, descriptors is a real bit of magic in there. And some examples of something that uses a descriptor is class method in Python, which is another decorator. We use decorators. If you put one of your decorators around a class method, things start to not quite work right. So, there's a lot of complicated details and I'm not going to go into it. I've done talks about this in the past and if you really want to know about all these issues that can occur with decorators and what can go wrong and how you should do them properly, if you go to my blog, it's the best place. You look on the right-hand side, there's a quick link section and it has decorators monkey patching. There's about a dozen or so blog posts there where I've talked about and gone through the basics of decorators and how they're implemented, why they're implemented wrong, how they should be implemented and so on and so on. So, you want to know more about that than go there. So, much as you might think decorators simply, if you're going to implement, this is my advice. Don't try and do them yourself. Okay? Don't follow that pattern that I showed up there earlier. But what is the solution? The solution is a project I wrote called RAT. What it does is it embodies all that proper way of doing things. So, it deals with all those things about introspection. It deals with the things of how to create a decorator which when applied around another sort of decorator, whether it's a normal decorator or one implementer using a scripter, it handles all that magic and does everything correctly. All the introspection things are fixed. You can query your decorator function and you'll get back the correct name, the correct doc string, the correct arguments and a whole host of other things. In terms of using RAT to create your own decorator, then it's a bit simpler than we had before. Before, we were implementing the decorator by using a function closure. Essentially, one function is nested inside of another. Using this decorator from RAT to be clear, you get rid of one level there, which makes it all look a bit simpler. You're going to just declare your wrapper function like that and you'll get a few arguments coming. RAT, which is a function you decorate with, and then at the end you've got ARGS and KWIRGS. There's other things in here called instance. Now, what's interesting about instance, if I go the right way, is that when you use the original decorator pattern, one of the bits of information and knowledge that you lose that you don't know about is whether you've applied a decorator to a normal function or an instance method of a class or a class method, or even to a class, that information is very hard to get out and use that basic decorator pattern. In RAT, it allows you to get that out such that when your wrapper function is called, it will can tell you effectively why this instance argument, how your decorator was being used. So we can see whether the decorator is being applied to a class, to a functional static method, to a class method, or an instance method. Now that's very important because if you want to write a decorator which can be used in different scenarios like that and is able to dynamically adjust, you need something like that. And who uses Django? There are decorators in Django which there are two versions of them. One you can apply to a normal function and then the same type of decorator, but you have to use a different one of applying it to an instance method because they haven't got that smarts in there to allow their decorator implementation to pick up in what context it's used in. RAT handles that. That's a good thing I say you if you're able to create these things called universal decorators. Now imagine a time that you might not need this but it's a cute feature. Now, if you don't trust me and believe me and say you should use RAT and it's wonderful and all that, I had multiple people from the core developers of Python come up to me, can you please get RAT inside of the Python standard library? I mean the last one was... I forgot this first name, someone Hastings. Anyway, very, very important person to see Python world and I've told you we've got this name. Whether we'll get into the standard library I don't know. I've missed the cutoff for Python 2.6. I've got a year and a half I think for Python 2.7 maybe I'll get enthusiastic and look at it. Now, I've talked about RAT and decorators but and it's really good for that. That's actually wasn't what RAT was created for. The reason that RAT was created was for something called monkey patching. I used to work at a company called New Relic. Anyone heard of New Relic? They do application performance monitoring for web applications. They... what they do is they provide an agent library if you like or an agent package which integrates into a web application to put in instrumentation which allows you then to monitor that web application. So number of requests coming in, how long the requests take but a lot, lot deeper than that. If you are using Django for example, it will associate a particular request with the particular view handler in Django which was invoked to handle that request. So it will associate that data for that request with that view handler and we can get a breakdown of not my web apps getting all these requests but my web apps getting all these requests and I know that 50% of them went to this particular view handler and 25% to this handler. And it can dig down into extracting data out about database performance. How many calls you doing to your database SQL database? How long each of those queries took? What were the details of the queries? Now to do all that if you are going to instrument your own code you may well go off and use your own decorator. You've got the ability to modify your code put those decorators in there where you need them to extract information out and then report it into a monitoring system such as DataDoc, StatsD a couple others as well there's a lot of open source on this one. So you can do it all manually but when you talk about a product like New Relic they don't really want you to expect you to go and put all of this instrumentation in your own code yourself to do all of that. So what New Relic does is it goes in a monkey patch just to help out of the code base. It knows about Django or Pyramid or whatever all these frameworks it will detect when you have imported those modules and put Django great, you're using Django I'm going to go in and put all this monkey patching in there to instrument so I know when this view handler is called, when this template rendering is happening and it does all that dynamically without you even knowing and if you're using New Relic and you thought hey this is a lot of magic if you had no idea how about works you should be really scared so when I was at New Relic I wrote that I had a lot of information for them and yeah, it monkey patched the hell out of everything and in doing that I don't know that monkey patch coding for them but I sort of fought one holiday I was actually up in KL I've just come back from a holiday from KL I was actually in KL one holiday before a number of years ago it might have been a five or six week holiday I don't remember and I thought okay let's talk about how to do monkey patching because of New Relic and I thought it's time to sit down and do it properly now and I did it as a separate library which is what wrapped us and so that's what all came up from that work from there so why then is wrap got decorators in there but also monkey patching and that is because decorators rely on a lot of the similar principles to monkey patching so I actually did the monkey patching support and side effect of that was this great way of implementing decorator really easy as well so that's how it came about now the reason for that who has used Python 2.3 or earlier anyone use Python from that by back wow so Python 2.3 earlier did not have decorator syntax this didn't exist okay you could still do the same thing but the way you would write it in your code you just have to remember that we had that function wrapper implementation before so if you use it 2.4 plus you could just go add name of decorator and apply it to function in Python 2.3 you get your function and you're going to go function equals so we've got to actually replace this with a function wrapper passing it to function and so if you remember the notation the nested function so you've called that outer function which has passed in the function as an argument and the body of that has then returned the inner function it's a closure function closure and that's what actually gets assigned back into that so this is what generally we refer to as being monkey patching and that's how decorator spectrally are implemented under the hood the difference is decorator applied when your code is defined so if you've written your own code be it a function at a module scope what you're doing you go in there you put your code and then you put at function wrapper or if you define your class it's at function wrapper on the instance method and that decorator is applied when that Python code is being read in by the interpreter and converted from code to byte code so it is done when the code is defined the difference with monkey patching is it's performed after the fact and as a result it can't use the decorator syntax now when I mean by after the fact it's literally going to be after that whole module has been imported some time later why would you want a monkey patch you may want a monkey patch you may want a monkey patch if you need to fix bugs in code you cannot modify so imagine Django had a bug in it and they know about it they've fixed it it's not going to be available until Python 1.10 which is just going through pre release calendar but imagine you were on version 1.8 of Django and you couldn't move up for various reasons but you still need that fix now you've got the choice of fork Django make your own modified version of it and then maintain that alternatively you can use your existing Django 1.8 and use monkey patching to go and apply a fix to that code after the fact so that's one reason you might use it but another reason you might use it and probably the use case which most people would encounter it is for doing testing now who here has used the Mock package anyone heard of Mock one again same person but if you're using Python 3 I can't remember what it's called there is a version of Mock now one of the more recent Python 3 versions what Mock is is if you're writing unit tests for Python code it's a way of when you're writing those unit tests you want to isolate bits of the code you're testing so that you can test just those bits a bit at a time and when you've got a large application which may be doing things like calling out to some back end service and you want to just test the function which is doing that call and it's in the result you don't want it to be talking to that back end service because that back end service may not exist so this is a library out here called Mock and this again shows how bad my memory is I forgot the name of the guy who writes it he's a UK person he's got a big beard I haven't met him in New Zealand and he wrote this thing called Mock and it's a way of doing monkey patching so you write your unit test and you apply decorators to your unit test and with a description of what I need the monkey patch for that unit test and so when that unit test runs you've got to apply all these monkey patches to change the code so it might stub out some code so rather than actually making a call to request library and then doing a call to back end service you'll mock out parts of the request library so that the call will actually go to your Mock code so instead of calling back it it'll call you a little test function or Mock function which returns a faked up result so that's another useful and finally I mentioned the case of Neuralit before you might want to do it to go into code and add instrumentation to be able to do performance monitoring as well so monkey patching with RAPT give you an example so you remember this function we had before the wrapper previously I was having RAPT.decorator I'm dropping that decorator at the moment so imagine I've got this bit of code here in this example.py and I want to apply a wrapper around this name method in there because I need to change the implementation slightly to do something that's expired or might be mocking it out to do testing what you can do with RAPT is essentially you've got this patches modeling import RAPT define the wrapper and the class from that code folder I want to actually apply this wrapper RAPT.rap function name of class we're actually going to give it a class object the name of the method and the wrapper and RAPT is going to go in there and put a wrapper around that method and it's going to do that if you then go and create an instance of that example class now and call name on that method which then allows you to do something and in this case I'm just calling the original but I could change arguments as they go in I could get the result as it comes out and change the result or I could just not even call just stub it out with a mock value for testing and that's all it does but you'll see the separation here which I mentioned before about decorators do it with the defined monkey patches after the fact I've already imported this this module in so I'm going and doing evil things afterwards now when I showed how things were done in 2.3 you might remember I had an example here function equals wrapper function you shouldn't do that actually that itself can cause various strange corner case problems with classes class instance methods in particular so I could do that so I've got my wrap decorator example again so that's my decorator version you can do this and it'll work 99% of the time but there's some corner cases that it won't work in so that's where when you're using wrap you'll use my function trust that wrap will go in and do the things that it needs to do properly and I don't know how familiar you are with how the python object model works I can tell you of how in the python module in a python class there is a dict, underscore dict that's where all the attributes the methods from that type are in there if we do this we're getting that function out of there but this magic thing happens with python called binding usually it's used to take the normal function and associate it with an instance of a class that's where things start to fall apart if you try and do this yourself because we've got this off the class type itself, binding has occurred it's actually bound that function to a none whereas normally when you're using an instance it'll be bound to an instance anyway I'll just confuse everyone and myself if I go into that just trust me, don't do that that's why I've got the other function so direct patching of methods breaks in certain cases basically if you're going to use wrapped you'd let wrapped do it for you now you'll remember there when we had the example .py and we had my patches file and I had to actually import that example class from the example.py we can actually clean that up a bit in this case I've got my wrapper function and I've got this other decorator inside of wrapped which is patch function wrapper so in this case rather than going import from example import example from import example from example I should have used different names anyway instead of importing the module and getting the class out of it we can just say patch this function wrapper in module and the method example.name okay when I import patches.py it'll zip through this, it'll see this it'll apply that wrapper and it's all done okay we can clean that up a bit now I mentioned testing before so what about testing where we do not want permanent patches because that previous example patch function wrapper, it's a permanent once you do that it's applied forever for the life of that process so wrapped has this other one then it's a transient function wrapper it's very very similar to that patch function wrapper but what we can do in this case is when this file gets pulled in it's not actually going to do anything at this point it's actually going to create a new decorator and we're going to create use that new decorator down here so what and it's applied it to this test method here what's going to happen in this case is that when we call test method what will happen is that this is when this kicks in it will apply that wrapper to that method look up method on that class and then it will call test method actually the body of it so when it calls this method here that wrapper will be exist do whatever we need to do and when it pops out of this function it's going to remove that wrapper and the reason for this is if you've got a whole bunch of test methods and mock library mock package works the same way you can't have the patches be permanent because you may want different patches applied for different tests so you run one test with one particular monkey patches applied when that test is finished you take them all out then you run the next test with a different set of monkey patches applied and that way you keep all the things separate when you're running a different test anyway there's a way in wrapper doing that also wrap has another case of what if we need to intercept access to a single instance of an object okay so let's give an example of that imagine that we have just ignored this so imagine our test method is going storage equals instance of storage class and then it calls storage look up key so normally what we have to do is we create our instance until we go and do that now in this particular case we've created that storage instance within the scope of this method so it doesn't matter it's a local copy but you can imagine that when we monkey patch something we're actually monkey patching a method on the type of the class so every single instance we create of that class that we've monkey patched has that monkey patched code applied to it so we only want to have a monkey patch applied to one instance because we might be doing this in instrumentation in a real life application and it might be a multi threaded application and so there's always different threads running all over the place and we only want to patch one instance of a class in one thread we don't want that same monkey patch to be affecting everything else now what wrap test for that is this thing called object proxy it's the thing that actually underlies everything in wrap everything is built around this wrap object proxy all the monkey patching function wrappers are built on object proxy decorator mutation built on this object proxy what it is it's a way of just essentially giving it any python object you wrap this object proxy around it and if I now call the proxy what will actually happen is it will just forward on that call to the original method on the original storage class the original lookup method but if I go put my wrapper around it my proxy wrapper it allows me to intercept that one method call and so when I call this case storage lookup of this file it's actually going to call my method here and I can do what it's over and call the original one this is the original object I wrapped here but if I call storage.clear if I clear in here it will still call the original straight so essentially what's called transport object proxy it works not just on method calls if you access an attribute via the proxy it will give you back the one that's in the original one if you've ever used from the python standard library from weakref module there is a type in there called ref the form of object proxy if there is not transparent in the sense that when you want to access it you actually have to use ref and like a call to get back to original this one just does all transparent so there are the different ways you can use wrap to do this and that monkey patchy if you need to now very important thing you mentioned before about how decorators are applied when the code is being read in monkey patchy is done after the fact one thing you have to be very very careful of is ordering problems when you apply monkey patches and here's an example I have a function and an example and I want to monkey patch that so that gets imported by module somewhere else in the application code and it might go from example import function I laid out when I try and patch this function and I go oh great I have my wrap patch function and I'll apply a wrapper around it there's a problem anyone see what the problem is so in what you're going to apply it's still not attached in what you're going to apply it's still not attached so I'm going to apply this to here but this because it went from example import function has copied a reference of function into the global namespace of module so when I patch this it's not patching this function so that's what I mean by ordering problems if other things get in there before you do and import that module and do things like this and then your monkey patch doesn't apply to their copies of it and if you have ever used a ventlet or g-event if you they the purpose of ventlet and g-event are packages in python which not in the core but third party which rather than using multifredding to implement concurrency they use a thing called greenlets essentially it's co-operative multi-tasking it relies on something that is running to say I'm going to block here I'm going to voluntarily give up control so that something else can run to do that though so it's transparent those packages go into monkey patch the python standard library they go into monkey patch into the socket code multifredding code a whole bunch of other places the way that they work is this naive approach of you in your application there's a particular function of g-event where you have to go g-event.monkeypatch all that has to eventually get done it goes to all these all these monkey patches get applied but if the application code is already imported some of the stuff that it needs to monkey patch you'll end up with a copy and your copy won't be imported g-event and the cells have got tripped up by this because in the python standard library itself a lot of code around there which goes from time import sleep and things will get copies of sleep when you use these packages there'll be some sleep call out that doesn't work and it blocks your whole function because it hasn't got this little wrapper around it which says no I'm going to give up control so that something else can run while I sleep I don't like g-event and eventlet if you ever think you have a need for them probably you don't don't use them unless you really really understand how they work and you think you have a need for them because they don't do monkey patch important another problem I want to concur is the fact that in that previous code I've got this patches module so you might have in your application code okay I want to do all this different monkey patching but imagine if you've got different ways of running your application in some cases it may not only exercise certain functionality so you only may import certain code but if I have a whole bunch of these patches of being implied in one big patches file and it's going to import all of this code that it wants to monkey patch upfront if you ever use that code later on you've imported it for no reason all you've done is increased the amount of memory your application is using so that's another danger thing you have to be careful of so what can we do about it everyone with me what peps are so pep is what's got a python enhancement proposal if you're familiar with the internet they have rfcs request the comments pep is like a python equivalent of that it's where someone can write up a proposal about how something should be implemented and down the track if it's accepted it may be implemented into the core python library or the language and so on now there's this pep created called pep.prc.com which is post importals it never got implemented never got accepted so it doesn't exist it never got done but wrapped has implemented a part of that actually it hasn't implemented at all now maybe for my patches module was going to actually cause examples to be imported straight away using concepts from this post importals I'm going to go in here I've got my wrapper and I've got my function applied patches which is seen as actually going to apply the patch but I've put it around at the decorator which is wrapped when imported so example so all it is is a definition and what happens is that you import that and it hasn't caused example to be imported that point but if example is imported later on by something I've installed this thing called post importals so when that module is imported later it'll go great I've seen that that module has been imported now I'm going to call this function and allow you to apply that patch only at the point that the module was actually imported very very importantly it is applied before anything else gets to do anything with the module so if the first user of that module was from example import function or example plus this gets in before that happens so I can actually apply my patch before anything else very important now that is better but it still requires that patches module to be imported for anything else in your main application script so you still have to go in to modify your application and we've got it down now to a little bit of code modification but it's still going to modify your application code what would be great is if you didn't have to modify anything your application code and there's a way of doing that so we need a way to trigger monkey patches without modifying the application code and I have another package for that it's called autorept so people use autorept as well now for this to work what we need to do though is we need to separate each of your sets of monkey patches into their own separate modules now I'm going to use an example here in the python standard library this is a module called whizgy ref so whizgy is the python's standard for when facing with web applications between servers and applications and there's this simple whizgy server in there now I want to instrument that whizgy server so that when I get a htdb request for my application I want to dump out how long that web request took so I'm going to go and create this separate module now which packages up my monkey patches so I've got to set up the py file here which is what you use if you want to create your own installable python module which you want to put up on pypy and let people install this on I'm going to call my module name whizgy ref to plug in very important here I've got this thing in here called entry point this is something which is a part of this package called set up tools originally when python came around there was a thing called distutils it was the basic library package which you used when implementing these setup.pys to create installable modules someone created something a bit more complicated called set up tools and one of these things they had with this thing called entry point it's just a way of when you install a module it can register these things called entry points it just creates a file in your python installation associated with that package so here's this extra bit of information this module provides this service or this functionality or something like that and you can go and look up those entry points later and we're going to make use of that so this may look it's going to be the actual punky patch module similar to before actually I should point out something about my entry point so this is the details of my entry point what I'm saying is when whizgy ref got simple server module is imported I want you to call rack whizgy ref to plug in which is name of module apply patches and here's that apply patches is here I'm going to say patching module and a wrap function wrap with that using that function from wrap what it's going to do is it's going to take whizgy request handle which is the actual handle function inside the whizgy service implementation which handles one request and I'm going to wrap it with this function called timed function so timed function then following the wrap way of the evaporator is going to start a timer we started it call the original function and when it's done we're just going to print out a speech so we're applying a monkey patch now here's the magic with auto wrapped I'm going to go pip install all the wrapped I've gone pip install my monkey patch module and I have an app.py which is my application and that's importing that simple server from whizgy ref and giving it a whizgy application to run that's your original code I am not touching that at all we're not going to modify it all we need to do because I've installed order wrap is set this environment variable this is the name of my module which cleared the monkey patch exporting it so the application is here I don't have to run python just python nothing else python app.py and my code got patched in automatically I haven't finished it I haven't modified one line of code in the application and I wouldn't have changed all very magic and I don't actually do how that works is very evil the order wrap module has been around over a year this is the first time I've ever told anyone about it even though it's been up on actually I did do a blog post about it it's not something to say much about I'm not sure what the reaction will be with people this is a really weird concept in python packages when you install a python package into your python distribution one of the things that it can install into the python installation into the site packages directory which is where all your modules are installed along with the package you can install this file I call it .pth it's like the original purpose of it was that you can almost view it like a sim link or an alias if you like it would normally have in it a directory so what would happen is when python starts up and trying to work out your sys.path where it's going to get all your modules from it goes through the directories and looks for these .pth files it will open it up and stick that in sys.path so it was a way of having packages installed elsewhere rather than just the site packages directory and python would know where to get packages from those the main use of it is not actually to have packages installed somewhere else it was so that when you install a package you can have a version number and the directory that would be actually in a sub directory of the site packages so you might have Django-1.10 in a sub directory but there will also be a Django.pth file which says Django-1.10 so that way it knows when it goes through sys.pth it will put site packages Django 1.10 in sys.path so it knows where to find that actual version of Django that's where it came from somewhere along the line and I believe it had something to do with codecs for language locales someone had this really weird idea that hey let's allow executable code inside of that .pth file and there's this bit of magic in there python when going through looking at all those .pth files if it starts with import space it's going to go oh this is code I'm actually going to read in that line of code and execute it when python is being initialised so autorept is doing this horrible magic which puts code in one of these .pth files when python starts up that bit of code is going to is that environment variable set for autorept bootstrap if it is I'm going to import autorept I'm going to call this bootstrap function which then goes and hooks into the python import machinery for modules and that gives me on my way hooking into the import mechanism so that we have told it this is this monkey patch module over here I've been able to use those entry points to get the information about where that monkey patch function is and that all gets registered and later on when your code imports that whizgy breath simple server module my code will go oh good I'm going to monkey patch for you before anyone even gets to it it's really, really horrible nasty and the interesting thing I find about this is that it's maybe a weird concept for many I think is that it means that technically because of the way all this works I've had to package up my monkey patch as a module you can start to distribute monkey patches as packages on pypo and the use case for this for me is instrumentation for monitoring now back in New Relic when I did that that was obviously a reply to a bit of software and all of the monkey patch required for all the different frameworks that existed the database modules and all this sort of thing we at New Relic had to implement all those and they were part of the New Relic package and it's not really extensible by anyone else because it's all New Relic stuff but technically if one wanted one could go and write a replacement for New Relic if you like which has a basic bit of functionality in there for handling the reporting of metrics pipeline into some back end and through just using this ability to package up monkey patches people could come along and start package up instrumentation for all these different frameworks themselves and just put them on pipeline and if someone knew about it they could say great I'll bring in my base monitoring package and I need this bit of monkey patch Django and this bit of monkey patch and just list them in that environment they just patch and they don't modify their code at all and they can get a whole ecosystem of all these horrible monkey patches it's a scary idea but I don't know I'll get people interested in that last thing about wraps so head decorator sport had all this stuff with monkey patching it has one bonus feature if you're doing multi-frame programming I've thrown in an example of your life an example of a decorator in there actually I wanted to use it myself if you've done multi-frame programming you would know that you have to be careful about doing friend synchronization and you know you need to make sure if you've got shared data that you don't have multiple things accessing the same data at the same time and normally you would use the lock object in the threading module yourself to do that and that gets a bit complicated and things like that there's a much simpler way if one can actually incorporate that manipulation of the lock the acquire of the lock and the release of the lock around the function which is modifying the data you can make it really simple you can have that synchronized so in this particular case it means that if multiple threads call this function at the same time only one can execute the code at the same time and this one is separated so it's got its own synchronization lock on it and who has used Java anyway okay you're familiar with the synchronized what are they called decorators annotation is it you're familiar with the synchronized annotation in Java? Keyword oh yeah so Java has this idea of synchronized keyword and it's very similar to decorators in the way we use them right but it's a very very important thing when you use synchronized keyword on a method of a class in Java it's effectively locking that whole instance of that class okay or if the synchronized decorator does Java have static methods now I think if you apply this synchronized to the static function it's locking the whole class I don't know about the instance anyway if you remember back to my description of the wrap decorator before we talked about the universal decorator the fact that the decorator could tell you applying it to normal function instance method or class or class method we can make use of that inside of this synchronized decorator implementation so in this particular case we have synchronized on the function before and all it's doing is controlling access to that one function, global function people are synchronized on a method now because I know that I'm being using it on an instance method of class hey I can lock the instance of the class or if I apply it to a class method class method normally I can apply it to a class I can lock the class if I apply it to a static method static methods aren't really bound they're like a global function then I'm just locking that one function but also in Java I can't remember how to synchronize for this for works, there's some syntax for this in decorator in Java as well if you want to be able to synchronize on a block of code my synchronized decorator even though it's a decorator I've made it a bit more magic as well and if you don't know what context managers are they are the things that you use with this with syntax you might be familiar with if you've gone with open file now that gives back a file object but that with statement ensures that that is closed when that with statement exits and that's the fact because this file object is what's called a context manager so I've made my decorator even more fancy I've made it bold and purpose it's not just a decorator it's also context manager so as well as using it as decorator we can actually use it in this so the decorator it can also at the same time do this and it's smart enough that in this case it's an instance method so we're synchronizing on the instance and here obviously we've synchronized itself and so I can say or if it's a another instance method for some reason needed to synchronize on the class so similar to a class method I can actually give it the object and I'll synchronize on that instead so that's my extra bonus thing in wrapped so why might you use wrapped in for creating better decorators I don't say I've got a hundred percent right but I'm a lot, lot closer than using functools.wrappers a lot, lot closer and there's a lot of code in there there is a pure python version there's also C implementations for the performance so I'll use this implementation and make it nice and performant and it will fall back to pure python for some reason you're going to follow I've got safety mechanisms for monkey patching and you get this brilliant little synchronization decorator and that's it, that's my talk so what docs there is, wrap.read.docs.io but better still go to my blog go look on the right hand side and there's that quick link for monkey patching now decorators monkey patching over a dozen blog posts on the topic actually I think they're linked off so that's one of my little open source projects that's it so any questions? the sample code that you went through is that available on the site or is this presentation available? I'll be putting it up it'll end up on was it slideshow probably we don't even meet up but yeah I usually push stuff off I think it's up on slideshow there's two slide slides I can't remember which one I used but the blog posts that over a dozen blog posts go into a lot more detail there's got all these examples in there any more how long have you been using Python? as I said I downloaded version .9 I looked at it and went oh crap tab spaces as indenting as like you gotta be joking I sort of played around a little bit but obviously it was very early then and I think I next dealt with it when it was about version 1.2 1.2 maybe 1.3 and I started playing with it more than and I wrote all these big Python wrappers around my C++ library which I had out then and that C++ library that started in about 1990 before Python C++ standard template library existed so it had string classes it had collection classes it had an old template file it was a logging system it was an event system it was a distributed messaging system in there and I created Python wrappers for the distributed messaging system a whole way of doing distributed applications using a published private request for Python module and that was used in some telco software where I was working and a later job where I was writing software to drive card printers to print driver's licenses that software is still used it's still running even though I haven't played with that C++ library for many years any other questions? yeah, any other questions? one last slide after this for those who weren't at Python Singapore I did a talk on a thing called warp drive and that is to do with web application deployment and Docker trying to make web applications much much easier to deploy it's not just local warp drive is designed to do stuff it's very easy on your local development system but also inside of Docker but also in hosting services such as OpenShift which is where I work which I'm an advocate for but I'm now an author I've got my name on a book now this book is free if you're interested in platform as a service if you need to host a web application then you can go and download this book for free and it will tell you about how OpenShift works our latest version which is using Docker for container runtime Kubernetes for orchestration and scheduling because Docker alone it's great on your own machine but if you need to start going beyond one machine until many many machines Docker alone is not there and this company is trying to fill in all the holes to make their Docker cloud or what are they called Docker data center they are still on way behind things like Kubernetes Mesos and all these other ones but we are thinking of Kubernetes so if you're interested in web application hosting or Python web apps that book mentions Java though unfortunately only mentions Python once in the whole but you can download it for free it'll explain how you can actually download it on your own laptop and cloud it I do actually have in that VM you download there are actually some templates in there for deploying Python web apps using my warp drive software which is what my other talk was about and obviously there's a video from the Python Singapore that talk if you just can go back and look at it although I should come to Python Australia in a few weeks time and see it there because I'm going to give a talk again okay? Thank you


Hollywood Radio Theater. We get many enjoyable moments out of the books we read, the sights we see, and above all the things we hear. The Hollywood Radio Theater hopes to add to your enjoyment by bringing you each week the finest in dramatic and comedy entertainment featuring a stellar cast of movie personalities, many of whom will appear in their original motion picture roles. Now here is our producer, Mr. William Keyless. Tonight's play, Take Care of My Little Girl. Now to anyone who might think our story controversial, we assure you it's the exception and not the rule. Now from the original cast of this 20th Century Fox screen success, our stars are lovely Gene Crane as the ideal pledge who finds romance with a GI student played by Dale Robertson, a newcomer to Stardom and our stage. Now, Take Care of My Little Girl starring Gene Crane as Liz Erickson and Dale Robertson as Joe Blake. Elizabeth Erickson, this without a doubt, is the most exciting journey in all her 18 years. She's on the train at last, the train that's taking her to Midwestern University. And to make it still more wonderful at her side is her best friend Janet Shaw. Oh, gosh, Liz, what'll happen when we get there? I mean, will we go straight to the campus? Not till tomorrow. Our first stop's the Murray-Arms Hotel. Golly, I hope my trunks arrive. You should've heard Dad when he heard how much it's going to cost. That hotel, I mean. Oh, mine too. Oh, but Mother convinced him. She said it makes such a good impression on the sororities if you stay at the Murray-Arms during rushing. And after all, it'll only be for a week. Oh, then you'll be living at the tri-u house. Upsilon, epsilon, epsilon. Well, so will you. Well, they take me, I will.  My mother didn't go to college. Oh, Janet, stop. Now, look, the house mother at tri-u. Her name's Mrs. Clark. Well, she and my mother were roommates, and mother's written to her about you. I guess it's silly to worry so. But whatever happens, Liz, we'll stay together, won't we? You bet we'll stay together. Oh, Dan, I can't believe it. We're practically there. The compliance will proceed with the registration. Good luck to you all. Professor Blake, here's my card. It is not Professor Blake. Not even Instructor Blake. I'm just a senior student. The authority has thought that because of my advanced age I could help freshmen take their courses. Oh. Oh, you were in the war. Up to my neck. I haven't designated any science here. Must I? I'm not very good at science. It's required for freshmen. Now, what science would you like? Well, what science have you got? Well, we have some very nice chemistry today. Physics, zoology. Well, what about botany? Now, how do you like that? Well, I like it fine. The point is, how do you like it? This is somewhat outside my problems. But just why did you come to college? Well, my father says I'm too young to get married and too old to hang around the house. Well, that's a better reason than most. Why did you pick me to Western? My mother went to Midwesting. She was a tri-hugh. Well, well. Now, let's find you a real interesting major. Yes, let's. You know, this may surprise you, but I was awfully good at languages. Frankly, it does surprise me.  You better get in another line. I'm afraid this is going to take me a little while. How do you do? We just want to say hello to your hotel, your room company. Oh, yes, it's just fine. We're dying to meet you for the opening tea. Will you be free at three o'clock? Oh, I'm sure I'll be free as well. Well, thank you. Good-goodbye, Miss Colby. Thank you again. Well, try you, Jim, free o'clock tomorrow. Welcome to our tea list. Oh, thank you, Miss Colby.  It's sort of a madhouse, isn't it? Oh, that's Jenny Barker there at the door. Senator Barker's daughter? Of course, Senator Barker. And that's Helen Brown. She's head girl's cheerleader. That's quite an honor, you know. And the loud girl is Casey Krause. No use apologizing for her. There's one in every sorority. I think it's peachy about your mom and mother-clive being so chummy. And speaking of mother-clive... Just to tell me, Marjorie, I'd know in a minute all of Eric's and Elizabeth's... Well, how do you do, Mrs. Clark? Well, well, I received a long chatty letter from your mother just yesterday. She's very proud of you, my dear. I've heard about you as long as I can remember, Mrs. Clark. Oh, really? Your mother gave me very special instructions to take care of her little girl. I just met your friend Janet, such a sweet girl. I guess we're both a little excited, Mrs. Clark. Everything's so different and wonderful. And I want to hear all about it. Only first tell me about the mother. You know that 20 years ago she was a little... Everything going all right, Mary? Yes, I think we can all take a bowel march. Like everything else, a Russian tea is just a matter of proper preparation. Who's that in the corner? Her name's Ruth Gates. I'm a real squirrel. Just look at the sack she's wearing. Oh, yeah, God's March. She's a legacy. I tried to talk to her before. She's just impossible. The Erikson girl, though, seems to be making quite a hit with Mother Clark. What about her friend, that Janet something or other? Average. Strictly average. I understand they're awfully close, Liz and Janet. Now, this could be a little tricky, Mary. Oh, relax. Now, you know as well as I do that every girl here automatically will be rushed by every other sorority on campus. Listen, we're still the best, and we'll still pick the ones we want. Oh, come on. Let's tell these kids what it means to be quiet. Fine, except my roommate's waiting for me in the lobby. What's a big rush? Well, we're due at the Kappa Kappa Della house for dinner. Oh, I am, but it's rush week. The fine news. Is there anything wrong with my schedule?  You mean we had pineapple sherbet instead of two-prone ice cream? Those kappas are getting more radical each year. What fraternity are you? None. Oh. Break the date if you like. Don't you believe in fraternities? Well, I'm a 28-year-old who's spent six years in the army. The whole thing seems a little silly. And don't let me influence you.  Oh, you haven't got a chance. I was brought up on tri-U. Martha used to say, if you're a good little girl and do as I say, you'll be a tri-U, too.  About tri-U? About men. Why should we talk about men? You're kidding. A pretty girl like you. Oh, don't worry about me. I can handle anybody. Grab my arm. Go on, just grab my arm. There's nobody going to grab your arm. Hmm. There's quite an arm at that. Now, let's get across the street and have that cloak. Mother, my trunk. It still hasn't arrived. Tomorrow night's the dinner at tri-U, and you should see the looks the girls are giving me. The same suit, mother, four times in a row. Well, there's only one thing to do. Dad's not going to like it. Huh? I'm sure they do. I forgot to tell you in my letter.  Oh, much heavier than you are, dear. Oh. There's the best dinner I've had since I got here. Well, I should think you'd be more interested in other things, Adley. For instance, Jan. Well, the girls. And that candlelight ceremony. Gosh, was it impressively? Oh, it was beautiful. Well, I'm poofed. I can't wait till I hit the sack. But they're voting on us right now. I won't close my eyes all night. The minute my head hits that pillow, I'm gone. Look at this, look. What are you doing here? Well, thanks for telling me. But if you've got a date, Mr. Blake, it's with three girls. We came together and we're sticking together. A guy his age can't handle three of us. Oh, no. We can have a lot of fun together. We can go... I guess I didn't sound very convincing, did I? Oh, you didn't. Now you'd better come along quietly. No. Now let me try it again. Oh, no. The four of us can have a lot of fun together. I guess in the East nobody ever says goodnight. Back in Tucson. You making that, Adley? That's the old main bell. The one they sing the song about. Oh, imagine that bell's over a hundred years old. Right now I'd give ten dollars to your account again. Oh, you.  Well, it was beautiful. Nothing you can say is going to spoil this moment for me. Adley, there's a girl with a right attitude. She's taking all this hanky-panky right in stride. There are a lot of good things about sororities. For instance?  And if a sorority wants you, especially a good one, it gives you a wonderful feeling of belonging. Golly, isn't it natural to want to belong? What about all the clubs, lodges, associations, brotherhoods, ladies' hostilities? What about them? Oh, all right. So I'm silly. Resards, you still may have the last laugh. What's that mean? The tri-us. Right now they're deciding who they're going to pledge. Golly, just because they've been nice to me doesn't mean they're going to... Well, not a chance, Liz. Not a chance. You're in. How can you be so sure? Well, I'm not just an old man. I'm a wise old man. I'll tell you all about it over that couple of calls. Mr. B. Voting. Now, what about Adley Swanson? Is she in or out? Tucson, Arizona. Horses and canners. Well, she'd be a breath of fresh air around here. She doesn't seem to be a sorority type somehow. Uh, uh, may I say a word or two? Mother Clark, of course. Well, we've had a note from an alumna in Adelaide's hometown. Adelaide's mother operates a million dollars worth of branching property. She thinks Adelaide would have much to offer. Well, to be perfectly honest, there's so little you can really tell about girls during rushing. Depends from where I'm sitting. Does anyone want a black ball, Adelaide Swanson? No. All right, we have four more to go. Now sit tight, sisters. Ruth Gates. Now, now, girls, please. You know how I hate to interfere, but Ruth's a legacy. Her mother was a dear, sweet girl and a fine example of tri-use. Casey was a legacy, too. We took her in and looked what happened. Thank you, Dallas. Truly. I'd like you to know that sorority's gotten rich on my 50 cents fine. Now, what are we wasting time for? Ruth Gates is absolutely hopeless. Now, just a second. I agree that Ruth Gates is a sad sack, but she's probably been brushed off ever since she was a kid. That's not our problem, Casey. But we can do things for this girl. Isn't that what sorority's a fool? Oh, for heaven's sake. Well, I think Casey has a point. At least we ought to discuss it. Actually, girls, the pledging period is really just a trial period. It would please me very much. All right. I won't stand in the way of a girl being pledged. But let's get one thing straight. Unless Ruth changes, and I don't believe in miracles, I'm never going to allow her to become initiated. Well, that's fair enough. Thank you, dear. Well, I guess we've pledged Ruth's date. Now, here's one legacy we're not going to fight about. I guess we're all pretty unanimous about Liz Erickson. Count me in. She's creamy. Me, too. She's terrific. Well, I guess we're all sold on Liz. Now, about Janet, sure. Liz and Janet, well, they're just never apart. Maybe Liz won't take our bid unless we take Janet, too. How many have we decided to ask? 13. Well, at least room for only two more. We've got to be careful from now on. I know two other girls who are simply must. They come before Janet with me. Now, where's the harm if we take 16 girls instead of 15? Every other sorority on the cabinet. We're not every other sorority. We'll try you. Anyhow, how much do we know about Janet's family and her background? We can't afford to do that. Now, let's not get on the subject of families and background. What about our own dear Mrs. Richards? Didn't she nearly go to jail? Oh, now, Liz. Look, Casey, Cruz, how dare you. That's enough out of you, Casey. You'll find 50 cents. Now, listen, nobody is going to shut me up when it comes to telling the truth. You want me? Yeah, me, too. Say, what do I do about this? What do you do for you accepting, of course? Oh, no, I'm not. Adelaide. Oh, it's too much social stuff. Too many phony smiles and all that singing. But it's not all just singing. What about the girls? What about the beautiful friendships you're making? All of them. What's the matter with the girls in the dormitory? Can't I make friends with them without all that singing? Honey, where have you been? Just around. How did you do? Two bids. No, Liz, not try you. Oh, sometimes there's a mistake. If you go... There's no mistake. I've been back. Well, did you get five pie? Yeah. Delta Mew. Well, so did I. Then all we have to do is to decide between them. They're both just as good as try you. Well, I'm going to Highler Hall. If you two had any sense, you'd come with me. Oh, Adelaide. Janet, darling, what do you think? Personally, I say Delta Mew. You know very well that Delta Mew isn't near as good as try you. It's a goon sorority. Oh, it's not so bad. Besides, we made an agreement. A kid's agreement. We didn't mean it. I meant every word. Wherever we go, we're going to go together. Please. It's an 11 o'clock class. Oh, Janet, don't be crazy. Let me go. Just a second. The U.L. is the express agency. Your trunk's here. Hello. Oh, well, can you send it right up here to the hotel? Oh, oh, no. No. Just a minute, please. Oh, Ad, what should I do? About Janet? I'm afraid you're on your own, kid. Hello. I guess you better send the trunk to the try you out. Oh, thank you. We'll return in a few moments with act two of Take care of my little girl. The time has passed when the boys and girls of the United States never travel over 50 miles from their birthplace. In hundreds of locations around the world today, you young men and women in uniform are serving the United States. Your country depends upon you in many ways. First, there's your military job to perform. That's carefully defined. It's detailed so that you know exactly what to do. But there's another way in which you serve your country that's a little more difficult to outline. It involves your daily contacts with people of other nations. To them, you're an example of the American way of life.  Your actions will be interpreted by them as the typical actions of an American citizen. For that reason, you must be conscious of your duty to help promote better understanding between nations. Be a good example of our way of doing things. Remember, a country is known by its people. What people think about your country depends upon you. Now, Mr. William Keely, our producer. Act two of Take Care of My Little Girl, starring Jean Crane as Liz and Dale Robertson as Joe. Julie pledged to the most exclusive sorority at Midwestern University. Classes are over for the day, and Liz has promised to meet Adelaide across the campus in the jug room. I ran into a friend of yours. Have a cup of coffee. Oh, what are you two so glum about? And where's Janet? We just come from seeing Janet off. She's gone home. Gone home? But... There are always a lot of casualties pledged weak. But she's awful, huh? I feel so awful. You and I are going to take a little walk. You mind, Adelaide?  I knew I'd get stuck with the check anyway. You can afford it. Listen, Janet, we've promised each other. We made an agreement we'd never be separated. Now, wait a minute. You're building yourself way out of proportion. No, no, I'm not. Janet's life is ruined, and I'm responsible. You listen to me.  In six months she'll see how ridiculous it all was, and she'll come back here. Go somewhere else. She'll be a much more sensible, a much happier girl. Well, I still have the feeling I'm pretty awful. No, you're not. You're just not very bright, that's all. If I look anything like the way I feel... You look fine.  It tilts a little too much. Outside of that, I find nothing to criticize. Now, let's get back to the jug room. I've got to eat. I've got a job tonight. It'll be free Saturday night. Oh, well, Saturday night's the dinner date. Oh, yeah, so it is. The cream of the crop. The ladies will try you and the gentlemen of the lambda house. Who's your date? Oh, no one's special. Everyone just goes over and meets them. It gives the pledges a chance to... It sounds swell. Well, I intend to have a very good time. Yeah. Yeah, you do that, Liz. No matter what happens, you have a good time. What's your self, Liz? This is Chad Carr. Mr. Carr, Ms. Eric. Well, hi. Hi. Big romantic interest of the Kansas. He skips dinner, then shows up clobbered. He's part of his charm. Liz, huh? You see that door? Uh-huh. What's that? We're in the clearing. What are we doing in the kitchen? It's my wine cellar. I just hand me a couple of those glasses, will you? Just a little for me. That's all you're going to get. This stuff's expensive. Is that why you're looking so grim? No. No, I got stood up tonight. Oh, and that's pretty awful, huh? Well, I've got a reputation. The news got out of the kill my roommate. Well, at least you can laugh about it. Who's laughing? What am I doing telling the truth to you? There's something about me. I don't know. People just can't lie to me. Maybe I'm different. I want you to change. I want you to be like the other trios. Act like Mary, talk like Marge, dress like Dallas. Then I'll be able to lie to you with the greatest of ease. Who you been dating? Joe Blake. Do you know him? Yeah, I know him. What's the matter? Is something wrong with him? No, nothing wrong with him, and I don't like him. You'll have to be a little clearer than that. Joe Blake is a quiet, superior air. Well, he is superior. Well, he might be a little noisier about it, so we'd have something on him. I bet he hasn't told you a thing about his war record. No, just that he was in it. That's what I mean. Two silver stars, he never says a word about it. I can't think. Come on, I'll turn you over to the mat. And you? I am going out again. I got to find out why I was stood up. It's been a real pleasure, Miss Eriks. Well, thank you, Mr. Carnes. Happy landing. Take ten minutes. Oh, well, I don't think I'm getting soft. The midterm exams start in just three days, and in this sorority, we have certain definite rules about study hours, six hours daily for every pledge. Ruth, didn't you hear me? I said you can stop for ten minutes. All right, girls, impossible. Liz, do you have a minute, please? We'll be sending out the invitations tomorrow, Liz, for our midterm dance. Maybe you can explain this to me. I guess it doesn't make much sense, Marge. You put Joe Blake's name down on the date list, and then you cross them out and put down Chad Carnes. Oh, I know, and I cross Chad out, too. Well, who's it going to be for head and safe? You can't be serious about Joe. Sure, sure it is Joe. Well, I've known him longer than Chad.  I don't mean to butt in, Liz, but all the other men will be from fraternity. Mary's right. Joe wouldn't feel at home. He'd be uncomfortable. No, Chad on the other hand. Oh, I know. He's fun, and I love dating him, but I don't know. By the way, does Joe own a dinner jacket? I just bet he doesn't. Anyhow, he can rent one, can't he? Well, that's all the flypies have to hear a rented suit. Thanks, Mary. Thanks for making up my mind for me. Just send my invitation to Joe Blake, please. It's up to you, Liz. I guess you know what you're doing. For you, Liz, telephone. Oh, thanks, Dallas. If it's Adelaide, tell us. He's supposed to be in the middle of a French exam. Well, he spoke to me and fought with me. Thanks, Dallas. Dad, where are you? A juggler. But your exam don't tell me you've finished it already. Liz, I gotta see him. All right, Chad. I'll be right over. The exam, I took one look at the questions, and I knew I was dead. Oh, how long could I just sit there staring at the ceiling? But what did you do? I handed him my blue book practically after him, came down here, and I got the idea. What idea? Well, didn't you tell me you were a prize student in French? Well, I'm no prize winner, but I... Look, here's a copy of the questions. I bought another blue book. I thought if we could go someplace, you could fill in the answers for me. I'll still have plenty of time before the exam's officially through. What good would that do? You've already handed in your blue book. Sure, but when the exam's over, the prof will take the blue books to his office. Gee, Chad, it sounds awfully risky. So I'm thrown out of school a few days earlier. Yeah, but what a way to go. Oh, what's the matter, Liz? Scruples? Oh, no, not exactly. Oh, look, Liz, everybody cheats you know that, except maybe a few spooks. Well, I'll admit it certainly takes guts. Chad, I... I can't. Okay. No, I know I've been flip about flunking out, but I... Liz, believe me, it's the most important thing in the world to me right now. He said I'd never make it, not in a million years. I gotta show it. Who? Oh, my father. All my life he's been right. He calls me his remittance man. And he laughs. Only does his laugh. How... how will your mother take it? My mother or my father's wife. You mean they're not one and the same? No, this is my father's third. Oh. Well, where... where is your mother? I guess she's still in Pasadena. Look, Liz, if... if I flunk out now, I... I just couldn't go home and face my father. I just couldn't. No. No, you've got to graduate. I'll do it, Chad. Now, where can we go? Get his office down there. Yes. As I'll say it again. That shows what little bowling can do, Professor. Can I present Miss Erickson, Professor Bant. How do you do? How do you do? Uh, Miss Erickson's going to France this summer, sir. And, uh, well, I... I told her you could be a big help to her. You see, she doesn't want to see the usual tourist stuff.  Well, I've heard so much about Brittany, Professor, but I haven't the faintest idea where it is. Well, first of all, suppose we take a look at the map back here. Brittany's on the coast, you see? Ended. Professor. That's all right, girls. I just hope I was able to help you, Miss Erickson. The map of France and I switched blue books. All of a sudden, I... I can't stop trembling. I'm going to see to it that everybody at the lamp the house knows what you've done for me. I'll... I'll never forget this, Liz. What do you think? I say what Liz did for Chad will really launch her.  It was plain, ordinarily cheating, and I don't like it. Don't mind Mary, Liz. She has to make a noise like the Chapter President. She's a hero over at the lambda house. Do you know what one of them said? Well, he said, Liz has the look, the right sorority connection, and when the grapevine gets going on this little episode, she's a cinch for Queen of the Fragrance. Queen of the Fragrance? Golly, what did I do? I'll tell you what you did. A little thing like this will bring attention to you, and that means votes, and that should show you the difference between men. Oh, I can just picture Joe Blake having enough nerve to do a thing like this. It didn't require, uh, just a lack of character. Oh, ye God, Mary, we haven't had a fresh queen since 44. Yes, sir. Walking me home, Joe. Thanks for the true confession. Okay, if we sit on the porch for a minute. Sure, I guess so. Of course, what just bowls me over is that margin Dallas actors if I just swam the English Channel or something. And you see, some people cheating is a major sport. And you've just earned your letter. Oh, well, I don't know if I'm crazy about your attitude. Sorry, Liz. The only attitude I have, you know me, one suit, one attitude. Well, you needn't be so smug. We're not the only ones who go in for cheating. Look, I know sororities haven't got a monopoly. Maybe I'd like to cheat, too, but I'd only be cheating myself. You think I'm pretty much of a heel, don't you? I didn't say that. Just think of the way I've been defending you. What? Why, they've been halving me for weeks, and I've been standing up for you. I'm beginning to think that margin all the others are right.  Now, wait a minute.  Sure, I was feeling so excited and happy, and you have to come along, and I've got a dinner jacket. I guess that just about sums me up. I haven't even got a dinner jacket. Better not keep raffles waiting. Why? Why, you... Oh, I'll tell you one thing. I'd never do it again. My life of crime is over. You know, my only regret is that I waited until my senior year to dream up this little system. Think of all the years I wasted studying. Oh, Chad. All that time we were in Professor Benson's office, and I thought you frightened. Well, here I go, telling you the truth again. Yes, I was frightened. You didn't show it one bit. I was afraid for you, too. I've got to go in. I'm supposed to be boning on math. I'll take a certified public accountant to concentrate on math on a night like this. Liz. Liz, I want to kiss you. How do you say, once again, in French? On course, you will say. Maybe it's not us. Maybe it's just the excitement. No, no, no. This should have happened along the way. I... I want you to have my pen, Liz. You know, some girls say that getting a boy's pen doesn't mean a thing. Others think it means you're engaged or something. Well, I... I guess it means you're engaged to be engaged. It means that someday, if you pass math and don't put on weight, I might ask you to be my first wife. It's like my father'd be flattered if I followed his pattern. Oh, no. Come on. Look, it's not that funny. No. I was just thinking how happy this is going to make Mard. Good night, Chad. Good night, Liz. Well, I didn't know Chad and I had an audience. Sorry, Liz. I guess I should have just sneaked away. What do you want? Matter now. No. No, I guess it doesn't. That's what I figured. So long, Liz. Have fun. We pause now for station identification. The curtain rises on Act 3 of Take Care of My Little Girl, starting Jean Crane as Liz and Dale Robertson as Joan. For the past few days, Sorority Row at Midwestern University has become Nightmare Allen. For this is Hell Week, the traditional week when freshmen become the world's lowliest creatures. Liz Erickson is no exception. Her particular job at the moment is walking around the block, tracing each footstep on the sidewalk with a piece of chalk. Oh, hello, Ruth. Around the whole darn block. My back will be broken. I've got to go to the graveyard and copy the names off a hundred tombstones. Ruthie, wait a minute. Honey, I don't think you'd better go. But we've got to do what they tell us, and now especially. Oh, Liz, as soon as this is over, we'll be tri-used. I don't like the way you look, Ruth. I'll bet you've got a fever. Oh, I'm just tired and excited. Oh, I saw Joe Blake today. He asked about you. Oh, did he? Oh, he's so nice, Liz. Oh, I wish I were just half as popular as you are. First, Joe, and then Ted Karnes and... Oh, Liz, thanks for being so nice to me.   And, honey, stop apologizing for being alive. Well, you wouldn't understand. You wouldn't know what all this means to me. Well, it won't mean a thing, honey, unless you get on the job. Oh, my gosh, the graveyard! Last piece of business, our grand pledge, miss. Well, now tell us what she's planned for the pledges tonight. Well, let's start with our prize package, Ruthie Gates. She's to go to every house from 4th to 11th Street and get the name of every occupant. Well, I don't think it's fair. What's the matter with you, Dallas? No, we don't vote on the pledges until Friday, but you all know what my attitude was when we pledged, Ruth, and, well, that miracle hasn't happened. He's still the same squirrel. I think she's improved 100%. And where does that put her? I defy even Tasia to say that Ruth is good enough to be a tri-u. Oh, come now. How many of you really want Ruth for a sorority, sister? Go on. Raise your hands. There you are. Less than half. And it only takes one black ball. How can you be so cruel? Don't you know that Ruth... Every more cruel to let Ruth go through three more days of hell-weak agony and torture? I say let's do the decent thing and tell her tonight. Well, I'm glad I won't have to tell her. No, none of you will have to tell her. It's all up to little Dee, isn't it? All right, Marge, get on with the rest of the list. Come on in. Slowly, Ruth Gates reporting his dog is born. Oh, let's forget that, Mom. And shall we have some tea? Oh, no, thanks, Mary, but I've got to rush off on my next assignment. Ruthie, have you been happy here? I mean really happy with us. I've never been so happy in my life. Well, what I mean is, well... There have been cases, you know, of pledges stealing they were in the wrong group. I want to be at try humor than anything else in the world. I'm afraid I have some bad news, Ruthie. I understand you've run up some pretty big bills at Simonson. Well, yes, for clothes, Mary. I wanted to have the right clothes. They reported it to the Dean of Women. Well, under the circumstances. Well, we have such finicky bylaws. But Mary, I'll pay them. They said I could wait... Oh, it's not just that, Ruth. I wish there was something I could do, but my hands are tied. You've got to go to Fourth Street, Mary. Get in there. No, dear. You don't have to do that now. Oh, you look so tired, Ruth. Why don't you run along to bed? Oh, and there's absolutely no rush about moving out. Is that all, Mary? Yes, dear. That's all. What's the matter with you? Lost or something? Jones! Oh, hello. What are you doing up so late? Hell week stuff? Yes. A little job to do. I haven't seen you since when was it? Middle of December? First week in December. As a matter of fact, I did catch a glimpse of you the other day, but I was wearing a ridiculous 1890 baby suit, and I didn't want to... Yes. The parasol. You saw me? And I saw you see me. Well, thanks for not letting me see that you saw me see you. The... I'm glad to see you, Jones. Honest. That's Chad's pen you're wearing. Uh-huh. Well, a little bit later, but my insincere congratulations. My... my insincere thanks. So much for Chad. Now, what's your target for tonight? Well, I've got to get to Cloverdale, and then make sure the buses aren't running, and get this postcard signed by the head nurse at the hospital, and then somehow get back here. And that's all I have to do.  How? Walk me down the street. I'm due at a party, Jack Gruber's place, you know him? No. But tell me, how do I get out of going to Cloverdale? Hand in your pen. Oh, Jones. Sign the nurse's name yourself. Then you can go to the party with me. Not the top-notch people, of course, but music and something to eat. How about it, Liz? Oh, I can't, Joe. I really can't. That's too bad. This is where Jack lives. No, no. Downstairs. Basement apartment. Look at him. He sure looks cozy and warm in there. Why, there's Casey and Adelaide. That's right. Gosh, I haven't seen Adelaide for ages. Yeah, that's the way it goes. You don't always mean to lose track of friends. Maybe if I went in for it, for just a few minutes. Good. Good, let's go. What is this, Liz? Hello, Casey.   Give you away? My girl, I'm proud of you. Well, she's still at the wrong water hall. Adelaide, honestly, I've been meaning to come over and see you. Honey, the road to Hyder Hall is paved with good intentions. I'm awful glad to see you, Liz. Liz, look, the doorway. Well, isn't this just dandy? Chad's guard. Sorry to barge in, but can anyone tell me if Liz Derrick is here? Well, Chad. What are you doing here? Get your coat, Liz, let's go. Wait a minute. How did you know I was here? What have I pledged to you? How will you get your coat? Say, that's quite a spy system you have. Does a girl give you an assignment for the night? Oh, honey. Have you done it? No. Why not? Because I told her not to. Liz, you're crazy. Three days before initiation. You've got to marry Tully, you're sorry. Yes, and then I might try going to Professor Benson and telling him I'm sorry. What's that got to do with it?  Integrity? Maybe I'm no one to talk after helping you, Chief, but you're just a fellow to preach integrity. Just a minute, Liz. You have to try to understand Chad's sense of values. Look, you don't think I'm scared just because I'm surrounded by your friends.    Come on, Liz. Maybe we'd better...  So that's enough of that. Everybody's acting like kids. Someone was me. No. No, I'm not. Okay. Stay. You seem very much of hope. Well, at last I've got something to tell my children. I saw Chad Garnes get a smack in the nose. Sorry, Liz. Gosh, I... I'm overdressed. What does that mean? It means, what do I do with a fraternity pin? I... I don't want to wear any more. Come in. Oh, lowly Elizabeth Erickson... Don't ever mind that, Liz. Chad just phoned me. He said to tell you he was sorry for behaving like a lout. What's it all about, Liz? Oh, nothing, Mary. While you were out, you didn't happen to run in the Roots' case, did you? No, but she had a long assignment. Yes, I... I know. Wait, you're worried about her, aren't you? Oh, I knew she wasn't feeling well.  I... I had to tell Ruth she would be pledged. Be pledged? Oh, but for what? There's no point in discussing that. Now we've got to find her. Liz, where are you going? Like you said, Mary, we've got to find her. What next, Liz? We've been to the railroad station, the airport, the busty pool. We've searched all over town. I've got to find her, Joe. What was Ruth's assignment tonight, you know? Oh, some silly thing. The names of everybody living between 4th and 11th Street. Oh, but Mary told her not to go. Yeah, well, I've got a crazy idea. Come on, we'll go over to 4th Street. Well, 4th, 5th, 6th, 7th... There's just no sign of her, Joe. I told her she wouldn't... Wait a minute. There, across the street. Isn't that someone on the steps? Ruth! Ruthie! Come on. She's just sitting here. Ruthie! Doctor, finish. Finish getting the names. Oh, Ruthie, what's the matter? Oh, they look at me. Maybe if I get the names, maybe they'll let me... They've done it. Give me a hand. We've got to get her to the infirmary right away. Straight to the hospital as soon as your phone lives. How is she? They're taking the X-rays, Mother Clark. Oh, this is just awful. That poor girl. Doctor. Across the hall. Dallas, you and Mary stay here. Oh, what a strange girl that Ruthie is. Mary was so nice to her. She begged her to go to bed. Then she slipped solid. Mary, I don't understand. Three days before initiation. Why did you do that? How could you do a thing like that? I'll wait outside, please. Or if you could have seen her face. I know you don't like her, Dallas, but Ruth was so happy at the house. She tried so hard.  I've got these things with you. We had no choice, Liz. Ruth, run up some big bills, she can't pay. That reflects seriously on the house. But I'm in the same fix. I've been running up bills, too.  Oh, I see. You have one set of rules for the girls you want and another for the ones you... Well, the doctor said it's pneumonia, but she's going to be all right. Oh, thank heavens. We'll send us flowers the first thing in the morning, Dallas.  Oh, look. Let's all go back to the house and have some hot chocolate. Come on, Liz. You'll be able to think more clearly in the morning. I'm pretty clear right now, Mary. Will you please tell me, Liz, what is the matter? Something's been bothering me for a long time. I... I never quite knew what it was. Well, now I know.  What did you say, dear? What... what are our ideals? Just being good friends and helping each other. Oh, you're... you're all upset about for Ruth. But we all are, dear. We'll be the laughing stock of the campus. Why, I try you pledge hasn't turned in her pen since 1939, and she was kind of funny to begin with. Maybe she wasn't. Maybe she was a nice girl with a wrong kind of figure for clothes. I'm beginning to lose patience with you. Liz, dear, have you thought what this is going to do to your mother?  Just ask your mother. There are so many wonderful things about sorority. But the friendships you made, the real true friendships, that's the most beautiful part. Well, I have a wonderful idea. Supposing we take Ruth back here. Oh, now wait a minute. You've been all through this whole... Oh, let Ruth wear the pen. Who cares? Nobody ever has to know we be pledged here. Well, Liz, why, she'll be the happiest. No, it won't work. Mother Clark, a lot of things you've said are true. There are good things about sorority. But it's not enough to make up for the people they hurt. And I don't happen to like what's happened to me. I was so anxious to be a try. You, I, I let Janet Charlie school. I found myself preferring people like Chad Carn. It's a Joe Blaine. Well, who wouldn't? And I thought it was smart to cheat. I even thought it was important to be Frosh Queen. One thing you are right about, Dallas. Ruthie doesn't belong at the Tri-U house, where she'll be nearly tolerated. You know very well what I mean. No, Ruthie belongs at Hyler Hall. She doesn't need to be tolerated, Mary. She needs to be wanted. I, I'm sorry, Mother Clark. What happened to your pledge, Ben? I guess this is just my night for losing jewelry. Did you quit or did they throw you out? I quit. And they'll say they threw you out. Well, that's perfect arrangement. Everyone's face is safe. Now what? Well, I thought I'd double up with Adelaide for tonight. Good. I'll walk you over. See you in the morning. I'll see if I can find a room at Hyler Hall for Ruthie and me. Listen. The old main bell. Remember, Janet Shaw, she got such a kick out of listening to it. Gosh, Ben. That seems a long time ago. It was a long time ago. How about dinner tomorrow night? Sure. Dutch, of course. Oh, Joe, wait. Now what's your problem? Oh, I, I was just thinking about my mother. We have to be so careful the way we break things to her. Well, Liz, our mothers have to grow up, too, you know. In a minute, our scars will return. Most everyone knows that education is divided into two parts. Part one, we might say, consists of book study. And part two consists of putting the knowledge gained from books into operation. Part two in our schools and colleges is usually referred to as lab work. For example, the young student doctor reads and memorizes the workings of the human body, then moves on to become a hospital intern to put that knowledge into action. The botanist reads about a certain type of leaf or plant formation, then lays down his textbook and turns to his microscope, where he studies the specimen of this particular plant life. You know, in a certain sense, you men in the armed forces overseas are being studied under a microscope. And on the top side of that microscope are millions of people who have heard a lot or read a lot about Americans. Now, perhaps for the first time in their lives, they have an opportunity to do some lab work. So let them see a good specimen, a true specimen, a true picture of the United States. Remember, a country is known by its people. What people think about your country depends on you. Now, here's Mr. Keely with our cars. And here they are coming forward for a curtain call. Gene Crane and Dale Robertson. Sorry to catch a plane, but won't you take a minute to tell us about the movie time USA tour you're making? Well, I'll be gone about two months, Bill, all around the country. Well, I hope you're going to mention your latest picture for 20th Century Fox. The return of the Texan while you're on tour. Be sure of it. I fly out tonight and I'll cover New York City and surrounding territory, Boston and surrounding territory, Oklahoma City and surrounding territory, New Orleans and surrounding territory, and Texan. Ah, at last, the return of the Texan. Well, maybe the Texans won't let you return to California. I think they will. See, I was born in Oklahoma. It's sort of a rivalry. Which state has the most rugged men and beautiful women? And now I know you're anxious to be on your way. Now, ah, wait a minute. I want to hear about next week's play. You've been keeping it a secret for weeks. And I'm afraid it's still a secret because this picture was selected as the moviegoers of America in a nationwide poll for a photo play magazine to determine the winner of its famous gold medal award. I can only say this is the play you've all been asking and waiting for. I'll be listening from surrounding territory. Good night. Good night. The Hollywood Radio Theatre is produced by Mr. William Keely. Our orchestra is directed by Rudy Schrager. This is John Milton Kennedy, inviting you to join us again next week at this same time for another presentation of the Hollywood Radio Theatre. Radio Theatre is a presentation of the United States Armed Forces Radio Service.


Hello, DDS Stevens here, Senior Handler at the InternetStorm Center. In this video we are going to look at some YARA rules to detect office documents with VBA code. I wrote a couple of diary entries, like here simple YARA rules for office mall docs and here one with improved rules to have less false positives. Here in one with the simple rules, I have two different rules. One for the binary file format and one for the XML file format. So long time ago, Microsoft started to use the compound file binary format or what I like to call the OLE file format for its office documents and this is that rule. And then in 2007 they introduced a new file format, the OO XML file format, so the office open XML file format, which is essentially a zip container containing mostly XML files. So let's take a look at these rules. I have them here. This one is for later in the video, but here are the two simple rules. Let's start with the OLE VBA one. So if I run YARA with these rules on an office document old file format with VBA code, then the rules detected. And how does this rule work? Well, just two classes in the condition. First of all, we check if we are dealing with an OLE file by checking what the first four bytes are of that file. So I have that file open here in the binary editor. These eight bytes here are the magic sequence for OLE files. So each and every OLE file starts with that sequence. And what I typically do is just test for the first four bytes. If you have a bit of imagination, this reads like DOC file, and this hexadecimal data reads like DOC file. So that is what I'm testing for. I read an unsigned 32-bit integer at position zero, beginning integer, and I check if the value is this. And if that is the case, then I also want to find a byte sequence, which is actually a compressed code for attribute. And it's this hexadecimal sequence. Let me copy this and search this. Here you have that sequence. So let me explain why I select that sequence. If you run OLE dump on that document, you see that it contains VBA code in Stream 7, so I can select Stream 7, decompress the VBA code, and here you have the VBA code. And you can see that the VBA code starts with attribute space and then a variable name. That is always the case with VBA code that has not been tampered with. So every office document, for example, that is created with VBA code, its VBA code will start with attribute space. And that is what I'm going to search for. Now what I'm searching for is compressed, so I cannot just look for the string attribute space. I have to search for the compressed version of that string. And I can show you this by saying 7S. So in Stream 7, I want to see the compressed source code. And here you have it. So it always starts with 01. And then here you have a two byte integer that specifies the length of the compressed source code. Now it is an integer that is a length and also some of the high bits of that integer are always set. This is not something that can be easily used for detection because it changes. But then this is what I can use. This here is the first piece of a compressed chunk. So 00 indicates here that this is all a representation of compressed data, 8 bytes here attribute. And that is then followed again by another piece. So 00, so also everything stored and that is then 65, E, 20 space and so on. So I select this sequence here to detect compressed VBA code. It contains ASCII characters, common ASCII characters attribute and E, but it also contains two null bytes. So that makes it a bit more specific. So that is just how the rule works. If we find a file that starts with this and if it contains this, then we are going to generate an alarm for an office document, an OLE file that contains VBA code. Now for the new file format and new is relative because that file format was introduced with Office 2007. So what we are dealing with here is a zip container. And I can also show you this with my tool zip dump. As you can see here are all kinds of XML files. And if the office document, the 00 XML file contains VBA code, then it will contain an OLE file and that OLE file contains the VBA code. And the name of that OLE file is VBAproject.bin. So that is what I'm testing for. It's a very simple test. I test if I'm dealing with a zip file and then I just test if I have a string VBAproject.bin inside that file. What is that test here to test for a zip file? If you open that 00 XML file, so that zip container in an hexadecimal editor, you will see that it starts with this byte sequence. This is the magic header, the byte sequence for a zip file record. And a normal 00 XML file will start with a zip file record. So we can check for the presence of these bytes at the start of the file, like I do here. And then just search for VBAproject.bin. So I'm going to search for ASCII and here you have it. Now this is a very simple rule and it can have false positives. For example, if you have file names that contain that string, like for example, a file name that would be this is VBAproject.bin, then this would also trigger. But that is not a valid VBAproject.bin file because the name is not what it should be. But then that rule will trigger. We can improve that rule and that is what I've done here. We can improve that rule so that it will not only check if it finds VBAproject.bin, but also if that string that is found is found inside a zip file record. And that's what I do here in this rule. So here that was PKVBA. So in a zip file, a PKZIP file, we want to find VBA. This rule, the improved rule is also PKVBA but then RE because I'm going to use a regular expression. First of all, here, the file name, it's not actually VBAproject.bin, but it is word slash VBAproject.bin. So it's contained in a folder word, but inside the structure that is actually the file name. And we can see that here. If I break this down here, I select the zip file record for word VBAproject.bin and I drill down in the structure, you can see that the file name, the actual file name is not just VBAproject.bin, but what is stored inside the record is word slash VBAproject.bin. And that's also what we see here. So the file name that I have to look for is this here. But of course, that is for word, for Excel, it will be Excel. So what I did is create a regular expression that will match all of these variants of the file name. So here you have a bit of regular expression that can match folders that are just composed of letters and the slash character. So the test here now is again, am I dealing with the pkzip file? And then did I find that regular expression? And then if I find the regular expression, I will do two more tests to see that I am indeed dealing with a file name inside a zip file record. Now if you come back here, you have the file name here. And here you have the magic sequence for a zip file record, 54b0304. The distance in bytes between this position, this field here and this field. So from here to here, that is exactly 30 bytes. So I'm going to do some calculations in my Yara rule here. So first of all, at vbaproject.bin, that represents the address where that regular expression was found, so the position. Now that string can be found more than once. And as we can see, it is indeed also found more than once here in the rule. You can see that if I run Yara on that document here, it hits. I mean, there's a trigger. And if I look for the strings, you can see here that these strings and variations of these strings are found at many positions. So I need to test all of the strings that are found. And that is why I'm using a for loop here, for condition. And the rule is, if just one matches, then that is good enough for me. If we found one record that contains vbaproject.bin, then we have found vbacode. So I will match for any and not for all. They don't all have to add just one of them. So that is the index then here. So this is index e into the array of vbaprojects.strings that are found. So that represents here the position of an instance of that string word slash vbaproject.bin that was found. Then we subtract 30 from that. And then I read the unsigned 32-bit integer begendian at that position. And I compare that with the magic sequence. So that is the rule. If this triggers, then already I have a first indication that I have indeed found a filename and that filename is inside a zip file record. And then finally I do also another test. And the second test that I do is the following. Here you have the filename word slash vbaproject.bin that is 19 characters long, 4 bytes in front of this field you have this field and this is the name length. So that's 2 bytes long as you can see here 13-0-0. So that's in hexadecimal, little endian, so that's 19 in decimal. So what I do in my rule here, I take the length of the string that I found. So exclamation point vbaproject.bin that stands for the length of the string that was matched and this is the index into the array. So this is the length here of my string 19 if it is the correct string. And then I will again take the address of that string, subtract 4 to go to two fields in front and read that as an unsigned integer 16-bit little endian. And that should also be 19. And if both are true, both classes are true, then I'm pretty sure that I found a vbaproject.bin filename inside a zip file record and then because of the fork any, this whole part here will be true and thus the rule will trigger.