Yes it can be done using - unitCannotMoveInto which is located in CvGameUtils.py. I did it for my mod (my mod limits the number of units to 2 / tile, but the theory is the same. One word of caution - this will also limit the number of units allowed in a city, so you may want to add some code to change that.